fix(kinesisanalytics): give resource-tag conditions the tags of the application a request names (#8794)

The generated request resources give Managed Service for Apache Flink's
application type the aws:ResourceTag/ key, but no service answered the
kinesisanalytics namespace's stored tags, so a condition on an
application's tags saw none. KinesisAnalyticsV2Service now answers it:
storedTags reads the application stored under the Region the ARN names
and its name, and in the default Region under the name alone, in the
request's account, where the handlers read, in place, and matched on the
whole ARN; a read that misses both keys while a legacy record moves
looks under the Regional key again. TagResource took no lock and
UntagResource changed the map in place; both now give the application a
new map one call at a time, and the tags field is volatile.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-17 20:03:10 -04:00
1 parent 4b342dad3f
commit 5110042f6c
6 files changed
+164 -23

No files matched your search

@@ -1222,9 +1222,47 @@ class IamRequestResourceEnforcementIntegrationTest {
@Test
void anApplicationIsCheckedOnTheArnItsNameGives() {
String name = "res-app-" + suffix();
String arn = application(name, null);
assertEquals("arn:aws:kinesisanalytics:" + REGION + ":" + ACCOUNT + ":application/" + name, arn);
User user = user("res-application");
user.policy(allowOn("kinesisanalytics:DescribeApplication", arn));
describeApplication(user, name).statusCode(200);
refusedJson(describeApplication(user, name + "-other"), "kinesisanalytics:DescribeApplication");
}
/**
* An {@code aws:ResourceTag} condition reads the tags Managed Service for Apache Flink holds on the application a
* request names, as TagResource leaves them, so an allow on one team's tag lets the caller describe that team's
* application and not another's.
*/
@Test
void aKinesisAnalyticsResourceTagConditionReadsTheTagsOfTheApplication() {
String web = "[{\"Key\":\"team\",\"Value\":\"web\"}]";
String tagged = "res-app-tagged-" + suffix();
String other = "res-app-other-" + suffix();
String taggedArn = application(tagged, web);
application(other, web);
adminJson("kinesisanalytics", "KinesisAnalytics_20180523.TagResource")
.body("{\"ResourceARN\":\"" + taggedArn + "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"data\"}]}")
.post("/").then().statusCode(200);
User user = user("res-application-tags");
user.policy("{\"Effect\":\"Allow\",\"Action\":\"kinesisanalytics:DescribeApplication\",\"Resource\":\"*\","
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
describeApplication(user, tagged).statusCode(200);
refusedJson(describeApplication(user, other), "kinesisanalytics:DescribeApplication");
}
/**
* The ARN of the application {@code name} an administrator creates, with the {@code tags} list if any, deleted
* afterwards.
*/
private String application(String name, String tags) {
String arn = adminJson("kinesisanalytics", "KinesisAnalytics_20180523.CreateApplication")
.body("{\"ApplicationName\":\"" + name + "\",\"RuntimeEnvironment\":\"FLINK-1_18\","
+ "\"ServiceExecutionRole\":\"arn:aws:iam::" + ACCOUNT + ":role/flink-role\"}")
+ "\"ServiceExecutionRole\":\"arn:aws:iam::" + ACCOUNT + ":role/flink-role\""
+ (tags == null ? "" : ",\"Tags\":" + tags) + "}")
.post("/").then().statusCode(200).extract().path("ApplicationDetail.ApplicationARN");
cleanup.register(() -> adminJson("kinesisanalytics", "KinesisAnalytics_20180523.DeleteApplication")
.body("{\"ApplicationName\":\"" + name + "\",\"CreateTimestamp\":"
@@ -1232,12 +1270,7 @@ class IamRequestResourceEnforcementIntegrationTest {
.body("{\"ApplicationName\":\"" + name + "\"}").post("/").then().statusCode(200).extract()
.jsonPath(new JsonPathConfig(JsonPathConfig.NumberReturnType.BIG_DECIMAL))
.getString("ApplicationDetail.CreateTimestamp") + "}").post("/"));
assertEquals("arn:aws:kinesisanalytics:" + REGION + ":" + ACCOUNT + ":application/" + name, arn);
User user = user("res-application");
user.policy(allowOn("kinesisanalytics:DescribeApplication", arn));
describeApplication(user, name).statusCode(200);
refusedJson(describeApplication(user, name + "-other"), "kinesisanalytics:DescribeApplication");
return arn;
}
/**
@@ -5,6 +5,7 @@ import io.floci.aws.core.common.AwsArnUtils;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.RegionResolver;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.InMemoryStorage;
import io.floci.aws.core.storage.StorageFactory;
import io.floci.aws.services.kinesisanalytics.container.FlinkContainerManager;
import io.floci.aws.services.kinesisanalytics.model.ApplicationStatus;
@@ -19,6 +20,7 @@ import java.time.Instant;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -391,6 +393,55 @@ class KinesisAnalyticsV2ServiceTest {
assertEquals("dev", after.get("env"));
}
/**
* IAM's lookup reads the tags the application the ARN names holds, as the tag calls leave them, and nothing for
* another account's, another Region's or an unknown application; a tag call puts a new map, so one a reader
* already holds stays as it was.
*/
@Test
void storedTagsAreTheTagsOfTheApplicationTheArnNamesAndTaggingPutsANewMap() {
FlinkApplication app = create("demo");
String arn = app.getApplicationArn();
service.tagResource(arn, Map.of("team", "data", "env", "dev"));
Map<String, String> held = app.getTags();
service.untagResource(arn, List.of("env"));
assertEquals(Map.of("team", "data", "env", "dev"), held);
assertEquals("kinesisanalytics", service.namespace());
assertEquals(Map.of("team", "data"), service.storedTags(arn));
assertTrue(service.storedTags(arn.replace("000000000000", "111122223333")).isEmpty());
assertTrue(service.storedTags(arn.replace("us-east-1", "us-west-2")).isEmpty());
assertTrue(service.storedTags(arn.replace("application/demo", "application/nope")).isEmpty());
assertTrue(service.storedTags("arn:aws:kinesis:us-east-1:000000000000:stream/demo").isEmpty());
}
/**
* An application stored under its name alone, before applications were kept by Region, or before storage was
* account-aware, is read where the handlers find it, in place: the lookup migrates nothing.
*/
@Test
void storedTagsReadALegacyRecordInPlaceWithoutMigratingIt() {
InMemoryStorage<String, FlinkApplication> raw = new InMemoryStorage<>();
KinesisAnalyticsV2Service legacyState =
mockModeService(new AccountAwareStorageBackend<>(raw, null, "000000000000"));
FlinkApplication byName = legacyApplication("by-name");
byName.setTags(Map.of("team", "data"));
raw.put("000000000000/by-name", byName);
FlinkApplication bare = legacyApplication("bare");
bare.setTags(Map.of("team", "ops"));
raw.put("bare", bare);
FlinkApplication unscoped = legacyApplication("unscoped");
unscoped.setTags(Map.of("team", "web"));
raw.put("us-east-1/unscoped", unscoped);
assertEquals(Map.of("team", "data"), legacyState.storedTags(byName.getApplicationArn()));
assertEquals(Map.of("team", "ops"), legacyState.storedTags(bare.getApplicationArn()));
assertEquals(Map.of("team", "web"), legacyState.storedTags(unscoped.getApplicationArn()));
assertTrue(legacyState.storedTags(byName.getApplicationArn().replace("us-east-1", "us-west-2")).isEmpty());
assertEquals(Set.of("000000000000/by-name", "bare", "us-east-1/unscoped"), raw.keys());
}
@Test
void tagResourceRejectsUnknownArn() {
assertThrows(AwsException.class, () -> service.tagResource(