fix(firehose): give resource-tag conditions the tags of the delivery stream a request names (#8743)

The generated request resources give Firehose's deliverystream type the
aws:ResourceTag/ key, but no service answered the firehose namespace's
stored tags, so a condition on a delivery stream's tags saw none.
FirehoseService now answers it: storedTags reads the stream in the
request's account, where the handlers read, in place under its key in
the ARN's Region or the account's key from before the key named the
Region, and matched on the whole ARN. TagDeliveryStream and
UntagDeliveryStream read, changed and wrote the stream with no lock, so
one could drop another's tags or write back a stream a delete had just
removed; they now hold the per-stream lock a delete and a Redshift
update hold, and the tags field is volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 10:31:00 -04:00
1 parent 6618ae3de6
commit f9e88a2215
6 files changed
+139 -27

No files matched your search

@@ -239,6 +239,35 @@ class FirehoseServiceTest {
"legacy entries from another region must not be adopted");
}
/**
* IAM's tag lookup reads the tags of the delivery stream whose ARN it is given, as tag calls leave them, and those
* of one stored under the account's key from before the key named the Region, in place, without migrating it;
* nothing for an ARN of another account or Region, or of no stream.
*/
@Test
@SuppressWarnings("unchecked")
void storedTagsAreTheTagsOfTheDeliveryStreamTheArnNames() {
String arn = firehoseService.createDeliveryStream("tagged", null);
firehoseService.tagDeliveryStream("tagged", List.of(new DeliveryStreamDescription.Tag("team", "data"),
new DeliveryStreamDescription.Tag("env", "test")));
firehoseService.untagDeliveryStream("tagged", List.of("env"));
String legacyArn = "arn:aws:firehose:us-east-1:000000000000:deliverystream/legacy";
DeliveryStreamDescription legacy = new DeliveryStreamDescription("legacy", legacyArn, null, null);
legacy.setAccountId("000000000000");
legacy.setTags(List.of(new DeliveryStreamDescription.Tag("tier", "web")));
AccountAwareStorageBackend<DeliveryStreamDescription> streams =
(AccountAwareStorageBackend<DeliveryStreamDescription>) backends.get("firehose/streams.json");
streams.putForAccount("000000000000", "legacy", legacy);
assertEquals(Map.of("team", "data"), firehoseService.storedTags(arn));
assertEquals(Map.of("tier", "web"), firehoseService.storedTags(legacyArn));
assertTrue(streams.getForAccount("000000000000", "legacy").isPresent());
assertEquals(Map.of(), firehoseService.storedTags(arn.replace(":000000000000:", ":111122223333:")));
assertEquals(Map.of(), firehoseService.storedTags(arn.replace(":us-east-1:", ":eu-west-1:")));
assertEquals(Map.of(), firehoseService.storedTags(arn + "0"));
assertEquals(Map.of(), firehoseService.storedTags("arn:aws:s3:::tagged"));
}
@Test
@SuppressWarnings("unchecked")
void aPersistedRedshiftBackupGetsTheDefaultsOnDescribe() {
@@ -804,6 +804,32 @@ class IamRequestResourceEnforcementIntegrationTest {
refusedJson(describeDeliveryStream(user, name + "-other"), "firehose:DescribeDeliveryStream");
}
/**
* An {@code aws:ResourceTag} condition reads the tags Firehose holds on the delivery stream a request names, as a
* tag call leaves them, so an allow on one team's tag lets the caller describe that team's stream and not
* another's.
*/
@Test
void aFirehoseResourceTagConditionReadsTheTagsOfTheDeliveryStream() {
String tagged = deliveryStream("res-tag-stream-" + suffix(), "web");
String other = deliveryStream("res-tag-stream-" + suffix(), "web");
adminJson("firehose", "Firehose_20150804.TagDeliveryStream").body("{\"DeliveryStreamName\":\"" + tagged
+ "\",\"Tags\":" + teamTag("data") + "}").post("/").then().statusCode(200);
User user = user("res-stream-tags");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"firehose:DescribeDeliveryStream\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
describeDeliveryStream(user, tagged).statusCode(200);
refusedJson(describeDeliveryStream(user, other), "firehose:DescribeDeliveryStream");
}
/** A Firehose delivery stream of the name, tagged with the team, deleted afterwards. */
private String deliveryStream(String name, String team) {
return created("firehose", "Firehose_20150804.CreateDeliveryStream", "{\"DeliveryStreamName\":\"" + name
+ "\",\"Tags\":" + teamTag(team) + "}", "Firehose_20150804.DeleteDeliveryStream",
"{\"DeliveryStreamName\":\"" + name + "\"}", name);
}
/** An identity pool is checked on the ARN its id gives, the one Cognito tags it under. */
@Test
void anIdentityPoolIsCheckedOnTheArnItsIdGives() {