feat(iam): read ElastiCache from the generated tables (#9303)

Move `elasticache` from NOT_COVERED to NAMESPACES in
regen_iam_request_resources.py, so ElastiCache requests are checked on the
resources they name instead of `*`: a cache cluster, a replication group, a
parameter or subnet group, a snapshot, a user, a user group or a serverless
cache by the identifier its request names, as <type>:<name>, the ARN
ElastiCache mints. The tag calls name their resource in ResourceName, which
the table does not read, and stay on `*`.

ModifyUserGroup is also checked on each user its UserIdsToAdd and
UserIdsToRemove name, as the Service Reference lists the user type for it:
a type the action acts on that no resource names yet takes its one variable
from a list named after it with ToAdd or ToRemove. Over the whole table this
changes ModifyUserGroup and no other operation.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-23 20:07:23 -04:00
1 parent ad651873d6
commit 39290aa8be
7 files changed
+214 -7

No files matched your search

@@ -3455,6 +3455,46 @@ class IamRequestResourceEnforcementIntegrationTest {
"dms:DeleteReplicationSubnetGroup");
}
/**
* An ElastiCache parameter group is checked on the ARN ElastiCache mints for it, {@code parametergroup:<name>}, so a
* grant on one lets the caller create it and not another.
*/
@Test
void anElastiCacheParameterGroupIsCheckedOnTheArnItsNameGives() {
String group = "res-pg-" + suffix();
cleanup.register(() -> admin("elasticache").formParam("Action", "DeleteCacheParameterGroup")
.formParam("Version", "2015-02-02").formParam("CacheParameterGroupName", group).post("/"));
User user = user("res-elasticache");
user.policy(allowOn("elasticache:CreateCacheParameterGroup",
"arn:aws:elasticache:" + REGION + ":" + ACCOUNT + ":parametergroup:" + group));
createCacheParameterGroup(user, group).statusCode(200);
refused(createCacheParameterGroup(user, group + "-other"), "elasticache:CreateCacheParameterGroup");
}
/**
* An ElastiCache user group's change is checked on each user it adds or removes too, so a deny scoped to one user
* refuses a change that adds that user, and not one that adds another.
*/
@Test
void anElastiCacheUserGroupChangeIsCheckedOnTheUsersItAdds() {
User user = user("res-elasticache-users");
user.policy(allowOn("elasticache:ModifyUserGroup", "*") + ",{\"Effect\":\"Deny\",\"Action\":"
+ "\"elasticache:ModifyUserGroup\",\"Resource\":\"arn:aws:elasticache:" + REGION + ":" + ACCOUNT
+ ":user:res-denied\"}");
refused(user.query("elasticache", "ModifyUserGroup").formParam("Version", "2015-02-02")
.formParam("UserGroupId", "res-group").formParam("UserIdsToAdd.member.1", "res-denied").post("/")
.then(), "elasticache:ModifyUserGroup");
user.query("elasticache", "ModifyUserGroup").formParam("Version", "2015-02-02")
.formParam("UserGroupId", "res-group").formParam("UserIdsToAdd.member.1", "res-other").post("/")
.then().body(not(containsString("not authorized to perform")));
}
private static ValidatableResponse createCacheParameterGroup(User user, String name) {
return user.query("elasticache", "CreateCacheParameterGroup").formParam("Version", "2015-02-02")
.formParam("CacheParameterGroupName", name).formParam("CacheParameterGroupFamily", "redis7")
.formParam("Description", "res").post("/").then();
}
private static ValidatableResponse glue(String operation, String body) {
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
}
@@ -1940,6 +1940,40 @@ class ResourceArnBuilderTest {
builder.buildResources("dms", "dms:DescribeEndpoints", ctx, "us-east-1", ACCOUNT, "aws"));
}
// ── ElastiCache ─────────────────────────────────────────────────────────────
/**
* An ElastiCache request is checked on the cluster, replication group or parameter group its identifier names, as
* {@code <type>:<name>} in the request's Region, the ARN ElastiCache mints; a tag call names its resource in
* {@code ResourceName}, which the table does not read, so it is checked on {@code *}.
*/
@Test
void elastiCacheChecksTheResourceItsIdentifierNames() {
setFormBody("Action=DescribeCacheClusters&Version=2015-02-02&CacheClusterId=cache-1");
assertEquals(List.of("arn:aws:elasticache:us-west-2:000000000000:cluster:cache-1"),
builder.buildResources("elasticache", "elasticache:DescribeCacheClusters", ctx, "us-west-2", ACCOUNT,
"aws"));
setFormBody("Action=CreateCacheParameterGroup&Version=2015-02-02&CacheParameterGroupName=tuned"
+ "&CacheParameterGroupFamily=redis7&Description=d");
assertEquals(List.of("arn:aws:elasticache:us-west-2:000000000000:parametergroup:tuned"),
builder.buildResources("elasticache", "elasticache:CreateCacheParameterGroup", ctx, "us-west-2",
ACCOUNT, "aws"));
setFormBody("Action=ListTagsForResource&Version=2015-02-02"
+ "&ResourceName=arn%3Aaws%3Aelasticache%3Aus-west-2%3A000000000000%3Acluster%3Acache-1");
assertEquals(List.of("*"), builder.buildResources("elasticache", "elasticache:ListTagsForResource", ctx,
"us-west-2", ACCOUNT, "aws"));
setFormBody("Action=DescribeCacheClusters&Version=2015-02-02");
assertEquals(List.of("*"), builder.buildResources("elasticache", "elasticache:DescribeCacheClusters", ctx,
"us-west-2", ACCOUNT, "aws"));
// A user group's change is checked on the group and on each user it adds or removes.
setFormBody("Action=ModifyUserGroup&Version=2015-02-02&UserGroupId=admins&UserIdsToAdd.member.1=alice"
+ "&UserIdsToRemove.member.1=bob");
assertEquals(List.of("arn:aws:elasticache:us-west-2:000000000000:usergroup:admins",
"arn:aws:elasticache:us-west-2:000000000000:user:alice",
"arn:aws:elasticache:us-west-2:000000000000:user:bob"),
builder.buildResources("elasticache", "elasticache:ModifyUserGroup", ctx, "us-west-2", 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. */