feat(redshift): support default IAM roles for COPY and UNLOAD (#6304)

* feat(redshift): support default IAM roles for COPY and UNLOAD

* fix(redshift): distinguish default role keyword from literals

* fix(redshift): accept blank default IAM roles
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-23 08:33:20 -04:00
1 parent a8b5e8b8ec
commit 7e51e69c44
17 files changed
+670 -62

No files matched your search

@@ -91,15 +91,13 @@ public class RedshiftQueryHandler {
List<String> iamRoleArns = memberList(params, "IamRoles");
String region = regionResolver.resolveRegionFromAuth(authorizationHeader);
String defaultIamRoleArn = params.getFirst("DefaultIamRoleArn");
Cluster cluster = manageMasterPassword
? service.createClusterWithManagedMasterPassword(identifier, nodeType, masterUsername,
clusterSubnetGroupName, vpcSecurityGroupIds, iamRoleArns,
params.getFirst("MasterPasswordSecretKmsKeyId"), region)
: iamRoleArns.isEmpty()
? service.createCluster(identifier, nodeType, masterUsername, masterUserPassword,
clusterSubnetGroupName, vpcSecurityGroupIds)
params.getFirst("MasterPasswordSecretKmsKeyId"), region, defaultIamRoleArn)
: service.createCluster(identifier, nodeType, masterUsername, masterUserPassword,
clusterSubnetGroupName, vpcSecurityGroupIds, iamRoleArns);
clusterSubnetGroupName, vpcSecurityGroupIds, iamRoleArns, defaultIamRoleArn);
String parameterGroupName = params.getFirst("ClusterParameterGroupName");
String multiAz = params.getFirst("MultiAZ");
boolean hasParameterGroup = parameterGroupName != null && !parameterGroupName.isBlank();
@@ -748,7 +746,8 @@ public class RedshiftQueryHandler {
throw new AwsException("InvalidParameterValue", "ClusterIdentifier is required", 400);
}
Cluster cluster = service.modifyClusterIamRoles(clusterIdentifier,
memberList(params, "AddIamRoles"), memberList(params, "RemoveIamRoles"));
memberList(params, "AddIamRoles"), memberList(params, "RemoveIamRoles"),
params.getFirst("DefaultIamRoleArn"));
String xml = new XmlBuilder()
.start("ModifyClusterIamRolesResponse")
.start("ModifyClusterIamRolesResult")
@@ -941,6 +940,9 @@ public class RedshiftQueryHandler {
builder.end("VpcSecurityGroups");
}
if (cluster.getDefaultIamRoleArn() != null) {
builder.elem("DefaultIamRoleArn", cluster.getDefaultIamRoleArn());
}
if (cluster.getIamRoleArns() != null && !cluster.getIamRoleArns().isEmpty()) {
builder.start("IamRoles");
for (String iamRoleArn : cluster.getIamRoleArns()) {
@@ -154,7 +154,7 @@ public class RedshiftService {
handle.getHost(), handle.getPort(), endpoint.getAddress(),
cluster.getMasterUsername(), password, CLUSTER_DB_NAME,
passwordValidatorFor(entry.accountId(), cluster.getClusterIdentifier()),
cluster.getIamRoleArns());
cluster.getIamRoleArns(), cluster.getDefaultIamRoleArn());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
cluster.setEndpoint(endpoint);
@@ -194,9 +194,18 @@ public class RedshiftService {
public synchronized Cluster createCluster(String identifier, String nodeType, String username, String password,
String clusterSubnetGroupName, List<String> vpcSecurityGroupIds,
List<String> iamRoleArns) {
return createCluster(identifier, nodeType, username, password, clusterSubnetGroupName,
vpcSecurityGroupIds, iamRoleArns, null);
}
public synchronized Cluster createCluster(String identifier, String nodeType, String username, String password,
String clusterSubnetGroupName, List<String> vpcSecurityGroupIds,
List<String> iamRoleArns, String defaultIamRoleArn) {
if (clusters.get(identifier).isPresent()) {
throw new AwsException("ClusterAlreadyExists", "Cluster " + identifier + " already exists", 400);
}
List<String> roles = iamRoleArns == null ? List.of() : List.copyOf(iamRoleArns);
String defaultRole = validateDefaultIamRole(defaultIamRoleArn, roles);
// A previous cluster with this identifier may have been deleted without its temp
// credentials being cleared; drop them so the new cluster starts with none.
credentialBroker.revokeCluster(clusters.accountId(), identifier);
@@ -208,7 +217,8 @@ public class RedshiftService {
cluster.setMasterPassword(password);
cluster.setClusterSubnetGroupName(clusterSubnetGroupName);
cluster.setVpcSecurityGroupIds(vpcSecurityGroupIds != null ? vpcSecurityGroupIds : List.of());
cluster.setIamRoleArns(iamRoleArns != null ? List.copyOf(iamRoleArns) : List.of());
cluster.setIamRoleArns(roles);
cluster.setDefaultIamRoleArn(defaultRole);
// A group named at create time is applied afterwards via modifyCluster.
cluster.setClusterParameterGroupName(DEFAULT_PARAMETER_GROUP_NAME);
cluster.setClusterStatus("creating");
@@ -228,7 +238,7 @@ public class RedshiftService {
proxyManager.startProxy(relayKey(accountId, identifier), proxyPort,
handle.getHost(), handle.getPort(), endpoint.getAddress(),
username, password, CLUSTER_DB_NAME,
passwordValidatorFor(accountId, identifier), cluster.getIamRoleArns());
passwordValidatorFor(accountId, identifier), cluster.getIamRoleArns(), cluster.getDefaultIamRoleArn());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
cluster.setEndpoint(endpoint);
@@ -268,12 +278,20 @@ public class RedshiftService {
String identifier, String nodeType, String username, String clusterSubnetGroupName,
List<String> vpcSecurityGroupIds, List<String> iamRoleArns,
String kmsKeyId, String region) {
return createClusterWithManagedMasterPassword(identifier, nodeType, username, clusterSubnetGroupName,
vpcSecurityGroupIds, iamRoleArns, kmsKeyId, region, null);
}
public synchronized Cluster createClusterWithManagedMasterPassword(
String identifier, String nodeType, String username, String clusterSubnetGroupName,
List<String> vpcSecurityGroupIds, List<String> iamRoleArns,
String kmsKeyId, String region, String defaultIamRoleArn) {
if (secretsManagerService == null) {
throw new AwsException("InternalFailure", "Secrets Manager is unavailable", 500);
}
String password = RandomPasswordGenerator.generate(objectMapper.createObjectNode());
Cluster cluster = createCluster(identifier, nodeType, username, password,
clusterSubnetGroupName, vpcSecurityGroupIds, iamRoleArns);
clusterSubnetGroupName, vpcSecurityGroupIds, iamRoleArns, defaultIamRoleArn);
String secretName = "redshift/" + identifier;
String secretString = managedMasterSecret(cluster, password);
Secret secret;
@@ -677,6 +695,11 @@ public class RedshiftService {
public synchronized Cluster modifyClusterIamRoles(String clusterIdentifier, List<String> addIamRoles,
List<String> removeIamRoles) {
return modifyClusterIamRoles(clusterIdentifier, addIamRoles, removeIamRoles, null);
}
public synchronized Cluster modifyClusterIamRoles(String clusterIdentifier, List<String> addIamRoles,
List<String> removeIamRoles, String defaultIamRoleArn) {
Cluster cluster = clusters.get(clusterIdentifier)
.orElseThrow(() -> new AwsException("ClusterNotFound", "Cluster " + clusterIdentifier + " not found", 404));
@@ -687,14 +710,32 @@ public class RedshiftService {
Set<String> roles = new LinkedHashSet<>(cluster.getIamRoleArns());
roles.addAll(addIamRoles);
roles.removeAll(removeIamRoles);
String defaultRole = defaultIamRoleArn == null ? cluster.getDefaultIamRoleArn() : defaultIamRoleArn;
if (defaultIamRoleArn == null && !roles.contains(defaultRole)) {
defaultRole = null;
}
defaultRole = validateDefaultIamRole(defaultRole, List.copyOf(roles));
cluster.setIamRoleArns(List.copyOf(roles));
cluster.setDefaultIamRoleArn(defaultRole);
proxyManager.updateIamRoles(relayKey(clusters.accountId(), clusterIdentifier), cluster.getIamRoleArns());
proxyManager.updateIamRoles(relayKey(clusters.accountId(), clusterIdentifier), cluster.getIamRoleArns(), defaultRole);
clusters.put(clusterIdentifier, cluster);
clusters.flush();
return cluster;
}
private static String validateDefaultIamRole(String defaultIamRoleArn, List<String> iamRoleArns) {
if (defaultIamRoleArn == null || defaultIamRoleArn.isBlank()) {
return null;
}
requireIamRoleArn(defaultIamRoleArn);
if (!iamRoleArns.contains(defaultIamRoleArn)) {
throw new AwsException("InvalidParameterValue",
"Default IAM role must be associated with the cluster: " + defaultIamRoleArn, 400);
}
return defaultIamRoleArn;
}
private static void requireIamRoleArn(String arn) {
AwsArnUtils.Arn parsed;
try {
@@ -829,7 +870,7 @@ public class RedshiftService {
cluster.setProxyPort(proxyPort);
proxyManager.startProxy(key, proxyPort, handle.getHost(), handle.getPort(),
endpoint.getAddress(), cluster.getMasterUsername(), password, CLUSTER_DB_NAME,
passwordValidatorFor(accountId, clusterIdentifier), cluster.getIamRoleArns());
passwordValidatorFor(accountId, clusterIdentifier), cluster.getIamRoleArns(), cluster.getDefaultIamRoleArn());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
cluster.setEndpoint(endpoint);
@@ -1063,7 +1104,7 @@ public class RedshiftService {
proxyManager.startProxy(relayKey(accountId, clusterIdentifier), proxyPort,
handle.getHost(), handle.getPort(), endpoint.getAddress(),
username, password, CLUSTER_DB_NAME,
passwordValidatorFor(accountId, clusterIdentifier), cluster.getIamRoleArns());
passwordValidatorFor(accountId, clusterIdentifier), cluster.getIamRoleArns(), cluster.getDefaultIamRoleArn());
cluster.setContainerHost(handle.getHost());
cluster.setContainerPort(handle.getPort());
cluster.setEndpoint(endpoint);
@@ -21,6 +21,7 @@ public class Cluster {
private String clusterParameterGroupName;
private List<String> vpcSecurityGroupIds = new ArrayList<>();
private List<String> iamRoleArns = new ArrayList<>();
private String defaultIamRoleArn;
public String getClusterIdentifier() { return clusterIdentifier; }
public void setClusterIdentifier(String clusterIdentifier) { this.clusterIdentifier = clusterIdentifier; }
@@ -46,6 +47,8 @@ public class Cluster {
public void setVpcSecurityGroupIds(List<String> vpcSecurityGroupIds) { this.vpcSecurityGroupIds = vpcSecurityGroupIds; }
public List<String> getIamRoleArns() { return iamRoleArns; }
public void setIamRoleArns(List<String> iamRoleArns) { this.iamRoleArns = iamRoleArns; }
public String getDefaultIamRoleArn() { return defaultIamRoleArn; }
public void setDefaultIamRoleArn(String defaultIamRoleArn) { this.defaultIamRoleArn = defaultIamRoleArn; }
// Audit logging config as set by EnableLogging; no log delivery is emulated.
private boolean loggingEnabled = false;
@@ -15,6 +15,9 @@ import java.util.regex.Pattern;
public final class CopyStatementParser {
public sealed interface S3Statement permits S3CopyFrom, S3Unload {
String iamRoleArn();
boolean defaultIamRoleRequested();
}
/** COPY options that change field content; {@link #NONE} keeps the plain byte-copy path. */
@@ -50,7 +53,8 @@ public final class CopyStatementParser {
boolean jsonAuto,
boolean jsonAutoIgnoreCase,
boolean manifest,
CopyTransforms transforms) implements S3Statement {
CopyTransforms transforms,
boolean defaultIamRoleRequested) implements S3Statement {
public S3CopyFrom {
if (transforms == null) {
@@ -58,6 +62,25 @@ public final class CopyStatementParser {
}
}
public S3CopyFrom(
String targetTable,
List<String> columns,
String bucket,
String keyOrPrefix,
String delimiter,
int headerLines,
boolean gzip,
boolean csv,
String nullAs,
String iamRoleArn,
boolean jsonAuto,
boolean jsonAutoIgnoreCase,
boolean manifest,
CopyTransforms transforms) {
this(targetTable, columns, bucket, keyOrPrefix, delimiter, headerLines, gzip, csv,
nullAs, iamRoleArn, jsonAuto, jsonAutoIgnoreCase, manifest, transforms, false);
}
public S3CopyFrom(
String targetTable,
List<String> columns,
@@ -128,7 +151,33 @@ public final class CopyStatementParser {
boolean escape,
boolean cleanPath,
boolean encrypted,
String sseKmsKeyId) implements S3Statement {
String sseKmsKeyId,
boolean defaultIamRoleRequested) implements S3Statement {
public S3Unload(
String selectQuery,
String bucket,
String prefix,
String delimiter,
boolean header,
boolean gzip,
boolean csv,
boolean addQuotes,
String nullAs,
boolean manifest,
boolean allowOverwrite,
boolean parallel,
long maxFileSizeBytes,
String iamRoleArn,
String extension,
boolean escape,
boolean cleanPath,
boolean encrypted,
String sseKmsKeyId) {
this(selectQuery, bucket, prefix, delimiter, header, gzip, csv, addQuotes, nullAs, manifest,
allowOverwrite, parallel, maxFileSizeBytes, iamRoleArn, extension,
escape, cleanPath, encrypted, sseKmsKeyId, false);
}
public S3Unload(
String selectQuery,
@@ -213,7 +262,7 @@ public final class CopyStatementParser {
private static final Pattern NULL_AS_PATTERN = Pattern.compile(
"(?i)\\bNULL\\s+(?:AS\\s+)?(?:'((?:[^']|'')*)'|\"([^\"]*)\")");
private static final Pattern IAM_ROLE_PATTERN = Pattern.compile(
"(?i)\\bIAM_ROLE\\s+(?:'((?:[^']|'')*)'|\"([^\"]*)\")");
"(?i)\\bIAM_ROLE\\s+(?:'((?:[^']|'')*)'|\"([^\"]*)\"|(default)(?=\\s|;|$))");
private static final Pattern BLANKSASNULL_PATTERN = Pattern.compile("(?i)\\bBLANKSASNULL\\b");
private static final Pattern EMPTYASNULL_PATTERN = Pattern.compile("(?i)\\bEMPTYASNULL\\b");
private static final Pattern REMOVEQUOTES_PATTERN = Pattern.compile("(?i)\\bREMOVEQUOTES\\b");
@@ -264,6 +313,10 @@ public final class CopyStatementParser {
}
public static S3Statement parse(String sql) {
return parse(sql, null);
}
public static S3Statement parse(String sql, String defaultIamRoleArn) {
if (sql == null || sql.isBlank()) {
return null;
}
@@ -273,12 +326,12 @@ public final class CopyStatementParser {
}
Matcher unload = UNLOAD_PATTERN.matcher(cleaned);
if (unload.matches()) {
return parseUnload(unload);
return parseUnload(unload, defaultIamRoleArn);
}
return parseCopy(cleaned);
return parseCopy(cleaned, defaultIamRoleArn);
}
private static S3Unload parseUnload(Matcher matcher) {
private static S3Unload parseUnload(Matcher matcher, String defaultIamRoleArn) {
String select = unescapeSingleQuotes(matcher.group(1).trim());
if (!isSafeUnloadSubquery(select)) {
return null;
@@ -348,7 +401,7 @@ public final class CopyStatementParser {
Matcher cleanPathM = CLEANPATH_PATTERN.matcher(options);
Matcher encryptedM = ENCRYPTED_PATTERN.matcher(options);
Matcher kmsKeyIdM = KMS_KEY_ID_PATTERN.matcher(options);
AuthClauses auth = new AuthClauses(options);
AuthClauses auth = new AuthClauses(options, defaultIamRoleArn);
int next;
int offset = 0;
@@ -509,10 +562,10 @@ public final class CopyStatementParser {
}
return new S3Unload(select, bucket, prefix, delimiter, header, gzip, csv,
addQuotes, nullAs, manifest, allowOverwrite, parallel, maxFileSizeBytes, iamRoleArn, extension,
escape, cleanPath, encrypted, kmsKeyId);
escape, cleanPath, encrypted, kmsKeyId, auth.defaultIamRoleRequested);
}
private static S3CopyFrom parseCopy(String cleaned) {
private static S3CopyFrom parseCopy(String cleaned, String defaultIamRoleArn) {
Matcher matcher = COPY_PATTERN.matcher(cleaned);
if (!matcher.matches()) {
return null;
@@ -594,7 +647,7 @@ public final class CopyStatementParser {
Matcher removeQuotesMatcher = REMOVEQUOTES_PATTERN.matcher(options);
Matcher truncateColumnsMatcher = TRUNCATECOLUMNS_PATTERN.matcher(options);
Matcher acceptInvCharsMatcher = ACCEPTINVCHARS_PATTERN.matcher(options);
AuthClauses auth = new AuthClauses(options);
AuthClauses auth = new AuthClauses(options, defaultIamRoleArn);
int next;
int offset = 0;
@@ -735,7 +788,7 @@ public final class CopyStatementParser {
}
return new S3CopyFrom(table, columns, bucket, keyOrPrefix, delimiter, headerLines, gzip, csv,
nullAs, iamRoleArn, jsonAuto, jsonAutoIgnoreCase, manifest, transforms);
nullAs, iamRoleArn, jsonAuto, jsonAutoIgnoreCase, manifest, transforms, auth.defaultIamRoleRequested);
}
/**
@@ -753,10 +806,12 @@ public final class CopyStatementParser {
private final Matcher secretAccessKey;
private final Matcher sessionToken;
private final Matcher region;
private final String defaultIamRoleArn;
private String iamRoleArn;
private String credentialsRoleArn;
private boolean seenIamRole;
private boolean defaultIamRoleRequested;
private boolean seenCredentials;
private boolean seenAccessKeyId;
private boolean seenSecretAccessKey;
@@ -765,7 +820,8 @@ public final class CopyStatementParser {
private boolean credentialsHaveKeys;
private boolean credentialsMalformed;
AuthClauses(String options) {
AuthClauses(String options, String defaultIamRoleArn) {
this.defaultIamRoleArn = defaultIamRoleArn;
iamRole = IAM_ROLE_PATTERN.matcher(options);
credentials = CREDENTIALS_PATTERN.matcher(options);
accessKeyId = ACCESS_KEY_ID_PATTERN.matcher(options);
@@ -780,8 +836,9 @@ public final class CopyStatementParser {
return REJECT;
}
seenIamRole = true;
iamRoleArn = extractNullValue(iamRole);
return isBlank(iamRoleArn) ? REJECT : iamRole.end();
defaultIamRoleRequested = iamRole.group(3) != null;
iamRoleArn = defaultIamRoleRequested ? defaultIamRoleArn : extractNullValue(iamRole);
return !defaultIamRoleRequested && isBlank(iamRoleArn) ? REJECT : iamRole.end();
}
if (matchClause(credentials, offset, end)) {
if (seenCredentials) {
@@ -41,7 +41,13 @@ public class RedshiftAuthProxy {
private final IamService iamService;
private final SpectrumInterceptor spectrumInterceptor;
private final String clusterAccountId;
private volatile List<String> iamRoleArns;
private volatile RoleConfiguration roleConfiguration;
record RoleConfiguration(List<String> iamRoleArns, String defaultIamRoleArn) {
RoleConfiguration {
iamRoleArns = iamRoleArns == null ? List.of() : List.copyOf(iamRoleArns);
}
}
private final int handshakeTimeoutMillis;
private final int backendConnectTimeoutMillis;
private final Semaphore connectionPermits;
@@ -98,7 +104,7 @@ public class RedshiftAuthProxy {
this.iamService = iamService;
this.spectrumInterceptor = spectrumInterceptor;
this.clusterAccountId = clusterAccountId;
this.iamRoleArns = iamRoleArns == null ? List.of() : List.copyOf(iamRoleArns);
this.roleConfiguration = new RoleConfiguration(iamRoleArns, null);
this.handshakeTimeoutMillis = handshakeTimeoutMillis;
this.backendConnectTimeoutMillis = backendConnectTimeoutMillis;
this.connectionPermits = new Semaphore(Math.max(1, maxConnections));
@@ -159,8 +165,16 @@ public class RedshiftAuthProxy {
}
/** Swap the associated-role snapshot; new connections authorize COPY and UNLOAD against it. */
public void updateIamRoles(List<String> newIamRoleArns) {
this.iamRoleArns = newIamRoleArns == null ? List.of() : List.copyOf(newIamRoleArns);
public synchronized void updateIamRoles(List<String> newIamRoleArns) {
updateIamRoles(newIamRoleArns, roleConfiguration.defaultIamRoleArn());
}
public synchronized void updateIamRoles(List<String> newIamRoleArns, String defaultIamRoleArn) {
this.roleConfiguration = new RoleConfiguration(newIamRoleArns, defaultIamRoleArn);
}
RoleConfiguration roleConfiguration() {
return roleConfiguration;
}
public void stop() {
@@ -221,8 +235,10 @@ public class RedshiftAuthProxy {
if (session != null) {
// Redshift-only DDL (DISTKEY/SORTKEY/ENCODE/...) is rewritten for the plain
// PostgreSQL backend on the way through; every other message is relayed verbatim.
RoleConfiguration roles = roleConfiguration;
new RedshiftInterceptingBridge(session.client(), session.backend(), s3Service, iamService,
clusterAccountId, iamRoleArns, spectrumInterceptor, clusterKey, dbName).run();
clusterAccountId, roles.iamRoleArns(), spectrumInterceptor, clusterKey, dbName,
roles.defaultIamRoleArn()).run();
}
} catch (Exception e) {
LOG.debugv("Redshift connection error for cluster {0}: {1}", clusterKey, e.getMessage());
@@ -61,6 +61,7 @@ public class RedshiftInterceptingBridge {
private final IamService iamService;
private final String clusterAccountId;
private final List<String> iamRoleArns;
private final String defaultIamRoleArn;
private final SpectrumInterceptor spectrumInterceptor;
private final String clusterKey;
private final String databaseName;
@@ -96,12 +97,21 @@ public class RedshiftInterceptingBridge {
public RedshiftInterceptingBridge(Socket client, Socket backend, S3Service s3Service, IamService iamService,
String clusterAccountId, List<String> iamRoleArns,
SpectrumInterceptor spectrumInterceptor, String clusterKey, String databaseName) {
this(client, backend, s3Service, iamService, clusterAccountId, iamRoleArns, spectrumInterceptor,
clusterKey, databaseName, null);
}
public RedshiftInterceptingBridge(Socket client, Socket backend, S3Service s3Service, IamService iamService,
String clusterAccountId, List<String> iamRoleArns,
SpectrumInterceptor spectrumInterceptor, String clusterKey, String databaseName,
String defaultIamRoleArn) {
this.client = client;
this.backend = backend;
this.s3Service = s3Service;
this.iamService = iamService;
this.clusterAccountId = clusterAccountId;
this.iamRoleArns = iamRoleArns == null ? List.of() : List.copyOf(iamRoleArns);
this.defaultIamRoleArn = defaultIamRoleArn;
this.spectrumInterceptor = spectrumInterceptor;
this.clusterKey = clusterKey;
this.databaseName = databaseName;
@@ -565,7 +575,7 @@ public class RedshiftInterceptingBridge {
private CopyStatementParser.S3Statement parseS3Statement(String sql) {
try {
return CopyStatementParser.parse(sql);
return CopyStatementParser.parse(sql, defaultIamRoleArn);
} catch (RuntimeException e) {
LOG.warnv("CopyStatementParser failed, forwarding original statement: {0}", e.getMessage());
return null;
@@ -71,6 +71,15 @@ public class RedshiftProxyManager {
String backendHost, int backendPort, String advertisedHost,
String masterUsername, String masterPassword, String dbName,
PasswordValidator passwordValidator, List<String> iamRoleArns) {
startProxy(relayKey, proxyPort, backendHost, backendPort, advertisedHost, masterUsername,
masterPassword, dbName, passwordValidator, iamRoleArns, null);
}
public synchronized void startProxy(String relayKey, int proxyPort,
String backendHost, int backendPort, String advertisedHost,
String masterUsername, String masterPassword, String dbName,
PasswordValidator passwordValidator, List<String> iamRoleArns,
String defaultIamRoleArn) {
// A prior unclosable entry for this key is left in place: its listener may still
// be bound, and only a successful stop (never a fresh start) may drop it.
// Make sure the self-signed proxy certificate covers the host clients will connect to,
@@ -86,6 +95,7 @@ public class RedshiftProxyManager {
iamRoleArns,
redshiftConfig.proxyHandshakeTimeoutMillis(), redshiftConfig.proxyBackendConnectTimeoutMillis(),
redshiftConfig.proxyMaxConnections(), spectrumInterceptor);
proxy.updateIamRoles(iamRoleArns, defaultIamRoleArn);
try {
proxy.start(proxyPort);
} catch (IOException | RuntimeException e) {
@@ -124,6 +134,13 @@ public class RedshiftProxyManager {
}
}
public synchronized void updateIamRoles(String relayKey, List<String> iamRoleArns, String defaultIamRoleArn) {
RedshiftAuthProxy proxy = proxies.get(relayKey);
if (proxy != null) {
proxy.updateIamRoles(iamRoleArns, defaultIamRoleArn);
}
}
public synchronized void stopProxy(String relayKey) {
// Retry any listener a previous failed start/replace could not close. If it still
// cannot be closed this throws, and the entry stays for the next retry.
@@ -68,6 +68,13 @@ public final class S3CopySimulator {
private S3CopySimulator() {
}
private static void requireDefaultIamRole(CopyStatementParser.S3Statement statement) {
if (statement.defaultIamRoleRequested() && statement.iamRoleArn() == null) {
throw new S3TransferException(SQLSTATE_INSUFFICIENT_PRIVILEGE,
"No default IAM role is associated with the Redshift cluster", null);
}
}
record CopyInput(CopyStatementParser.S3CopyFrom spec, List<String> keys, S3Service s3,
IamService iamService, RedshiftRoleAccess.RoleSession roleSession) {
}
@@ -107,6 +114,7 @@ public final class S3CopySimulator {
static CopyInput prepareCopy(CopyStatementParser.S3CopyFrom spec, S3Service s3, IamService iamService,
String clusterAccountId, List<String> associatedRoleArns) {
requireDefaultIamRole(spec);
RedshiftRoleAccess.RoleSession roleSession = spec.iamRoleArn() != null
? RedshiftRoleAccess.resolveRoleSession(spec.iamRoleArn(), iamService, clusterAccountId, associatedRoleArns)
: null;
@@ -204,6 +212,7 @@ public final class S3CopySimulator {
static UnloadCollector prepareUnload(CopyStatementParser.S3Unload spec, S3Service s3, IamService iamService,
String clusterAccountId, List<String> associatedRoleArns) {
requireDefaultIamRole(spec);
RedshiftRoleAccess.RoleSession roleSession = spec.iamRoleArn() != null
? RedshiftRoleAccess.resolveRoleSession(spec.iamRoleArn(), iamService, clusterAccountId, associatedRoleArns)
: null;