mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cognito-idp): give resource-tag conditions the tags of the user pool a request names (#8753)
The generated request resources give Cognito user pools' userpool type the aws:ResourceTag/ key, but no service answered the cognito-idp namespace's stored tags, so a condition on a user pool's tags saw none. CognitoService now answers it: storedTags reads the pool stored under its id in the request's account, where the handlers read, in place, and matches the whole ARN, or the id for a pool stored before pools recorded their ARN, as DescribeUserPool's lookup by ARN does. Tag changes already store a new map under the pool's lock; the tags field is now volatile.
This commit is contained in:
1 parent
751aedde94
commit
948dcadae8
6 files changed
+94
-12
No files matched your search
@@ -1869,6 +1869,26 @@ class CognitoServiceTest {
|
||||
assertEquals(Map.of("env", "test", "team", "platform"), service.listTagsForResource(pool.getArn()));
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM's tag lookup reads the tags of the user pool whose ARN it is given, as tag calls leave them; nothing for an
|
||||
* ARN of another account or Region, or of no pool.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheUserPoolTheArnNames() {
|
||||
UserPool pool = service.createUserPool(
|
||||
Map.of("PoolName", "TaggedPool", "UserPoolTags", Map.of("env", "dev")),
|
||||
"us-east-1"
|
||||
);
|
||||
service.tagResource(pool.getArn(), Map.of("team", "data"));
|
||||
service.untagResource(pool.getArn(), List.of("env"));
|
||||
|
||||
assertEquals(Map.of("team", "data"), service.storedTags(pool.getArn()));
|
||||
assertEquals(Map.of(), service.storedTags(pool.getArn().replace(":000000000000:", ":111122223333:")));
|
||||
assertEquals(Map.of(), service.storedTags(pool.getArn().replace(":us-east-1:", ":eu-west-1:")));
|
||||
assertEquals(Map.of(), service.storedTags(pool.getArn() + "x"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::pool"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagResourceRejectsReservedKey() {
|
||||
UserPool pool = service.createUserPool(Map.of("PoolName", "TaggedPool"), "us-east-1");
|
||||
|
||||
+31
-5
@@ -518,14 +518,10 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
|
||||
@Test
|
||||
void aUserPoolIsCheckedOnTheArnItsIdNames() {
|
||||
String id = admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.CreateUserPool")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"PoolName\":\"res-pool-" + suffix() + "\"}")
|
||||
.post("/").then().statusCode(200).extract().path("UserPool.Id");
|
||||
String id = userPool(null);
|
||||
String arn = admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.DescribeUserPool")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"UserPoolId\":\"" + id + "\"}")
|
||||
.post("/").then().statusCode(200).extract().path("UserPool.Arn");
|
||||
cleanup.register(() -> admin("cognito-idp").header("X-Amz-Target", "AWSCognitoIdentityProviderService.DeleteUserPool")
|
||||
.contentType("application/x-amz-json-1.1").body("{\"UserPoolId\":\"" + id + "\"}").post("/"));
|
||||
assertEquals("arn:aws:cognito-idp:" + REGION + ":" + ACCOUNT + ":userpool/" + id, arn);
|
||||
|
||||
User user = user("res-pool");
|
||||
@@ -534,6 +530,36 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
refusedJson(describeUserPool(user, id + "x"), "cognito-idp:DescribeUserPool");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Cognito holds on the user pool a request names by its id, as
|
||||
* a tag call leaves them, so an allow on one team's tag lets the caller describe that team's pool and not
|
||||
* another's.
|
||||
*/
|
||||
@Test
|
||||
void aCognitoResourceTagConditionReadsTheTagsOfTheUserPool() {
|
||||
String tagged = userPool("{\"team\":\"web\"}");
|
||||
String other = userPool("{\"team\":\"web\"}");
|
||||
adminJson("cognito-idp", "AWSCognitoIdentityProviderService.TagResource").body("{\"ResourceArn\":\""
|
||||
+ "arn:aws:cognito-idp:" + REGION + ":" + ACCOUNT + ":userpool/" + tagged
|
||||
+ "\",\"Tags\":{\"team\":\"data\"}}").post("/").then().statusCode(200);
|
||||
|
||||
User user = user("res-pool-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"cognito-idp:DescribeUserPool\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
describeUserPool(user, tagged).statusCode(200);
|
||||
refusedJson(describeUserPool(user, other), "cognito-idp:DescribeUserPool");
|
||||
}
|
||||
|
||||
/** The id of a user pool an administrator creates, with the {@code tags} object if any, deleted afterwards. */
|
||||
private String userPool(String tags) {
|
||||
String id = adminJson("cognito-idp", "AWSCognitoIdentityProviderService.CreateUserPool")
|
||||
.body("{\"PoolName\":\"res-pool-" + suffix() + "\"" + (tags == null ? "" : ",\"UserPoolTags\":" + tags)
|
||||
+ "}").post("/").then().statusCode(200).extract().path("UserPool.Id");
|
||||
cleanup.register(() -> adminJson("cognito-idp", "AWSCognitoIdentityProviderService.DeleteUserPool")
|
||||
.body("{\"UserPoolId\":\"" + id + "\"}").post("/"));
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* A key is named by its id or by an alias, and an alias names the key it points at, so a request naming a key by
|
||||
* an alias is checked on the key the alias names, as the handler resolves it: a grant on that key allows it, a
|
||||
|
||||
Reference in new issue
Block a user