fix(rds): preserve snapshot partitions in custom regions (#5428)

* fix(rds): preserve snapshot partitions in custom regions

* fix(rds): reject relabeled cross-partition snapshot sources
This commit is contained in:
David Phillips authored and GitHub committed 2026-10-11 00:28:49 -04:00
1 parent fe51d2996d
commit ad1fbbc9b9
2 files changed
+73 -3

No files matched your search

@@ -4054,6 +4054,75 @@ class RdsServiceTest {
assertEquals("InvalidParameterValue", otherPartition.getErrorCode());
}
@ParameterizedTest
@CsvSource({"cn-north-1,xx-nowhere-9,xx-nowhere-9,aws-cn",
"cn-north-1,cn-north-1,xx-nowhere-9,aws-cn",
"cn-north-1,xx-nowhere-9,cn-north-1,aws-cn",
"us-gov-west-1,xx-nowhere-9,xx-nowhere-9,aws-us-gov"})
void copyDbSnapshotUsesDeploymentPartitionForCustomRegions(
String deploymentRegion, String sourceRegion, String targetRegion, String partition) {
regionResolver = new RegionResolver(deploymentRegion, "123456789012");
rdsService = newService(containerManager, proxyManager,
new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
rdsService.createDbInstance("source-db", "postgres", "13",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null, null, false,
false, null, Map.of(), sourceRegion);
when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");
DbSnapshot source = rdsService.createDbSnapshot("source", "source-db", Map.of(), sourceRegion);
assertEquals("arn:" + partition + ":rds:" + sourceRegion + ":123456789012:snapshot:source",
source.getDbSnapshotArn());
String foreignArn = source.getDbSnapshotArn().replace("arn:" + partition + ":", "arn:aws:");
AwsException foreignPartition = assertThrows(AwsException.class, () ->
rdsService.copyDbSnapshot(foreignArn, "copy", false, Map.of(), null, null, targetRegion));
assertEquals("InvalidParameterValue", foreignPartition.getErrorCode());
DbSnapshot copy = rdsService.copyDbSnapshot(source.getDbSnapshotArn(), "copy", false,
Map.of(), null, null, targetRegion);
assertEquals("arn:" + partition + ":rds:" + targetRegion + ":123456789012:snapshot:copy",
copy.getDbSnapshotArn());
assertEquals("available", copy.getStatus());
}
@ParameterizedTest
@CsvSource({"cn-north-1,us-east-1,xx-nowhere-9,aws-cn",
"cn-north-1,us-east-1,cn-north-1,aws-cn",
"us-gov-west-1,us-east-1,xx-nowhere-9,aws-us-gov",
"us-east-1,cn-north-1,xx-nowhere-9,aws"})
void copyDbSnapshotRejectsRelabeledForeignSourceArn(
String deploymentRegion, String sourceRegion, String targetRegion, String targetPartition) {
regionResolver = new RegionResolver(deploymentRegion, "123456789012");
rdsService = newService(containerManager, proxyManager,
new InMemoryStorage<>(), new InMemoryStorage<>(),
new InMemoryStorage<>(), new InMemoryStorage<>(), new InMemoryStorage<>());
rdsService.createDbInstance("foreign-db", "postgres", "13",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null, null, false,
false, null, Map.of(), sourceRegion);
when(containerManager.createPostgresSnapshot(any(), eq("admin"))).thenReturn("MOCK_DUMP_DATA");
DbSnapshot foreignSource = rdsService.createDbSnapshot("source", "foreign-db", Map.of(), sourceRegion);
String relabeledArn = "arn:" + targetPartition + ":rds:" + sourceRegion
+ ":123456789012:snapshot:source";
assertNotEquals(foreignSource.getDbSnapshotArn(), relabeledArn);
AwsException foreignPartition = assertThrows(AwsException.class, () ->
rdsService.copyDbSnapshot(relabeledArn, "copy", false, Map.of(), null, null, targetRegion));
assertEquals("InvalidParameterValue", foreignPartition.getErrorCode());
rdsService.createDbInstance("local-db", "postgres", "13",
"admin", "password", "dbname", "db.t3.micro",
20, false, null, null, null, null, false,
false, null, Map.of(), targetRegion);
DbSnapshot localSource = rdsService.createDbSnapshot("local-source", "local-db", Map.of(), targetRegion);
DbSnapshot copy = rdsService.copyDbSnapshot(localSource.getDbSnapshotArn(), "copy", false,
Map.of(), null, null, targetRegion);
assertEquals("arn:" + targetPartition + ":rds:" + targetRegion + ":123456789012:snapshot:copy",
copy.getDbSnapshotArn());
assertEquals("available", copy.getStatus());
}
@Test
void copyDbSnapshotRejectsDuplicateTargetsAndUnavailableSources() {
rdsService.createDbInstance("mydb", "postgres", "13",