fix(iam): check Kinesis Data Streams requests on the resources they name, from the generated table (#8989)

Kinesis was built by hand: ResourceArnBuilder read a request's
StreamARN, StreamName or ResourceARN into one ARN and checked everything
else on stream/*, the request resources table held no Kinesis operation,
and nothing gave a policy condition a stream's tags. kinesis moves from
HAND_BUILT to NAMESPACES, so the table gives each operation the
resources botocore's members name as the Service Reference types them:
the stream by StreamARN or StreamName, a consumer by ConsumerARN, a
tagged resource by ResourceARN, and the KMS key StartStreamEncryption
and StopStreamEncryption name. Its ResourceArnBuilder branch goes. Only
Kinesis's operations change in the table. KinesisStoredResourceArns
answers a stream's or a consumer's stored tags; the tag calls give the
resource a new map under their lock, and the tags fields are volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-19 10:04:27 -04:00
1 parent ad0e47910f
commit 43d6ea4961
11 files changed
+237 -61

No files matched your search

@@ -1041,6 +1041,42 @@ class IamRequestResourceEnforcementIntegrationTest {
return arn;
}
/**
* A Kinesis request is checked on the stream its StreamName or StreamARN names, from the generated table, so a
* grant on one stream does not reach another; and an {@code aws:ResourceTag} condition reads the tags Kinesis
* holds on that stream, as AddTagsToStream leaves them.
*/
@Test
void aKinesisRequestIsCheckedOnTheStreamItNamesWithItsTags() {
String tagged = kinesisStream("res-stream-" + suffix());
String other = kinesisStream("res-stream-" + suffix());
adminJson("kinesis", "Kinesis_20131202.AddTagsToStream").body("{\"StreamName\":\"" + tagged
+ "\",\"Tags\":{\"team\":\"data\"}}").post("/").then().statusCode(200);
String streams = "arn:aws:kinesis:" + REGION + ":" + ACCOUNT + ":stream/";
User user = user("res-stream");
user.policy(allowOn("kinesis:DescribeStreamSummary", streams + tagged) + ",{\"Effect\":\"Allow\","
+ "\"Action\":\"kinesis:ListShards\",\"Resource\":\"*\",\"Condition\":{\"StringEquals\":"
+ "{\"aws:ResourceTag/team\":\"data\"}}}");
send(user, "kinesis", "Kinesis_20131202.DescribeStreamSummary", "1.1", "{\"StreamName\":\"" + tagged + "\"}")
.statusCode(200);
refusedJson(send(user, "kinesis", "Kinesis_20131202.DescribeStreamSummary", "1.1",
"{\"StreamARN\":\"" + streams + other + "\"}"), "kinesis:DescribeStreamSummary");
send(user, "kinesis", "Kinesis_20131202.ListShards", "1.1", "{\"StreamName\":\"" + tagged + "\"}")
.statusCode(200);
refusedJson(send(user, "kinesis", "Kinesis_20131202.ListShards", "1.1", "{\"StreamName\":\"" + other + "\"}"),
"kinesis:ListShards");
}
/** A Kinesis stream of one shard an administrator creates, deleted after the test; its name. */
private String kinesisStream(String name) {
adminJson("kinesis", "Kinesis_20131202.CreateStream").body("{\"StreamName\":\"" + name
+ "\",\"ShardCount\":1}").post("/").then().statusCode(200);
cleanup.register(() -> adminJson("kinesis", "Kinesis_20131202.DeleteStream").body("{\"StreamName\":\""
+ name + "\"}").post("/").then().statusCode(200));
return name;
}
@Test
void aCloudMapNamespaceAndServiceAreCheckedOnTheArnsTheirIdsGive() {
String namespaceId = cloudMapNamespace("res-ns-" + suffix());
@@ -1304,19 +1304,28 @@ class ResourceArnBuilderTest {
// ── Kinesis ──────────────────────────────────────────────────────────────────
/** A Kinesis request is checked on the stream its StreamName or StreamARN names, read from the generated table. */
@Test
void kinesisBuildsArnFromStreamName() {
void kinesisChecksTheStreamItsNameOrArnNames() {
setJsonBody("{\"StreamName\":\"order-events\"}");
String arn = builder.build("kinesis", ctx, "us-east-1", "000000000000");
assertEquals("arn:aws:kinesis:us-east-1:000000000000:stream/order-events", arn);
}
@Test
void kinesisBuildsArnFromStreamArn() {
assertEquals(List.of("arn:aws:kinesis:us-east-1:000000000000:stream/order-events"),
builder.buildResources("kinesis", "kinesis:PutRecord", ctx, "us-east-1", ACCOUNT, "aws"));
String fullArn = "arn:aws:kinesis:us-east-1:000000000000:stream/order-events";
setJsonBody("{\"StreamARN\":\"" + fullArn + "\"}");
String arn = builder.build("kinesis", ctx, "us-east-1", "000000000000");
assertEquals(fullArn, arn);
assertEquals(List.of(fullArn),
builder.buildResources("kinesis", "kinesis:DescribeStreamSummary", ctx, "us-east-1", ACCOUNT, "aws"));
}
/** A consumer is checked on its ARN, and a tag call on the resource its ResourceARN names. */
@Test
void kinesisChecksAConsumerAndATaggedResourceOnTheirArns() {
String consumer = "arn:aws:kinesis:us-east-1:000000000000:stream/order-events/consumer/reader:1700000000";
setJsonBody("{\"ConsumerARN\":\"" + consumer + "\"}");
assertEquals(List.of(consumer),
builder.buildResources("kinesis", "kinesis:DescribeStreamConsumer", ctx, "us-east-1", ACCOUNT, "aws"));
setJsonBody("{\"ResourceARN\":\"" + consumer + "\",\"Tags\":{}}");
assertEquals(List.of(consumer),
builder.buildResources("kinesis", "kinesis:TagResource", ctx, "us-east-1", ACCOUNT, "aws"));
}
// ── Secrets Manager ──────────────────────────────────────────────────────────