diff --git a/docs/services/iam.md b/docs/services/iam.md
index 84fc302e21..dfdd11dbd4 100644
--- a/docs/services/iam.md
+++ b/docs/services/iam.md
@@ -3308,7 +3308,8 @@ floci populates:
Payment Cryptography for its keys, Resource Explorer for its indexes and views, Application Auto Scaling for its
scalable targets, ECS for its clusters, task definitions, services, capacity providers, tasks and container
instances, ACM for its certificates, Firehose for its delivery streams, Cognito for its user pools and identity
- pools, and OpenSearch for its domains. Tag keys differing only in case are one condition key holding every value.
+ pools, OpenSearch for its domains, and Signer for its signing profiles. Tag keys differing only in case are one
+ condition key holding every value.
- EC2 resource keys such as a network interface's `ec2:Vpc`, `ec2:Subnet`, `ec2:AvailabilityZone` and
`ec2:NetworkInterfaceID`: for every action on a resource EC2 holds, the members of the resource the
key names, an ARN for a key the Service Reference types as one. `resourceKeys` in
diff --git a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
index dbeb6e0260..87ceb8d349 100644
--- a/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
+++ b/src/main/java/io/floci/aws/core/common/StoredResourceArns.java
@@ -45,10 +45,10 @@ import java.util.Optional;
* key value store a name names and the tags of any resource it tags; ECS, for the revision a task definition
* reference resolves to, its default cluster and the tags of a cluster, a task definition, a service, a capacity
* provider, a task or a container instance; ACM, for the tags of a certificate; Firehose, for the tags of a delivery
- * stream; Cognito, for the tags of a user pool or an identity pool; OpenSearch, for the tags of a domain); looked up
- * lazily by {@code ResourceArnBuilder} and {@code IamConditionContextResolver} through
- * {@code Instance} for the namespace a request or an ARN is of, so IAM never depends on that
- * service directly.
+ * stream; Cognito, for the tags of a user pool or an identity pool; OpenSearch, for the tags of a domain; Signer, for
+ * the tags of a signing profile); looked up lazily by {@code ResourceArnBuilder} and
+ * {@code IamConditionContextResolver} through {@code Instance} for the namespace a request or an
+ * ARN is of, so IAM never depends on that service directly.
*
* Each answer is a lookup of what the service holds, asked for by an entry of the generated table ({@code find},
* {@code through}, a default, {@code forwarded}, a type's {@code resourceTagKeys}): never a fact about what an operation acts on, which the table alone
diff --git a/src/main/java/io/floci/aws/services/signer/SignerService.java b/src/main/java/io/floci/aws/services/signer/SignerService.java
index a77c432f78..54e8694914 100644
--- a/src/main/java/io/floci/aws/services/signer/SignerService.java
+++ b/src/main/java/io/floci/aws/services/signer/SignerService.java
@@ -8,6 +8,7 @@ import io.floci.aws.core.common.AwsException;
import io.floci.aws.core.common.PaginatedResult;
import io.floci.aws.core.common.Pagination;
import io.floci.aws.core.common.Resettable;
+import io.floci.aws.core.common.StoredResourceArns;
import io.floci.aws.core.common.TagHandler;
import io.floci.aws.core.storage.AccountAwareStorageBackend;
import io.floci.aws.core.storage.StorageFactory;
@@ -44,7 +45,7 @@ import java.util.regex.Pattern;
* S3. Both are documented on the service page and asserted by the service tests.
*/
@ApplicationScoped
-public class SignerService implements Resettable, TagHandler {
+public class SignerService implements Resettable, TagHandler, StoredResourceArns {
private static final Logger LOG = Logger.getLogger(SignerService.class);
private static final String SERVICE = "signer";
@@ -142,10 +143,11 @@ public class SignerService implements Resettable, TagHandler {
new LinkedHashMap<>(), requestedTags, region);
}
- private SigningProfile applyProfile(String profileName, SignerPlatforms.Platform platform,
- String certificateArn, String[] validity, JsonNode overrides,
- Map signingParameters,
- Map requestedTags, String region) {
+ /** Sets the tags too, so it runs one at a time with the other tag writes ({@link #tagResource}). */
+ private synchronized SigningProfile applyProfile(String profileName, SignerPlatforms.Platform platform,
+ String certificateArn, String[] validity, JsonNode overrides,
+ Map signingParameters,
+ Map requestedTags, String region) {
SigningProfile profile = profiles.get(storageKey(region, profileName)).orElse(null);
boolean created = profile == null;
if (created) {
@@ -233,11 +235,12 @@ public class SignerService implements Resettable, TagHandler {
/**
* Writes a profile record for a CloudFormation resource that was provisioned before this
* service existed, keeping the identifiers that stack already handed out instead of minting a
- * version: the adoption a later tags-only update needs.
+ * version: the adoption a later tags-only update needs. It replaces the record, tags included, so
+ * it runs one at a time with the tag writes.
*/
- public SigningProfile adoptSigningProfile(String profileName, String platformId, String version,
- String validityType, Integer validityValue,
- String region) {
+ public synchronized SigningProfile adoptSigningProfile(String profileName, String platformId, String version,
+ String validityType, Integer validityValue,
+ String region) {
validateProfileName(profileName);
SignerPlatforms.Platform platform = platformOf(platformId);
String arn = AwsArnUtils.Arn.of(SERVICE, region, profiles.accountId(),
@@ -529,7 +532,7 @@ public class SignerService implements Resettable, TagHandler {
* {@code Tags} property on an update that changed nothing else. Unlike {@link #tagResource}, it
* removes the tags the caller left out.
*/
- public void replaceTags(String profileName, Map tags, String region) {
+ public synchronized void replaceTags(String profileName, Map tags, String region) {
validateProfileName(profileName);
SigningProfile profile = requireProfile(profileName, region);
Map resolved = tags == null ? new LinkedHashMap<>() : new LinkedHashMap<>(tags);
@@ -548,8 +551,12 @@ public class SignerService implements Resettable, TagHandler {
return new LinkedHashMap<>(requireProfileFromArn(region, arn).getTags());
}
+ /**
+ * Gives the profile a new map. Every write of a profile's tags runs one at a time, so none loses another's, and a
+ * reader holds one whole set.
+ */
@Override
- public void tagResource(String region, String arn, Map tags) {
+ public synchronized void tagResource(String region, String arn, Map tags) {
validateTags(tags);
SigningProfile profile = requireProfileFromArn(region, arn);
Map merged = new LinkedHashMap<>(profile.getTags());
@@ -562,7 +569,7 @@ public class SignerService implements Resettable, TagHandler {
}
@Override
- public void untagResource(String region, String arn, List tagKeys) {
+ public synchronized void untagResource(String region, String arn, List tagKeys) {
SigningProfile profile = requireProfileFromArn(region, arn);
Map remaining = new LinkedHashMap<>(profile.getTags());
tagKeys.forEach(remaining::remove);
@@ -576,6 +583,40 @@ public class SignerService implements Resettable, TagHandler {
jobs.clear();
}
+ @Override
+ public String namespace() {
+ return SERVICE;
+ }
+
+ /** A request names a signing profile by its name, which its ARN carries whole, so there is nothing to find. */
+ @Override
+ public Optional find(String type, List names, String region) {
+ return Optional.empty();
+ }
+
+ /**
+ * The tags of the signing profile whose ARN is {@code arn}, in the request's account, where the tag handlers read:
+ * an ARN of another account names none. Read in place under the Region the ARN names and the profile's name, a
+ * profile stored before storage was account-aware included, and matched on the whole ARN. Tag writes give the
+ * profile a new map, so the read is of one whole set.
+ */
+ @Override
+ public Map storedTags(String arn) {
+ if (!AwsArnUtils.isArnFor(arn, SERVICE)) {
+ return Map.of();
+ }
+ AwsArnUtils.Arn parsed = AwsArnUtils.parse(arn);
+ if (!parsed.accountId().equals(profiles.accountId()) || !parsed.resource().startsWith(PROFILE_RESOURCE)) {
+ return Map.of();
+ }
+ Map tags = AccountAwareStorageBackend.readInAccount(profiles, parsed.accountId(),
+ storageKey(parsed.region(), parsed.resource().substring(PROFILE_RESOURCE.length())))
+ .filter(profile -> arn.equals(profile.getArn()))
+ .map(SigningProfile::getTags)
+ .orElse(Map.of());
+ return new LinkedHashMap<>(tags);
+ }
+
// ---------------------------------------------------------------- helpers
private SigningProfile requireProfile(String profileName, String region) {
diff --git a/src/main/java/io/floci/aws/services/signer/model/SigningProfile.java b/src/main/java/io/floci/aws/services/signer/model/SigningProfile.java
index 043749aa63..7fe08e0746 100644
--- a/src/main/java/io/floci/aws/services/signer/model/SigningProfile.java
+++ b/src/main/java/io/floci/aws/services/signer/model/SigningProfile.java
@@ -81,7 +81,7 @@ public class SigningProfile {
private Integer signatureValidityPeriodValue;
private JsonNode overrides;
private Map signingParameters = new LinkedHashMap<>();
- private Map tags = new LinkedHashMap<>();
+ private volatile Map tags = new LinkedHashMap<>();
private String status;
private String statusReason;
private Long revocationEffectiveFrom;
diff --git a/src/test/java/io/floci/aws/services/signer/SignerIamEnforcementIntegrationTest.java b/src/test/java/io/floci/aws/services/signer/SignerIamEnforcementIntegrationTest.java
index d506c89128..236f9f03d5 100644
--- a/src/test/java/io/floci/aws/services/signer/SignerIamEnforcementIntegrationTest.java
+++ b/src/test/java/io/floci/aws/services/signer/SignerIamEnforcementIntegrationTest.java
@@ -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)
diff --git a/src/test/java/io/floci/aws/services/signer/SignerServiceTest.java b/src/test/java/io/floci/aws/services/signer/SignerServiceTest.java
index 473a9c3e6e..8d73d9513d 100644
--- a/src/test/java/io/floci/aws/services/signer/SignerServiceTest.java
+++ b/src/test/java/io/floci/aws/services/signer/SignerServiceTest.java
@@ -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 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);