fix(redshift): read ARNs with '!' in a secret name or ':' in an IAM path (#7112)

This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-31 14:03:19 -04:00
1 parent d2f0455cd9
commit bc237ae980
4 files changed
+25 -2

No files matched your search

@@ -24,7 +24,7 @@ final class RedshiftDestinationValidator {
private static final String ROLE_ARN_REGEX = "arn:.*:iam::\\d{12}:role/[a-zA-Z_0-9+=,.@\\-_/]+";
private static final Pattern ROLE_ARN = Pattern.compile(ROLE_ARN_REGEX);
private static final String SECRET_ARN_REGEX =
"arn:.*:secretsmanager:[a-zA-Z0-9\\-]+:\\d{12}:secret:[a-zA-Z0-9\\-/_+=.@]+";
"arn:.*:secretsmanager:[a-zA-Z0-9\\-]+:\\d{12}:secret:[a-zA-Z0-9\\-/_+=.@!]+";
private static final Pattern SECRET_ARN = Pattern.compile(SECRET_ARN_REGEX);
private static final Pattern UNREADABLE_KEY_CHARS = Pattern.compile("[\\s'\"]");
private static final Set<String> BACKUP_MODES = Set.of("Disabled", "Enabled");
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.redshift;
import io.github.hectorvent.floci.core.common.AccountResolver;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.services.iam.IamService;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -37,7 +38,7 @@ public class RedshiftIamDbUserResolver {
LOG.warnv("GetClusterCredentialsWithIAM caller could not be resolved; using {0}", FALLBACK_DB_USER);
return FALLBACK_DB_USER;
}
String resource = arn.get().substring(arn.get().lastIndexOf(':') + 1);
String resource = AwsArnUtils.parse(arn.get()).resource();
if (resource.startsWith("assumed-role/")) {
String[] parts = resource.split("/");
return parts.length >= 2 ? "IAMR:" + parts[1] : FALLBACK_DB_USER;
@@ -144,6 +144,19 @@ class RedshiftDestinationValidatorTest {
assertTrue(messageOf(dest).contains("secretsManagerConfiguration.secretARN"));
}
@Test
void secretArnAcceptsEveryCharacterTheModelAllows() throws Exception {
RedshiftDestination dest = valid();
dest.setUsername(null);
dest.setPassword(null);
RedshiftDestination.SecretsManagerConfiguration secrets = new RedshiftDestination.SecretsManagerConfiguration();
secrets.setEnabled(true);
secrets.setSecretArn("arn:aws:secretsmanager:us-east-1:000000000000:secret:team/db!creds-AbCdEf");
dest.setSecretsManagerConfiguration(secrets);
assertDoesNotThrow(() -> RedshiftDestinationValidator.validateConfiguration(dest, SHAPE));
}
@Test
void invalidBackupModeAndDisablingBackupAreRejected() throws Exception {
RedshiftDestination dest = valid();
@@ -42,6 +42,15 @@ class RedshiftIamDbUserResolverTest {
assertEquals("IAM:alice", resolver.resolveDbUser("auth"));
}
@Test
void userPathContainingAColonStillYieldsTheUserName() {
when(accountResolver.extractAccessKeyId("auth")).thenReturn("AKIA123");
when(iamService.resolveCallerArn("AKIA123"))
.thenReturn(Optional.of("arn:aws:iam::000000000000:user/team:x/alice"));
assertEquals("IAM:alice", resolver.resolveDbUser("auth"));
}
@Test
void mapsAssumedRoleArnToIamrPrefix() {
when(accountResolver.extractAccessKeyId("auth")).thenReturn("ASIA123");