feat(redshift-serverless): add resource policy actions for snapshots (#5730)

* feat(redshift-serverless): add resource policy actions for snapshots

Add PutResourcePolicy, GetResourcePolicy and DeleteResourcePolicy. A policy is
stored per account and Region and echoed in the shape of the API model, not
evaluated. It is tied to the snapshot it was put on by the snapshot's creation
time, so a snapshot recreated under the same name does not inherit it.

Required members come from the AWS model through RedshiftServerlessRequestShapes.

* fix(redshift-serverless): validate resource ARN before policy lookup and add account isolation tests

Validate resourceArn with snapshotNameFromArn at the start of require() so that foreign-account or non-snapshot ARNs return ValidationException on GetResourcePolicy and DeleteResourcePolicy even when no policy is stored. Parameterize snapshotNameFromArn so error messages reference resourceArn.

Add regression tests covering missing resourceArn on PutResourcePolicy and foreign ARN reads/deletes. Add integration test verifying policy isolation across accounts under real request contexts.
This commit is contained in:
Vũ Thế Huy authored and GitHub committed 2026-10-15 22:13:02 -04:00
1 parent 209ecd799b
commit a68e6bc768
11 files changed
+478 -9

No files matched your search

@@ -288,6 +288,32 @@ class RedshiftServerlessTest {
}
}
@Test
void resourcePolicyUsesAwsSdk() {
assumeFalse(TestFixtures.isRealAws(), "Creates resources and asserts emulator-local behavior");
try (RedshiftServerlessClient client = TestFixtures.redshiftServerlessClient()) {
String namespaceName = "floci-compat-policy-ns";
String snapshotName = "floci-compat-policy-snap";
try {
client.createNamespace(request -> request.namespaceName(namespaceName).adminUsername("admin")
.adminUserPassword("Secret123!"));
String snapshotArn = client.createSnapshot(request -> request
.snapshotName(snapshotName).namespaceName(namespaceName)).snapshot().snapshotArn();
client.putResourcePolicy(request -> request.resourceArn(snapshotArn).policy("{\"Version\":\"2012-10-17\"}"));
assertThat(client.getResourcePolicy(request -> request.resourceArn(snapshotArn))
.resourcePolicy().policy()).contains("2012-10-17");
client.deleteResourcePolicy(request -> request.resourceArn(snapshotArn));
assertThatThrownBy(() -> client.getResourcePolicy(request -> request.resourceArn(snapshotArn)))
.isInstanceOf(ResourceNotFoundException.class);
} finally {
deleteSnapshotBestEffort(client, snapshotName);
deleteBestEffort(client, namespaceName);
}
}
}
private static void deleteSnapshotBestEffort(RedshiftServerlessClient client, String snapshotName) {
try {
client.deleteSnapshot(request -> request.snapshotName(snapshotName));