mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(rds): keep Aurora member passwords owned by their cluster (#5685)
* fix(rds): keep Aurora passwords owned by the cluster * test(rds): cover member changes across regions
This commit is contained in:
1 parent
8145ffd00e
commit
430af5fce7
5 files changed
+146
-1
No files matched your search
+30
@@ -103,4 +103,34 @@ class RdsMemberCredentialsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@ValueSource(strings = {"aurora-postgresql", "aurora-mysql"})
|
||||
@DisplayName("Member-only password settings preserve other instance modifications")
|
||||
void memberPasswordSettingDoesNotPreventOtherChangesOrReboot(String engine) {
|
||||
String cluster = TestFixtures.uniqueName("member-modify");
|
||||
String member = cluster + "-member";
|
||||
try (RdsClient rds = TestFixtures.rdsClient()) {
|
||||
try {
|
||||
rds.createDBCluster(request -> request.dbClusterIdentifier(cluster).engine(engine)
|
||||
.masterUsername("clusteradmin").masterUserPassword("ClusterPassword!"));
|
||||
rds.createDBInstance(request -> request.dbInstanceIdentifier(member).dbClusterIdentifier(cluster)
|
||||
.engine(engine).dbInstanceClass("db.serverless"));
|
||||
DBInstance modified = rds.modifyDBInstance(request -> request.dbInstanceIdentifier(member)
|
||||
.masterUserPassword("MemberOnlyPassword!").publiclyAccessible(true)).dbInstance();
|
||||
assertThat(modified.masterUsername()).isEqualTo("clusteradmin");
|
||||
assertThat(modified.publiclyAccessible()).isTrue();
|
||||
assertThat(rds.rebootDBInstance(request -> request.dbInstanceIdentifier(member))
|
||||
.dbInstance().masterUsername()).isEqualTo("clusteradmin");
|
||||
assertThat(rds.describeDBInstances(request -> request.dbInstanceIdentifier(member))
|
||||
.dbInstances().get(0).publiclyAccessible()).isTrue();
|
||||
} finally {
|
||||
try {
|
||||
rds.deleteDBInstance(request -> request.dbInstanceIdentifier(member).skipFinalSnapshot(true));
|
||||
} finally {
|
||||
rds.deleteDBCluster(request -> request.dbClusterIdentifier(cluster).skipFinalSnapshot(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -760,6 +760,10 @@ Managed master secrets belong to the cluster; `ManageMasterUserPassword` on a me
|
||||
does not create a separate member secret. When a cluster record lacks a credential,
|
||||
the member retains its normalized default for that field.
|
||||
|
||||
`ModifyDBInstance` preserves the cluster-owned master password when
|
||||
`MasterUserPassword` is supplied for a member; other supported instance settings
|
||||
still apply. Change the cluster password with `ModifyDBCluster`.
|
||||
|
||||
Accepted cluster password changes update stored member credentials even when the
|
||||
cluster has no backend or runs in mock mode. An unchanged password does not update
|
||||
relays. Rotating an initialized data volume requires a running backend; changing
|
||||
|
||||
@@ -3006,7 +3006,10 @@ public class RdsService implements Resettable, ResourceProvider {
|
||||
instance.setOptionGroupName(optionGroupName);
|
||||
}
|
||||
boolean passwordRotated = false;
|
||||
if (newPassword != null && !newPassword.isBlank()) {
|
||||
boolean clusterMember = instance.getDbClusterIdentifier() != null
|
||||
&& !instance.getDbClusterIdentifier().isBlank();
|
||||
// Aurora member master credentials are owned and changed by the cluster.
|
||||
if (!clusterMember && newPassword != null && !newPassword.isBlank()) {
|
||||
String oldPassword = instance.getMasterPassword();
|
||||
boolean backendRunning = !config.services().rds().mock()
|
||||
&& instance.getDbClusterIdentifier() == null && instance.getContainerId() != null;
|
||||
|
||||
+44
@@ -251,6 +251,50 @@ class RdsIamAuthLambdaSessionIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void memberPasswordModificationKeepsClusterLoginBeforeAndAfterReboot() throws Exception {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
String cluster = "modify-owner-" + suffix;
|
||||
String member = "modify-member-" + suffix;
|
||||
String accessKey = "ASIA" + suffix.toUpperCase();
|
||||
try {
|
||||
rds("CreateDBCluster").formParam("DBClusterIdentifier", cluster)
|
||||
.formParam("Engine", "aurora-postgresql").formParam("MasterUsername", MASTER_USER)
|
||||
.formParam("MasterUserPassword", MASTER_PASSWORD).formParam("DatabaseName", DATABASE)
|
||||
.formParam("EnableIAMDatabaseAuthentication", "true")
|
||||
.when().post("/").then().statusCode(200);
|
||||
int port = rds("CreateDBInstance").formParam("DBInstanceIdentifier", member)
|
||||
.formParam("DBClusterIdentifier", cluster).formParam("DBInstanceClass", "db.serverless")
|
||||
.formParam("Engine", "aurora-postgresql").formParam("DBName", DATABASE)
|
||||
.when().post("/").then().statusCode(200).extract().xmlPath()
|
||||
.getInt("CreateDBInstanceResponse.CreateDBInstanceResult.DBInstance.Endpoint.Port");
|
||||
iamService.registerLambdaExecutionRoleSession(ACCOUNT_ID, accessKey, SESSION_SECRET, SESSION_TOKEN,
|
||||
"arn:aws:iam::" + ACCOUNT_ID + ":role/connect-with-iam");
|
||||
awaitPasswordReady(port);
|
||||
String token = SigV4TokenTestHelper.createRdsToken("127.0.0.1", port, MASTER_USER,
|
||||
accessKey, SESSION_SECRET, Instant.now().minusSeconds(60), 900, SESSION_TOKEN);
|
||||
assertCurrentUser(port, token);
|
||||
rds("ModifyDBInstance").formParam("DBInstanceIdentifier", member)
|
||||
.formParam("MasterUserPassword", "MemberOnlyPassword!")
|
||||
.formParam("PubliclyAccessible", "true").when().post("/").then().statusCode(200)
|
||||
.body(containsString("<PubliclyAccessible>true</PubliclyAccessible>"));
|
||||
assertCurrentUser(port, MASTER_PASSWORD);
|
||||
assertCurrentUser(port, token);
|
||||
assertThrows(SQLException.class, () -> connect(port, "MemberOnlyPassword!").close());
|
||||
rds("RebootDBInstance").formParam("DBInstanceIdentifier", member)
|
||||
.when().post("/").then().statusCode(200);
|
||||
assertCurrentUser(port, MASTER_PASSWORD);
|
||||
assertCurrentUser(port, token);
|
||||
assertThrows(SQLException.class, () -> connect(port, "MemberOnlyPassword!").close());
|
||||
} finally {
|
||||
iamService.unregisterSession(ACCOUNT_ID, accessKey);
|
||||
rds("DeleteDBInstance").formParam("DBInstanceIdentifier", member)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
rds("DeleteDBCluster").formParam("DBClusterIdentifier", cluster)
|
||||
.formParam("SkipFinalSnapshot", "true").when().post("/");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void memberUsesTheClusterManagedSecretBeforeAndAfterReboot() throws Exception {
|
||||
String suffix = Long.toString(System.nanoTime(), 36);
|
||||
|
||||
@@ -419,6 +419,47 @@ class RdsServiceTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void memberPasswordModificationPreservesSameNamedResourcesInOtherAccountsAndRegions() {
|
||||
InMemoryStorage<String, DbInstance> rawInstances = new InMemoryStorage<>();
|
||||
InMemoryStorage<String, DbCluster> rawClusters = new InMemoryStorage<>();
|
||||
String accountA = "111111111111";
|
||||
String accountB = "222222222222";
|
||||
RdsService serviceA = new RdsService(containerManager, proxyManager, ec2Service,
|
||||
new RegionResolver("us-east-1", accountA), config,
|
||||
new AccountAwareStorageBackend<>(rawInstances, null, accountA),
|
||||
new AccountAwareStorageBackend<>(rawClusters, null, accountA),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
RdsService serviceB = new RdsService(containerManager, proxyManager, ec2Service,
|
||||
new RegionResolver("us-east-1", accountB), config,
|
||||
new AccountAwareStorageBackend<>(rawInstances, null, accountB),
|
||||
new AccountAwareStorageBackend<>(rawClusters, null, accountB),
|
||||
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
|
||||
for (RdsService service : List.of(serviceA, serviceB)) {
|
||||
for (String region : List.of("us-east-1", "us-west-2")) {
|
||||
service.createDbCluster("shared-cluster", "aurora-postgresql", "16.3",
|
||||
"admin", "password", "dbname", false, null, null, null, false, region);
|
||||
service.createDbInstance("shared-member", "aurora-postgresql", "16.3",
|
||||
null, null, "dbname", "db.r5.large", 20, false, null, null,
|
||||
"shared-cluster", null, false, false, null, Map.of(), List.of(), region);
|
||||
}
|
||||
}
|
||||
clearInvocations(proxyManager);
|
||||
|
||||
serviceA.modifyDbInstance("shared-member", "MemberOnlyPassword!", true, null, null, null, "us-east-1");
|
||||
for (String account : List.of(accountA, accountB)) {
|
||||
for (String region : List.of("us-east-1", "us-west-2")) {
|
||||
DbInstance member = rawInstances.get(account + "/" + region + "::shared-member").orElseThrow();
|
||||
DbCluster cluster = rawClusters.get(account + "/" + region + "::shared-cluster").orElseThrow();
|
||||
assertEquals("password", member.getMasterPassword());
|
||||
assertEquals("password", cluster.getMasterPassword());
|
||||
assertEquals(account.equals(accountA) && region.equals("us-east-1"),
|
||||
member.isIamDatabaseAuthenticationEnabled());
|
||||
assertFalse(cluster.isIamDatabaseAuthenticationEnabled());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyClusterCredentialsAndIamKeepOtherAccountsAndRegionsUnchanged() {
|
||||
InMemoryStorage<String, DbInstance> rawInstances = new InMemoryStorage<>();
|
||||
@@ -2622,6 +2663,29 @@ class RdsServiceTest {
|
||||
List.of(instance.getDbiResourceId().toLowerCase())).isEmpty());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({"aurora-postgresql,false", "aurora-postgresql,true", "aurora-mysql,false", "aurora-mysql,true"})
|
||||
void memberPasswordModificationPreservesClusterPasswordAndOtherChanges(String engine, boolean mockMode) {
|
||||
when(config.services().rds().mock()).thenReturn(mockMode);
|
||||
DbCluster cluster = rdsService.createDbCluster("cluster-owner", engine, null,
|
||||
"admin", "ClusterPassword!", "dbname", false, null);
|
||||
DbInstance member = rdsService.createDbInstance("member-modify", engine, null,
|
||||
null, null, "dbname", "db.r5.large", 20, false, null, null, "cluster-owner");
|
||||
DbInstance sibling = rdsService.createDbInstance("member-sibling", engine, null,
|
||||
null, null, "dbname", "db.r5.large", 20, false, null, null, "cluster-owner");
|
||||
clearInvocations(containerManager, proxyManager);
|
||||
DbInstance modified = rdsService.modifyDbInstance("member-modify", "MemberOnlyPassword!", true, null);
|
||||
assertEquals("ClusterPassword!", modified.getMasterPassword());
|
||||
assertEquals("ClusterPassword!", rdsService.getDbInstance("member-modify").getMasterPassword());
|
||||
assertEquals("ClusterPassword!", cluster.getMasterPassword());
|
||||
assertEquals("ClusterPassword!", sibling.getMasterPassword());
|
||||
assertTrue(modified.isIamDatabaseAuthenticationEnabled());
|
||||
assertFalse(sibling.isIamDatabaseAuthenticationEnabled());
|
||||
verify(containerManager, never()).rotateMasterPassword(
|
||||
anyString(), anyString(), any(), anyString(), anyString(), anyString());
|
||||
verify(proxyManager, never()).updateMasterPassword(anyString(), anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyDbInstanceBlankPasswordDoesNotOverwriteExistingPassword() {
|
||||
rdsService.createDbInstance("mydb", "postgres", "13",
|
||||
|
||||
Reference in new issue
Block a user