mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(acm): give resource-tag conditions the tags of the certificate a request names (#8737)
The generated request resources give ACM's certificate type the aws:ResourceTag/ key, but no service answered the acm namespace's stored tags, so a condition on a certificate's tags saw none. AcmService now answers it: storedTags reads the certificate stored under the key of the Region the ARN names, in the request's account, where the handlers read, in place, and matched on the whole ARN. Tag changes already store a new map under the service's lock; the tags field is now volatile.
This commit is contained in:
1 parent
c6faa73eb7
commit
2fdcbecdf0
6 files changed
+104
-12
No files matched your search
@@ -69,6 +69,26 @@ class AcmServicePersistenceTest {
|
||||
assertEquals(cert.getCertificateChain(), loaded.getCertificateChain());
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM's tag lookup reads the tags of the certificate whose ARN it is given, as tag calls leave them and a restart
|
||||
* keeps them; nothing for an ARN of another account or Region, or of no certificate.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheCertificateTheArnNames(@TempDir Path dir) {
|
||||
AcmService first = newService(dir);
|
||||
String arn = first.requestCertificate("example.com", List.of(), ValidationMethod.DNS, null,
|
||||
KeyAlgorithm.RSA_2048, null, null, Map.of("Env", "test"), REGION).getArn();
|
||||
first.addTagsToCertificate(arn, Map.of("team", "data"), REGION);
|
||||
first.removeTagsFromCertificate(arn, List.of(Map.of("Key", "Env")), REGION);
|
||||
|
||||
assertEquals(Map.of("team", "data"), first.storedTags(arn));
|
||||
assertEquals(Map.of("team", "data"), newService(dir).storedTags(arn));
|
||||
assertEquals(Map.of(), first.storedTags(arn.replace(":000000000000:", ":111122223333:")));
|
||||
assertEquals(Map.of(), first.storedTags(arn.replace(":" + REGION + ":", ":eu-west-1:")));
|
||||
assertEquals(Map.of(), first.storedTags(arn + "0"));
|
||||
assertEquals(Map.of(), first.storedTags("arn:aws:s3:::example"));
|
||||
}
|
||||
|
||||
private AcmService newService(Path dir) {
|
||||
RegionResolver regionResolver = mock(RegionResolver.class);
|
||||
when(regionResolver.getAccountId()).thenReturn("000000000000");
|
||||
|
||||
+40
-5
@@ -847,11 +847,7 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
|
||||
@Test
|
||||
void aCertificateIsCheckedOnItsArn() {
|
||||
String arn = adminJson("acm", "CertificateManager.RequestCertificate")
|
||||
.body("{\"DomainName\":\"res-" + suffix() + ".example.com\"}").post("/").then().statusCode(200)
|
||||
.extract().path("CertificateArn");
|
||||
cleanup.register(() -> adminJson("acm", "CertificateManager.DeleteCertificate")
|
||||
.body("{\"CertificateArn\":\"" + arn + "\"}").post("/"));
|
||||
String arn = certificate(null);
|
||||
assertTrue(arn.startsWith("arn:aws:acm:" + REGION + ":" + ACCOUNT + ":certificate/"), arn);
|
||||
|
||||
User user = user("res-certificate");
|
||||
@@ -861,6 +857,45 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
"acm:DescribeCertificate");
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags ACM holds on the certificate a request names, as a tag call
|
||||
* leaves them, so an allow on one team's tag lets the caller read that team's certificate and not another's, and
|
||||
* a deny on it holds, also for the certificate's id under another Region's ARN, which is checked in the request's
|
||||
* Region too, where the handler reads it.
|
||||
*/
|
||||
@Test
|
||||
void anAcmResourceTagConditionReadsTheTagsOfTheCertificate() {
|
||||
String tagged = certificate(teamTag("web"));
|
||||
String other = certificate(teamTag("web"));
|
||||
adminJson("acm", "CertificateManager.AddTagsToCertificate").body("{\"CertificateArn\":\"" + tagged
|
||||
+ "\",\"Tags\":" + teamTag("data") + "}").post("/").then().statusCode(200);
|
||||
|
||||
User user = user("res-acm-tags");
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"acm:DescribeCertificate\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
describeCertificate(user, tagged).statusCode(200);
|
||||
refusedJson(describeCertificate(user, other), "acm:DescribeCertificate");
|
||||
|
||||
User denied = user("res-acm-tag-deny");
|
||||
denied.policy(allowOn("acm:DescribeCertificate", "*") + ",{\"Effect\":\"Deny\",\"Action\":"
|
||||
+ "\"acm:DescribeCertificate\",\"Resource\":\"*\",\"Condition\":{\"StringEquals\":"
|
||||
+ "{\"aws:ResourceTag/team\":\"data\"}}}");
|
||||
refusedJson(describeCertificate(denied, tagged), "acm:DescribeCertificate");
|
||||
describeCertificate(denied, other).statusCode(200);
|
||||
refusedJson(describeCertificate(denied, tagged.replace(":" + REGION + ":", ":eu-west-1:")),
|
||||
"acm:DescribeCertificate");
|
||||
}
|
||||
|
||||
/** The ARN of a certificate an administrator requests, with the {@code tags} list if any, deleted afterwards. */
|
||||
private String certificate(String tags) {
|
||||
String arn = adminJson("acm", "CertificateManager.RequestCertificate")
|
||||
.body("{\"DomainName\":\"res-" + suffix() + ".example.com\"" + (tags == null ? "" : ",\"Tags\":" + tags)
|
||||
+ "}").post("/").then().statusCode(200).extract().path("CertificateArn");
|
||||
cleanup.register(() -> adminJson("acm", "CertificateManager.DeleteCertificate")
|
||||
.body("{\"CertificateArn\":\"" + arn + "\"}").post("/"));
|
||||
return arn;
|
||||
}
|
||||
|
||||
/**
|
||||
* A pipeline is checked on the ARN its name gives, a request naming it by a bare {@code name} too, and a webhook
|
||||
* on {@code webhook:<name>}, the ARN CodePipeline gives it.
|
||||
|
||||
Reference in new issue
Block a user