mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(paymentcryptography): give resource-tag conditions the tags of the key a request names (#8716)
The generated request resources give Payment Cryptography's key type the aws:ResourceTag/ key, but PaymentCryptographyService answered no tags, so a condition on a key's tags saw none. Its storedTags now reads the key stored under the ARN in the account and Region it names, in place, a record saved before the Region joined its storage name included, matched on the key's whole ARN. TagResource and UntagResource edited the held map in place, which only ListTagsForResource's lock kept from a half-written read; they now put a new map in place of it, and the field is volatile, so the lookup reads one whole map without the lock.
This commit is contained in:
1 parent
e078bb7b00
commit
da8cc6fb1b
6 files changed
+90
-11
No files matched your search
+26
@@ -554,6 +554,32 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
refusedJson(getPaymentKey(user, alias), "payment-cryptography:GetKey");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Payment Cryptography holds on the key a request names, so an
|
||||
* allow on one team's tag lets the caller read that team's key and not another's.
|
||||
*/
|
||||
@Test
|
||||
void aPaymentCryptographyResourceTagConditionReadsTheTagsOfTheKey() {
|
||||
String tagged = taggedPaymentKey("data");
|
||||
String other = taggedPaymentKey("web");
|
||||
|
||||
User user = user("res-key-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"payment-cryptography:GetKey\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
getPaymentKey(user, tagged).statusCode(200);
|
||||
refusedJson(getPaymentKey(user, other), "payment-cryptography:GetKey");
|
||||
}
|
||||
|
||||
/** A Payment Cryptography key an administrator creates and tags with the team; its ARN. */
|
||||
private String taggedPaymentKey(String team) {
|
||||
String key = createPaymentKey();
|
||||
admin("payment-cryptography").header("X-Amz-Target", "PaymentCryptographyControlPlane.TagResource")
|
||||
.contentType("application/x-amz-json-1.0").body("{\"ResourceArn\":\"" + key
|
||||
+ "\",\"Tags\":[{\"Key\":\"team\",\"Value\":\"" + team + "\"}]}")
|
||||
.post("/").then().statusCode(200);
|
||||
return key;
|
||||
}
|
||||
|
||||
/**
|
||||
* A tagging request names its key by the ARN of one, as the reference takes it there, so a request naming it by
|
||||
* its id names no key for the check and is refused: a deny on the key is not skipped by naming it another way.
|
||||
|
||||
+19
@@ -43,6 +43,25 @@ class PaymentCryptographyServiceTest {
|
||||
new PaymentCryptographyRequestContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM's tag lookup reads the tags held on the key the whole ARN names, without the service's lock: tagging puts a
|
||||
* new map in place of the held one, so a set read before a change stays whole; nothing for another Region's ARN.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheKeyTheArnNamesAndTaggingPutsANewMap() {
|
||||
PaymentCryptographyKey key = createKey("us-east-1");
|
||||
service.tag(key, Map.of("team", "data"));
|
||||
Map<String, String> held = service.storedTags(key.getArn());
|
||||
|
||||
service.tag(key, Map.of("env", "prod"));
|
||||
service.untag(key, List.of("team"));
|
||||
|
||||
assertEquals(Map.of("team", "data"), held);
|
||||
assertEquals(Map.of("env", "prod"), service.storedTags(key.getArn()));
|
||||
assertEquals(Map.of(), service.storedTags(key.getArn().replace(":us-east-1:", ":eu-west-1:")));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:s3:::bucket"));
|
||||
}
|
||||
|
||||
/** A key of the given algorithm and class, for the tests that need one. */
|
||||
private PaymentCryptographyKey createKey(String region, String algorithm, String keyClass,
|
||||
String usage, Map<String, Boolean> modes) {
|
||||
|
||||
Reference in new issue
Block a user