mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(signer): give resource-tag conditions the tags of the signing profile a request names (#8771)
The generated request resources give Signer's signing-profile type the aws:ResourceTag/ key, but no service answered the signer namespace's stored tags, so a condition on a signing profile's tags saw none. SignerService now answers it: storedTags reads the profile stored under the Region the ARN names and its name, in the request's account, where the tag handlers read, in place, and matched on the whole ARN. Tag writes already gave the profile a new map but took no lock, so two could lose one's tags; every write of a profile's tags now runs one at a time, and the tags field is volatile.
This commit is contained in:
1 parent
025009fc64
commit
1e66899a95
6 files changed
+127
-18
No files matched your search
@@ -132,6 +132,44 @@ class SignerIamEnforcementIntegrationTest {
|
||||
.then().statusCode(403);
|
||||
}
|
||||
|
||||
/**
|
||||
* An {@code aws:ResourceTag} condition reads the tags Signer holds on the profile a request names, as TagResource
|
||||
* leaves them, so an allow on one team's tag lets the caller read that team's profile and not another's.
|
||||
*/
|
||||
@Test
|
||||
void aResourceTagConditionReadsTheTagsOfTheProfile() {
|
||||
String tagged = teamProfile("Tagged" + SUFFIX);
|
||||
String other = teamProfile("Untagged" + SUFFIX);
|
||||
given().header("Authorization", auth(ACCOUNT, "signer"))
|
||||
.contentType("application/json")
|
||||
.body("{\"tags\":{\"team\":\"data\"}}")
|
||||
.when().post("/tags/arn:aws:signer:us-east-1:" + ACCOUNT + ":/signing-profiles/" + tagged)
|
||||
.then().statusCode(204);
|
||||
String key = userWithPolicy("""
|
||||
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
|
||||
"Action":"signer:GetSigningProfile","Resource":"*",
|
||||
"Condition":{"StringEquals":{"aws:ResourceTag/team":"data"}}}]}
|
||||
""");
|
||||
|
||||
given().header("Authorization", auth(key, "signer"))
|
||||
.when().get("/signing-profiles/" + tagged)
|
||||
.then().statusCode(200).body("profileName", equalTo(tagged));
|
||||
|
||||
given().header("Authorization", auth(key, "signer"))
|
||||
.when().get("/signing-profiles/" + other)
|
||||
.then().statusCode(403);
|
||||
}
|
||||
|
||||
/** A profile of the fixture account named {@code name}, tagged with the web team; its name. */
|
||||
private static String teamProfile(String name) {
|
||||
given().header("Authorization", auth(ACCOUNT, "signer"))
|
||||
.contentType("application/json")
|
||||
.body("{\"platformId\":\"AWSLambda-SHA384-ECDSA\",\"tags\":{\"team\":\"web\"}}")
|
||||
.when().put("/signing-profiles/" + name)
|
||||
.then().statusCode(200);
|
||||
return name;
|
||||
}
|
||||
|
||||
private String userWithPolicy(String policy) {
|
||||
String user = "signer-iam-" + UUID.randomUUID();
|
||||
String key = EnforcementFixtures.createUser(cleanup, baseUri.getPort(), auth(ACCOUNT, "iam"), user)
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.InMemoryStorage;
|
||||
import io.floci.aws.services.signer.model.SigningJob;
|
||||
import io.floci.aws.services.signer.model.SigningProfile;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -263,6 +264,34 @@ class SignerServiceTest {
|
||||
assertEquals("signer", service.serviceKey());
|
||||
}
|
||||
|
||||
/**
|
||||
* IAM's tag lookup reads the tags of the profile whose ARN it is given, as tag calls leave them, and those of a
|
||||
* profile stored before storage was account-aware, in place, without migrating it; nothing for an ARN of another
|
||||
* account or Region, or of no profile.
|
||||
*/
|
||||
@Test
|
||||
void storedTagsAreTheTagsOfTheProfileTheArnNames() throws Exception {
|
||||
service.putSigningProfile("MyProfile", profileRequest(), REGION);
|
||||
service.tagResource(REGION, PROFILE_ARN, Map.of("team", "data"));
|
||||
service.untagResource(REGION, PROFILE_ARN, List.of("env"));
|
||||
|
||||
InMemoryStorage<String, SigningProfile> raw = new InMemoryStorage<>();
|
||||
SignerService legacyStore = new SignerService(new AccountAwareStorageBackend<>(raw, null, ACCOUNT), jobs);
|
||||
SigningProfile legacy = new SigningProfile();
|
||||
legacy.setProfileName("Legacy");
|
||||
legacy.setArn("arn:aws:signer:us-east-1:" + ACCOUNT + ":/signing-profiles/Legacy");
|
||||
legacy.setTags(Map.of("tier", "web"));
|
||||
raw.put(REGION + "::Legacy", legacy);
|
||||
|
||||
assertEquals(Map.of("team", "data"), service.storedTags(PROFILE_ARN));
|
||||
assertEquals(Map.of("tier", "web"), legacyStore.storedTags(legacy.getArn()));
|
||||
assertTrue(raw.get(REGION + "::Legacy").isPresent());
|
||||
assertEquals(Map.of(), service.storedTags(PROFILE_ARN.replace(ACCOUNT, "111122223333")));
|
||||
assertEquals(Map.of(), service.storedTags(PROFILE_ARN.replace("us-east-1", "eu-west-1")));
|
||||
assertEquals(Map.of(), service.storedTags(PROFILE_ARN + "0"));
|
||||
assertEquals(Map.of(), service.storedTags("arn:aws:acm:us-east-1:" + ACCOUNT + ":certificate/MyProfile"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancelKeepsTheProfileAsCanceledAndStopsNewJobs() throws Exception {
|
||||
SigningProfile active = service.putSigningProfile("MyProfile", profileRequest(), REGION);
|
||||
|
||||
Reference in new issue
Block a user