feat(iam): read MemoryDB from the generated tables (#9362)

Move `memorydb` from NOT_COVERED to NAMESPACES in
regen_iam_request_resources.py, so MemoryDB requests are checked on the
resources they name instead of `*`: a cluster, an ACL or a user by its name,
as <type>/<name>, the ARN MemoryDB mints, and a tag call on its ResourceArn.

A cluster and a multi-Region cluster both call their format's variable
${ClusterName}, so the generator could not tell DeleteCluster's ClusterName
from its MultiRegionClusterName and read no cluster, and filled
CreateCluster's multi-Region cluster from the new cluster's ClusterName. One
generic reading fixes both: a type of one variable is read from the one
top-level member named after the type and ending in the variable's name,
where nothing reads it yet or instead of a member named after something
else, and only when no other type the action acts on could take that member
alone. Over the whole table it changes these two MemoryDB operations and no
other.

CreateCluster marked the multi-Region cluster it may join as what it makes,
so its tags were checked on that, or on its ACL when it names none, not on
the new cluster. Where the namespace has a type named as a create is, that
type, and one whose format's leading word is that name, is what it makes; a
type whose name merely ends in the same word is not, and a related type the
request names by a member of its own is one it joins, so the cluster it
makes is recorded for its tags. Over the whole table this also stops
ElastiCache's CreateReplicationGroup from marking the global replication
group it may join as made, and marks the global replication group
CreateGlobalReplicationGroup makes.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 10:56:22 -04:00
1 parent 49a59da5e6
commit c24686a17d
8 files changed
+235 -11

No files matched your search

@@ -439,6 +439,18 @@ class RequestResourcesTest {
created("servicediscovery:CreateHttpNamespace", namespace));
}
/**
* A create whose action acts on other types tags the resource it makes when its request names it: MemoryDB's
* {@code CreateCluster} tags its new cluster, not the multi-Region cluster it may join.
*/
@Test
void aCreateActingOnOtherTypesTagsTheResourceItMakes() {
ContainerRequestContext cluster = json("{\"ClusterName\":\"cache\",\"MultiRegionClusterName\":\"global\","
+ "\"ACLName\":\"open-access\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"a\"}]}");
assertEquals(List.of("arn:aws:memorydb:us-east-1:000000000000:cluster/cache"),
created("memorydb:CreateCluster", cluster));
}
/** A namespace's stored ARNs that find nothing, and act on the resource {@code arn} names in its own account. */
private static StoredResourceArns reaching(String namespace, String arn) {
return new StoredResourceArns() {
@@ -3607,6 +3607,25 @@ class IamRequestResourceEnforcementIntegrationTest {
return userId;
}
/**
* A MemoryDB ACL is checked on the ARN its name gives, {@code acl/<name>}, the one MemoryDB mints, so a grant on one
* lets the caller describe it and not another.
*/
@Test
void aMemoryDbAclIsCheckedOnTheArnItsNameGives() {
String acl = "res-acl-" + suffix();
adminJson("memorydb", "AmazonMemoryDB.CreateACL")
.body("{\"ACLName\":\"" + acl + "\",\"UserNames\":[\"default\"]}").post("/").then().statusCode(200);
cleanup.register(() -> adminJson("memorydb", "AmazonMemoryDB.DeleteACL")
.body("{\"ACLName\":\"" + acl + "\"}").post("/"));
User user = user("res-memorydb");
user.policy(allowOn("memorydb:DescribeAcls", "arn:aws:memorydb:" + REGION + ":" + ACCOUNT + ":acl/" + acl));
send(user, "memorydb", "AmazonMemoryDB.DescribeACLs", "1.1", "{\"ACLName\":\"" + acl + "\"}")
.statusCode(200);
refusedJson(send(user, "memorydb", "AmazonMemoryDB.DescribeACLs", "1.1",
"{\"ACLName\":\"" + acl + "-other\"}"), "memorydb:DescribeAcls");
}
private static ValidatableResponse glue(String operation, String body) {
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
}
@@ -2043,6 +2043,29 @@ class ResourceArnBuilderTest {
"AlternateIdentifier.UniqueAttribute.AttributeValue")), asked);
}
// ── MemoryDB ────────────────────────────────────────────────────────────────
/**
* A MemoryDB request is checked on the cluster, ACL or user its name names, as {@code <type>/<name>}, the ARN
* MemoryDB mints. The Service Reference lists no {@code cluster} for CreateCluster but the multi-Region cluster it
* may join, named by its MultiRegionClusterName, not by the new cluster's ClusterName, though both formats call
* their variable {@code ${ClusterName}}; DeleteCluster is checked on the cluster its ClusterName names.
*/
@Test
void memoryDbChecksTheResourceItsNameNamesAsTheGeneratedTableReadsIt() {
setJsonBody("{\"ClusterName\":\"cache\"}");
assertEquals(List.of("arn:aws:memorydb:us-east-1:000000000000:cluster/cache"),
builder.buildResources("memorydb", "memorydb:DescribeClusters", ctx, "us-east-1", ACCOUNT, "aws"));
setJsonBody("{\"ClusterName\":\"cache\",\"NodeType\":\"db.t4g.small\",\"ACLName\":\"open-access\","
+ "\"MultiRegionClusterName\":\"global\"}");
assertEquals(List.of("arn:aws:memorydb:us-east-1:000000000000:acl/open-access",
"arn:aws:memorydb::000000000000:multiregioncluster/global"),
builder.buildResources("memorydb", "memorydb:CreateCluster", ctx, "us-east-1", ACCOUNT, "aws"));
setJsonBody("{\"ClusterName\":\"cache\"}");
assertEquals(List.of("arn:aws:memorydb:us-east-1:000000000000:cluster/cache"),
builder.buildResources("memorydb", "memorydb:DeleteCluster", ctx, "us-east-1", ACCOUNT, "aws"));
}
// ── S3 and S3 Control ───────────────────────────────────────────────────────
/** The resources an S3 or S3 Control request names, read from the generated table on the route it matches. */