fix(rds): honor restore IAM flags and reject malformed booleans (#5473)

* fix(rds): reject malformed restore flags

* fix(rds): disable IAM authentication by default on restore

* fix(rds): honor IAM settings on instance snapshot restore
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-11 23:25:34 -04:00
1 parent dd6bf4cfcb
commit 03a0dfefdd
10 files changed
+489 -15

No files matched your search

@@ -0,0 +1,79 @@
package com.floci.test;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.DBCluster;
import software.amazon.awssdk.services.rds.model.RdsException;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.assertThat;
@DisplayName("Cluster restore IAM authentication defaults")
class RdsClusterRestoreIamTest {
private static final Logger LOG = Logger.getLogger(RdsClusterRestoreIamTest.class.getName());
@ParameterizedTest
@ValueSource(strings = {"snapshot", "point"})
@DisplayName("Omitted IAM authentication is disabled and explicit choices are preserved")
void restoredIamDefaultsToDisabled(String path) {
String source = TestFixtures.uniqueName("restore-iam");
String snapshot = source + "-snap";
try (RdsClient rds = TestFixtures.rdsClient()) {
try {
rds.createDBCluster(b -> b.dbClusterIdentifier(source).engine("aurora-postgresql")
.masterUsername("admin").masterUserPassword("Password123!")
.enableIAMDatabaseAuthentication(true));
rds.createDBClusterSnapshot(b -> b.dbClusterIdentifier(source).dbClusterSnapshotIdentifier(snapshot));
for (Boolean flag : new Boolean[]{null, false, true}) {
String target = source + "-" + (flag == null ? "omitted" : flag.toString());
try {
DBCluster restored;
if ("snapshot".equals(path)) {
restored = rds.restoreDBClusterFromSnapshot(b -> {
b.dbClusterIdentifier(target).snapshotIdentifier(snapshot).engine("aurora-postgresql");
if (flag != null) {
b.enableIAMDatabaseAuthentication(flag);
}
}).dbCluster();
} else {
restored = rds.restoreDBClusterToPointInTime(b -> {
b.dbClusterIdentifier(target).sourceDBClusterIdentifier(source)
.useLatestRestorableTime(true);
if (flag != null) {
b.enableIAMDatabaseAuthentication(flag);
}
}).dbCluster();
}
boolean expected = Boolean.TRUE.equals(flag);
assertThat(restored.iamDatabaseAuthenticationEnabled()).isEqualTo(expected);
assertThat(rds.describeDBClusters(b -> b.dbClusterIdentifier(target)).dbClusters()
.get(0).iamDatabaseAuthenticationEnabled()).isEqualTo(expected);
assertThat(rds.describeDBClusters(b -> b.dbClusterIdentifier(source)).dbClusters()
.get(0).iamDatabaseAuthenticationEnabled()).isTrue();
} finally {
deleteCluster(rds, target);
}
}
} finally {
try {
rds.deleteDBClusterSnapshot(b -> b.dbClusterSnapshotIdentifier(snapshot));
} catch (RdsException e) {
LOG.log(Level.WARNING, "Could not clean up snapshot " + snapshot, e);
}
deleteCluster(rds, source);
}
}
}
private static void deleteCluster(RdsClient rds, String identifier) {
try {
rds.deleteDBCluster(b -> b.dbClusterIdentifier(identifier).skipFinalSnapshot(true));
} catch (RdsException e) {
LOG.log(Level.WARNING, "Could not clean up cluster " + identifier, e);
}
}
}
@@ -0,0 +1,69 @@
package com.floci.test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import software.amazon.awssdk.services.rds.RdsClient;
import software.amazon.awssdk.services.rds.model.DBInstance;
import software.amazon.awssdk.services.rds.model.RdsException;
import java.util.logging.Level;
import java.util.logging.Logger;
import static org.assertj.core.api.Assertions.assertThat;
class RdsInstanceSnapshotIamTest {
private static final Logger LOG = Logger.getLogger(RdsInstanceSnapshotIamTest.class.getName());
@ParameterizedTest
@ValueSource(booleans = {false, true})
void restoredIamUsesExplicitFlagOrDefaultsFalse(boolean sourceEnabled) {
String source = TestFixtures.uniqueName("snapshot-iam");
String snapshot = source + "-snap";
try (RdsClient rds = TestFixtures.rdsClient()) {
try {
rds.createDBInstance(b -> b.dbInstanceIdentifier(source).engine("postgres")
.dbInstanceClass("db.t3.micro").allocatedStorage(20)
.masterUsername("admin").masterUserPassword("Password123!")
.enableIAMDatabaseAuthentication(sourceEnabled));
rds.createDBSnapshot(b -> b.dbInstanceIdentifier(source).dbSnapshotIdentifier(snapshot));
for (Boolean flag : new Boolean[]{null, false, true}) {
String target = source + "-" + (flag == null ? "omitted" : flag.toString());
try {
DBInstance restored = rds.restoreDBInstanceFromDBSnapshot(b -> {
b.dbInstanceIdentifier(target).dbSnapshotIdentifier(snapshot);
if (flag != null) {
b.enableIAMDatabaseAuthentication(flag);
}
if (Boolean.TRUE.equals(flag)) {
b.port(5433);
}
}).dbInstance();
boolean expected = Boolean.TRUE.equals(flag);
assertThat(restored.iamDatabaseAuthenticationEnabled()).isEqualTo(expected);
assertThat(rds.describeDBInstances(b -> b.dbInstanceIdentifier(target)).dbInstances()
.get(0).iamDatabaseAuthenticationEnabled()).isEqualTo(expected);
assertThat(rds.describeDBInstances(b -> b.dbInstanceIdentifier(source)).dbInstances()
.get(0).iamDatabaseAuthenticationEnabled()).isEqualTo(sourceEnabled);
} finally {
deleteInstance(rds, target);
}
}
} finally {
try {
rds.deleteDBSnapshot(b -> b.dbSnapshotIdentifier(snapshot));
} catch (RdsException e) {
LOG.log(Level.WARNING, "Could not clean up snapshot " + snapshot, e);
}
deleteInstance(rds, source);
}
}
}
private static void deleteInstance(RdsClient rds, String identifier) {
try {
rds.deleteDBInstance(b -> b.dbInstanceIdentifier(identifier).skipFinalSnapshot(true));
} catch (RdsException e) {
LOG.log(Level.WARNING, "Could not clean up instance " + identifier, e);
}
}
}