mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(iam): check an object's tags apart from its members on create (#7739)
The tag-on-create check reads a body's tags under any spelling a handler
might read, so that no tag a handler applies goes unchecked. An object at
the tags member was read both ways into one set: its structures as tags
and its members as a map's tags. A member named as a structure's key then
replaced that structure's tag, so KMS's CreateKey with
{"Tags":{"team":{"TagKey":"team","TagValue":"red"}}} was checked as
team="" while its handler, which iterates Tags whatever it holds, stored
team=red: a deny on aws:RequestTag/team held on neither kms:CreateKey nor
kms:TagResource.
The two readings are now sets of their own, each checked, so the tag the
handler applies is checked whatever the members are named.
OpenSearch's creates refuse such an object as a TagList, but a deny on a
tag in its structure now refuses it first, as it does a list.
This commit is contained in:
1 parent
943efbbcc4
commit
16ce8261eb
4 files changed
+76
-21
No files matched your search
@@ -100,6 +100,23 @@ class TagOnCreateTest {
|
||||
.orElseThrow().otherSpellings());
|
||||
}
|
||||
|
||||
/**
|
||||
* An object read as a list of tags and as a map gives two sets, so a member named as its structure's key does not
|
||||
* replace the tag a handler iterating the object applies.
|
||||
*/
|
||||
@Test
|
||||
void anObjectReadAsTagsAndAsAMapGivesASetForEach() {
|
||||
Tagging collision = TagOnCreate.of("kms:CreateKey", json(
|
||||
"{\"Tags\":{\"team\":{\"TagKey\":\"team\",\"TagValue\":\"red\"}}}")).orElseThrow();
|
||||
assertEquals(List.of(), collision.sets());
|
||||
assertEquals(List.of(set(Map.of("team", "red")), set(Map.of("team", ""))), collision.otherSpellings());
|
||||
assertEquals(List.of(List.of(), List.of("red"), List.of("")), TagOnCreate.requestTagContexts(collision).stream()
|
||||
.map(context -> context.getOrDefault("aws:RequestTag/team", List.of())).toList());
|
||||
// A map holding only strings is read as a map alone.
|
||||
assertEquals(List.of(set(Map.of("team", "red"))), TagOnCreate.of("kms:CreateKey", json(
|
||||
"{\"Tags\":{\"team\":\"red\"}}")).orElseThrow().otherSpellings());
|
||||
}
|
||||
|
||||
/**
|
||||
* CodeDeploy's handler reads a tag's key and value as text whatever they hold, a missing key as an empty one,
|
||||
* and so does the check; other handlers' keys are read as text when they are a number or a flag too.
|
||||
|
||||
+34
-5
@@ -171,6 +171,28 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
user.json("kms", "TrentService.CreateKey", "1.1").body(createKey).post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* KMS's handler iterates {@code Tags} whatever it holds, so an object whose member is named as its structure's key
|
||||
* still tags the key with that structure: a deny on the tag holds on the create's own action and on the tagging
|
||||
* action alike.
|
||||
*/
|
||||
@Test
|
||||
void aTagInAnObjectIsCheckedThoughAMemberOfTheSameNameIsNoTag() {
|
||||
User user = user("tag-collision");
|
||||
String allowed = allow("kms:CreateKey") + "," + allow("kms:TagResource");
|
||||
for (String action : List.of("kms:CreateKey", "kms:TagResource")) {
|
||||
user.policy(allowed + ",{\"Effect\":\"Deny\",\"Action\":\"" + action + "\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"red\"}}}");
|
||||
refusedJson(user.json("kms", "TrentService.CreateKey", "1.1").body(keyTaggedByObject("red"))
|
||||
.post("/").then(), action);
|
||||
String keyId = user.json("kms", "TrentService.CreateKey", "1.1").body(keyTaggedByObject("blue")).post("/")
|
||||
.then().statusCode(200).extract().path("KeyMetadata.KeyId");
|
||||
admin("kms").header("X-Amz-Target", "TrentService.ListResourceTags")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"KeyId\":\"" + keyId + "\"}").post("/")
|
||||
.then().statusCode(200).body("Tags.find { it.TagKey == 'team' }.TagValue", equalTo("blue"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The tagging action is found by the operation, not by the action it is authorized as: Budgets'
|
||||
* {@code CreateBudget} is authorized as {@code budgets:ModifyBudget}.
|
||||
@@ -441,8 +463,9 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
/**
|
||||
* OpenSearch refuses a {@code TagList} that is not as its model has it, before it changes anything, so no reading
|
||||
* of one can differ from the tags a domain gets: under every grant and a deny on {@code team=red}, none of these
|
||||
* creates a domain, among them an object whose structure's key is also its member's name and a tag of the denied
|
||||
* key with no value after it. {@code AddTags} shares the reader, and tags at the model's limits are kept.
|
||||
* creates a domain, among them a tag of the denied key with no value after it. An object whose structure's key is
|
||||
* also its member's name is refused by the deny, its structure read as a tag. {@code AddTags} shares the reader,
|
||||
* and tags at the model's limits are kept.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"/2021-01-01/opensearch/domain, es:CreateDomain",
|
||||
@@ -452,14 +475,15 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
String name = "tag-os-" + suffix();
|
||||
String arn = "arn:aws:es:us-east-1:" + ACCOUNT + ":domain/" + name;
|
||||
String red = "{\"Key\":\"team\",\"Value\":\"red\"}";
|
||||
String inObject = "{\"team\":" + red + "}";
|
||||
user.policy(allow(create));
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, "{\"team\":" + red + "}")).post(path).then(),
|
||||
"es:AddTags");
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, inObject)).post(path).then(), "es:AddTags");
|
||||
|
||||
user.policy(allow(create) + "," + allow("es:AddTags") + ",{\"Effect\":\"Deny\",\"Action\":\"es:AddTags\","
|
||||
+ "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"red\"}}}");
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, "[" + red + "]")).post(path).then(), "es:AddTags");
|
||||
for (String tagList : List.of("{\"team\":" + red + "}", "[" + red + ",{\"Key\":\"team\"}]",
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, inObject)).post(path).then(), "es:AddTags");
|
||||
for (String tagList : List.of("[" + red + ",{\"Key\":\"team\"}]",
|
||||
"[" + red + ",{\"Key\":\"team\",\"Value\":null}]", "[{\"Value\":\"blue\"}]",
|
||||
"[{\"Key\":\"\",\"Value\":\"blue\"}]", "[{\"Key\":123,\"Value\":\"blue\"}]",
|
||||
"[{\"Key\":\"team\",\"Value\":{\"a\":1}}]", "[\"team\"]",
|
||||
@@ -541,6 +565,11 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
"Tags":{"team":"blue"}}""".formatted(name, role);
|
||||
}
|
||||
|
||||
/** A {@code CreateKey} body whose {@code Tags} is an object, its one member named as its structure's key. */
|
||||
private static String keyTaggedByObject(String team) {
|
||||
return "{\"Tags\":{\"team\":{\"TagKey\":\"team\",\"TagValue\":\"" + team + "\"}}}";
|
||||
}
|
||||
|
||||
/** A {@code CreateAnalyzer} body tagging the analyzer with the {@code team} given, or with no tags. */
|
||||
private static String analyzer(String name, String team) {
|
||||
String tags = team == null ? "" : ",\"tags\":{\"team\":\"" + team + "\"}";
|
||||
|
||||
Reference in new issue
Block a user