lambdaProfiles = signer.listSigningProfiles(
+ r -> r.platformId(PLATFORM_LAMBDA)).profiles();
+ assertThat(lambdaProfiles).extracting(SigningProfile::profileName).contains(PROFILE);
+ assertThat(lambdaProfiles).allMatch(profile -> PLATFORM_LAMBDA.equals(profile.platformId()));
+
+ ListSigningProfilesResponse firstPage = signer.listSigningProfiles(r -> r.maxResults(1));
+ assertThat(firstPage.profiles()).hasSize(1);
+ assertThat(firstPage.nextToken()).isNotNull();
+
+ ListSigningProfilesResponse secondPage = signer.listSigningProfiles(
+ r -> r.maxResults(1).nextToken(firstPage.nextToken()));
+ assertThat(secondPage.profiles()).hasSize(1);
+ assertThat(secondPage.profiles().get(0).profileName())
+ .isNotEqualTo(firstPage.profiles().get(0).profileName());
+ }
+
+ @Test
+ @DisplayName("Profile permissions move the revision id the removal requires")
+ void profilePermissions() {
+ signer.putSigningProfile(r -> r.profileName(PROFILE).platformId(PLATFORM_LAMBDA));
+
+ String revisionId = signer.addProfilePermission(r -> r
+ .profileName(PROFILE)
+ .action("signer:SignPayload")
+ .principal("123456789012")
+ .statementId("cross-account"))
+ .revisionId();
+
+ assertThat(signer.listProfilePermissions(r -> r.profileName(PROFILE)).permissions())
+ .singleElement()
+ .satisfies(permission -> {
+ assertThat(permission.action()).isEqualTo("signer:SignPayload");
+ assertThat(permission.principal()).isEqualTo("123456789012");
+ assertThat(permission.statementId()).isEqualTo("cross-account");
+ });
+
+ String nextRevisionId = signer.removeProfilePermission(r -> r
+ .profileName(PROFILE)
+ .statementId("cross-account")
+ .revisionId(revisionId)).revisionId();
+
+ assertThat(nextRevisionId).isNotEqualTo(revisionId);
+ assertThat(signer.listProfilePermissions(r -> r.profileName(PROFILE)).permissions()).isEmpty();
+ }
+
+ @Test
+ @DisplayName("A signing job is recorded, described, and can be revoked")
+ void signingJobLifecycle() {
+ signer.putSigningProfile(r -> r.profileName(PROFILE).platformId(PLATFORM_LAMBDA));
+
+ jobId = signer.startSigningJob(r -> r
+ .profileName(PROFILE)
+ .source(Source.builder()
+ .s3(S3Source.builder()
+ .bucketName("artifacts")
+ .key("app.zip")
+ .version("1")
+ .build())
+ .build())
+ .destination(Destination.builder()
+ .s3(S3Destination.builder()
+ .bucketName("signed")
+ .prefix("out/")
+ .build())
+ .build())
+ .clientRequestToken("sdk-token-1"))
+ .jobId();
+
+ DescribeSigningJobResponse job = signer.describeSigningJob(r -> r.jobId(jobId));
+
+ assertThat(job.status()).isEqualTo(SigningStatus.FAILED);
+ assertThat(job.statusReason()).contains("does not sign artifacts");
+ assertThat(job.profileName()).isEqualTo(PROFILE);
+ assertThat(job.platformId()).isEqualTo(PLATFORM_LAMBDA);
+ assertThat(job.source().s3().bucketName()).isEqualTo("artifacts");
+ assertThat(job.source().s3().key()).isEqualTo("app.zip");
+ assertThat(job.signedObject()).isNull();
+ assertThat(job.createdAt()).isNotNull();
+ assertThat(job.signatureExpiresAt()).isNull();
+ assertThat(job.revocationRecord()).isNull();
+
+ assertThat(signer.listSigningJobs(r -> r.status(SigningStatus.FAILED)).jobs())
+ .extracting(SigningJob::jobId)
+ .contains(jobId);
+
+ // A job with no signature has nothing to revoke.
+ assertThatThrownBy(() -> signer.revokeSignature(
+ r -> r.jobId(jobId).reason("artifact withdrawn")))
+ .isInstanceOf(ValidationException.class);
+ }
+
+ @Test
+ @DisplayName("Revoking a profile stops it accepting new jobs")
+ void revokeSigningProfile() {
+ String profileVersion = signer.putSigningProfile(r -> r
+ .profileName(PROFILE)
+ .platformId(PLATFORM_LAMBDA))
+ .profileVersion();
+
+ signer.revokeSigningProfile(r -> r
+ .profileName(PROFILE)
+ .profileVersion(profileVersion)
+ .reason("key compromised")
+ .effectiveTime(Instant.parse("2026-01-01T00:00:00Z")));
+
+ GetSigningProfileResponse revoked = signer.getSigningProfile(r -> r.profileName(PROFILE));
+ assertThat(revoked.status()).isEqualTo(SigningProfileStatus.REVOKED);
+ assertThat(revoked.revocationRecord().revocationEffectiveFrom()).isNotNull();
+
+ assertThatThrownBy(() -> signer.startSigningJob(r -> r
+ .profileName(PROFILE)
+ .source(Source.builder().s3(S3Source.builder()
+ .bucketName("artifacts").key("app.zip").version("1").build()).build())
+ .destination(Destination.builder().s3(S3Destination.builder()
+ .bucketName("signed").build()).build())
+ .clientRequestToken("sdk-token-revoked")))
+ .isInstanceOf(ValidationException.class);
+ }
+
+ @Test
+ @DisplayName("ListSigningPlatforms and GetSigningPlatform describe the AWS platforms")
+ void signingPlatforms() {
+ ListSigningPlatformsResponse platforms = signer.listSigningPlatforms();
+ assertThat(platforms.platforms())
+ .extracting(SigningPlatform::platformId)
+ .contains(PLATFORM_LAMBDA, PLATFORM_NOTATION);
+
+ GetSigningPlatformResponse platform = signer.getSigningPlatform(r -> r.platformId(PLATFORM_LAMBDA));
+ assertThat(platform.displayName()).isEqualTo("AWS Lambda");
+ assertThat(platform.categoryAsString()).isEqualTo("AWSLambda");
+ assertThat(platform.signingConfiguration().hashAlgorithmOptions().allowedValuesAsStrings())
+ .contains("SHA-384");
+ assertThat(platform.signingImageFormat().defaultFormatAsString()).isEqualTo("JSON");
+ assertThat(platform.maxSizeInMB()).isEqualTo(50);
+ }
+
+ @Test
+ @DisplayName("The profile ARN carries tags for the shared tagging actions")
+ void tagsThroughTheResourceArn() {
+ String arn = signer.putSigningProfile(r -> r
+ .profileName(PROFILE)
+ .platformId(PLATFORM_LAMBDA))
+ .arn();
+
+ signer.tagResource(r -> r.resourceArn(arn).tags(Map.of("team", "platform")));
+
+ assertThat(signer.listTagsForResource(r -> r.resourceArn(arn)).tags())
+ .containsEntry("team", "platform");
+
+ signer.untagResource(r -> r.resourceArn(arn).tagKeys("team"));
+
+ assertThat(signer.listTagsForResource(r -> r.resourceArn(arn)).tags())
+ .doesNotContainKey("team");
+ }
+
+ @Test
+ @DisplayName("A missing profile answers ResourceNotFoundException")
+ void missingProfile() {
+ assertThatThrownBy(() -> signer.getSigningProfile(r -> r.profileName("SdkTestMissing")))
+ .isInstanceOf(ResourceNotFoundException.class);
+ }
+}
diff --git a/docs/services/index.md b/docs/services/index.md
index d630c4be8d..6f2d977d12 100644
--- a/docs/services/index.md
+++ b/docs/services/index.md
@@ -117,6 +117,7 @@ Operation counts are exact. For dispatch-table services (Query and JSON 1.1) eac
| [AWS Batch](batch.md) | `/v1/...` | REST JSON | 10 |
| [CodeDeploy](codedeploy.md) | `POST /` + `X-Amz-Target: CodeDeploy_20141006.*` | JSON 1.1 | 35 |
| [CodePipeline](codepipeline.md) | `POST /` + `X-Amz-Target: CodePipeline_20150709.*` | JSON 1.1 | 44 |
+| [AWS Signer](signer.md) | `/signing-profiles`, `/signing-jobs`, `/signing-platforms`, `/revocations` | REST JSON | 18 |
| [AWS Network Firewall](network-firewall.md) | `POST /` + `X-Amz-Target: NetworkFirewall_20201112.*` | JSON 1.0 | 27 |
| [AWS Service Catalog](service-catalog.md) | `POST /` + `X-Amz-Target: AWS242ServiceCatalogService.*` | JSON 1.1 | 89 |
| [Service Quotas](servicequotas.md) | `POST /` + `X-Amz-Target: ServiceQuotasV20190624.*` | JSON 1.1 | 8 |
diff --git a/docs/services/signer.md b/docs/services/signer.md
new file mode 100644
index 0000000000..723bcedd28
--- /dev/null
+++ b/docs/services/signer.md
@@ -0,0 +1,142 @@
+# AWS Signer
+
+**Protocol:** REST JSON
+**Endpoint:** `http://localhost:4566/signing-profiles` (SigV4 service `signer`)
+
+Floci emulates the AWS Signer control plane: signing profiles, the permissions granted on them, the
+platforms AWS publishes, and the signing jobs started against a profile. Profiles, permissions, and
+jobs are persisted and isolated by account and region, and the `/tags/{resourceArn}` actions are
+served by the shared tag routes.
+
+## Supported Actions
+
+
+| Action | Description |
+| --- | --- |
+| `PutSigningProfile` | Creates a signing profile, or mints a new version of an existing one. |
+| `GetSigningProfile` | Returns one signing profile, its platform, overrides, tags and revocation record. |
+| `ListSigningProfiles` | Lists signing profiles with the platform and status filters and paged results. |
+| `CancelSigningProfile` | Deletes a signing profile. |
+| `RevokeSigningProfile` | Revokes a profile version, recording the reason and the effective time. |
+| `AddProfilePermission` | Grants a cross-account permission on a profile and moves its revision. |
+| `ListProfilePermissions` | Lists the permissions granted on a profile. |
+| `RemoveProfilePermission` | Removes a permission, requiring the profile's current revision id. |
+| `StartSigningJob` | Records a signing job against a profile and completes it. |
+| `ListSigningJobs` | Lists signing jobs with the status, platform and revocation filters. |
+| `DescribeSigningJob` | Returns one signing job with its S3 source, destination and revocation record. |
+| `RevokeSignature` | Marks a signing job's signature revoked, recording the reason. |
+| `GetRevocationStatus` | Reports the revocation status of the signatures named in the request. |
+| `ListSigningPlatforms` | Lists the signing platforms Floci serves, with their algorithms and image formats. |
+| `GetSigningPlatform` | Returns one signing platform. |
+| `ListTagsForResource` | Lists the tags attached to a signing profile. |
+| `TagResource` | Adds or replaces tags on a signing profile. |
+| `UntagResource` | Removes selected tags from a signing profile. |
+
+
+`PutSigningProfile` behaves as an upsert: the first call creates the profile and every later call
+mints a new ten-character `profileVersion`, leaving the previous version superseded, which is what
+AWS does with one exception. AWS returns the members the request omits to their defaults on the new
+version; Floci keeps the values the profile already had, so a client that re-puts a profile with only
+a `platformId` does not lose its certificate, overrides or validity period. Tags live on the profile
+rather than on a version, and a put that sends no `tags` member leaves them untouched.
+
+The signing platforms are `AWSLambda-SHA384-ECDSA`, `Notation-OCI-SHA384-ECDSA` and
+`AWSIoTDeviceManagement-SHA256-ECDSA`. A profile naming any other `platformId` is refused with
+`ValidationException`, and so is an override or signing parameter the platform does not accept: a
+`SHA-256` hash on the Lambda platform, for instance.
+
+`GetRevocationStatus` always answers with an empty `revokedEntities` list. It reports on signatures
+whose bytes a caller already holds, and Floci produces none (see below), so there is nothing that
+could have been revoked.
+
+Both list operations paginate with the model's `maxResults` (1 to 25) and an opaque `nextToken`
+that names the last item returned, so a page stays resumable when profiles or jobs are added
+between requests.
+
+A job carries its `clientRequestToken`, and a second `StartSigningJob` with the same token answers
+the job the first one created instead of starting another, so a client that retries after a timeout
+does not duplicate work.
+
+A profile that sets no `signatureValidityPeriod` gets the period Signer applies by default, 135
+months, on the platforms whose signatures expire; a job started from it therefore reports a
+`signatureExpiresAt`. The AWS IoT platform expires nothing and supports no revocation, so a job on
+it reports no expiry and `RevokeSignature` refuses it.
+
+Every timestamp this service emits is epoch seconds, as a JSON number, because that is the form the
+Signer model unmarshals. The AWS CLI coerces an ISO 8601 string and hides the difference, while the
+Java and Go SDKs reject the whole response, so the compatibility suite asserts the numeric form.
+
+## Not emulated
+
+Floci records a signing job but does not sign, and it says so instead of reporting a success
+nothing backs. `StartSigningJob` validates the profile and its S3 source and destination and
+completes the job as `Failed`, with a `statusReason` naming the object that was not written, so no
+caller downloads a key that is not there; `RevokeSignature` refuses a job that has no signature to
+revoke. `FLOCI_SERVICES_SIGNER_MOCK_SIGNING_JOBS=true` records jobs as `Succeeded` and echoes the
+destination as `signedObject`, for tools that only read job metadata; that mode is a mock, and the
+artifact still does not exist.
+
+`SignPayload` is not served: it answers an AWS-shaped error rather than a signature, because a
+payload signature is the one thing the metadata model cannot approximate. A profile permission can
+still name `signer:SignPayload`, which AWS lists with the other profile actions: the grant is policy
+metadata and is accepted, only the operation itself is not served.
+
+Cancelling a profile keeps it, as AWS does: it stays readable through `GetSigningProfile` with the
+same ARN and version and the status `Canceled`, it stops accepting jobs, and `ListSigningProfiles`
+hides it unless `includeCanceled=true` or `statuses` names `Canceled`. A `PutSigningProfile` on the
+same name brings it back as a new `Active` version.
+
+IAM treats Signer as any other service: `signer` and `signer-data` are in the vendored
+request-resource table, so an action is checked against the profile or job ARN the call names
+rather than against `*`. A profile a CloudFormation stack provisions through
+`AWS::Signer::SigningProfile` is the same record this service serves: the stack's `Ref` is the
+profile ARN, `Fn::GetAtt` answers `Arn`, `ProfileName`, `ProfileVersion` and `ProfileVersionArn`,
+the template's `Tags` land on the profile, and deleting the stack cancels it.
+
+## Configuration
+
+| Variable | Default | Description |
+|---|---|---|
+| `FLOCI_SERVICES_SIGNER_ENABLED` | `true` | Enable or disable the service |
+| `FLOCI_SERVICES_SIGNER_MOCK_SIGNING_JOBS` | `false` | Record jobs as `Succeeded` without an artifact, for tools that only read job metadata |
+
+## Examples
+
+```bash
+export AWS_ENDPOINT_URL=http://localhost:4566
+
+aws signer put-signing-profile \
+ --profile-name my-profile \
+ --platform-id AWSLambda-SHA384-ECDSA \
+ --signature-validity-period type=DAYS,value=135 \
+ --tags env=local
+
+job_id=$(aws signer start-signing-job \
+ --profile-name my-profile \
+ --source s3={bucketName=artifacts,key=app.zip,version=1} \
+ --destination s3={bucketName=signed,prefix=out/} \
+ --client-request-token local-1 \
+ --query jobId --output text)
+
+aws signer describe-signing-job --job-id "$job_id" # Failed: no artifact is written
+
+aws signer cancel-signing-profile --profile-name my-profile
+aws signer get-signing-profile --profile-name my-profile # Canceled, same ARN
+aws signer list-signing-profiles --include-canceled --query 'profiles[].profileName'
+```
+
+Through CloudFormation, the profile the stack reports is the profile this service serves:
+
+```json
+{
+ "Resources": {
+ "Profile": {
+ "Type": "AWS::Signer::SigningProfile",
+ "Properties": {"PlatformId": "AWSLambda-SHA384-ECDSA"}
+ }
+ },
+ "Outputs": {
+ "Arn": {"Value": {"Fn::GetAtt": ["Profile", "Arn"]}}
+ }
+}
+```
diff --git a/mkdocs.yml b/mkdocs.yml
index 25164c54ff..9ccddff870 100644
--- a/mkdocs.yml
+++ b/mkdocs.yml
@@ -172,6 +172,7 @@ nav:
- AppIntegrations: services/appintegrations.md
- Amazon Data Lifecycle Manager: services/dlm.md
- ACM: services/acm.md
+ - AWS Signer: services/signer.md
- Payment Cryptography: services/payment-cryptography.md
- Payment Cryptography data plane: services/payment-cryptography-data.md
- ECS: services/ecs.md
diff --git a/src/main/java/io/floci/aws/config/EmulatorConfig.java b/src/main/java/io/floci/aws/config/EmulatorConfig.java
index 5cd9a1baa1..5104cdbce7 100644
--- a/src/main/java/io/floci/aws/config/EmulatorConfig.java
+++ b/src/main/java/io/floci/aws/config/EmulatorConfig.java
@@ -874,6 +874,7 @@ public interface EmulatorConfig {
ConnectServiceConfig connect();
AppIntegrationsServiceConfig appintegrations();
DlmServiceConfig dlm();
+ SignerServiceConfig signer();
CognitoIdentityServiceConfig cognitoidentity();
GlobalAcceleratorServiceConfig globalaccelerator();
DataSyncServiceConfig datasync();
@@ -951,6 +952,19 @@ public interface EmulatorConfig {
boolean enabled();
}
+ interface SignerServiceConfig {
+ @WithDefault("true")
+ boolean enabled();
+
+ /**
+ * Records signing jobs as succeeded without producing an artifact, for callers that only
+ * read job metadata. Off by default: a job that reports success must have something to
+ * download, and Floci does not sign code.
+ */
+ @WithDefault("false")
+ boolean mockSigningJobs();
+ }
+
interface CognitoIdentityServiceConfig {
@WithDefault("true")
boolean enabled();
diff --git a/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java b/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
index 89aade34ba..a54b1f00d5 100644
--- a/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
+++ b/src/main/java/io/floci/aws/core/common/ResolvedServiceCatalog.java
@@ -101,6 +101,7 @@ import io.floci.aws.services.ses.SesSuppressionController;
import io.floci.aws.services.ses.SesTagController;
import io.floci.aws.services.ses.SesTemplateController;
import io.floci.aws.services.ses.SesTenantController;
+import io.floci.aws.services.signer.SignerController;
import io.floci.aws.services.signin.SigninController;
import io.floci.aws.services.ssooidc.SsoOidcController;
import io.floci.aws.services.ssoportal.SsoPortalController;
@@ -777,6 +778,10 @@ public class ResolvedServiceCatalog {
"dlm", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
protocols(ServiceProtocol.REST_JSON),
Set.of(), Set.of("dlm"), Set.of(), Set.of(DlmController.class)),
+ descriptor("signer", "signer", config.services().signer().enabled(), true,
+ "signer", config.storage().mode(), 5000L, null, ServiceProtocol.REST_JSON,
+ protocols(ServiceProtocol.REST_JSON),
+ Set.of(), Set.of("signer"), Set.of(), Set.of(SignerController.class)),
descriptor("cognito-identity", "cognitoidentity",
config.services().cognitoidentity().enabled(), true,
"cognitoidentity", config.storage().mode(), 5000L, null, ServiceProtocol.JSON,
diff --git a/src/main/java/io/floci/aws/services/cloudformation/provisioners/SignerCfnProvisioner.java b/src/main/java/io/floci/aws/services/cloudformation/provisioners/SignerCfnProvisioner.java
index 1311332555..7afd643419 100644
--- a/src/main/java/io/floci/aws/services/cloudformation/provisioners/SignerCfnProvisioner.java
+++ b/src/main/java/io/floci/aws/services/cloudformation/provisioners/SignerCfnProvisioner.java
@@ -1,26 +1,37 @@
package io.floci.aws.services.cloudformation.provisioners;
+import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
-import io.floci.aws.core.common.AwsArnUtils;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
import io.floci.aws.core.common.AwsException;
import io.floci.aws.services.cloudformation.model.StackResource;
+import io.floci.aws.services.signer.SignerPlatforms;
+import io.floci.aws.services.signer.SignerService;
+import io.floci.aws.services.signer.model.SigningProfile;
import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.regex.Pattern;
/**
- * Provisions {@code AWS::Signer::SigningProfile}. Floci has no Signer API, so a profile is only the
- * identifiers CloudFormation hands the template: {@code Ref} is the profile ARN, and the attributes
- * carry the name, a version and the version ARN a code signing config lists. Every property but
- * {@code Tags} is create-only: an update that keeps them keeps the profile, one that changes them
- * mints a new one, and one that would keep an explicit name is refused, as CloudFormation refuses
- * replacing any custom-named resource. A replaced or deleted profile leaves nothing behind to clean
- * up, and a rolled-back replacement points the resource back to the prior profile.
+ * Provisions {@code AWS::Signer::SigningProfile} through {@link SignerService}, so a profile a stack
+ * creates is the profile the Signer API serves: {@code aws signer get-signing-profile} returns the
+ * same ARN the stack hands out as {@code Ref}, with its platform, validity period and tags.
+ *
+ * {@code Ref} is the profile ARN and the attributes carry the name, a version and the version ARN
+ * a code signing config lists. Every property but {@code Tags} is create-only: an update that keeps
+ * them keeps the profile and re-applies its tags, one that changes them mints a new profile, and one
+ * that would keep an explicit name is refused, as CloudFormation refuses replacing any custom-named
+ * resource. A replaced profile is cancelled once the update commits; a rolled-back replacement puts
+ * the resource back and cancels the profile that update created.
*/
@ApplicationScoped
public class SignerCfnProvisioner implements CfnResourceProvisioner {
@@ -30,8 +41,23 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
private static final Pattern PROFILE_NAME = Pattern.compile("[0-9a-zA-Z_]{2,64}");
private static final Map MAX_VALIDITY = Map.of("DAYS", 4105, "MONTHS", 135, "YEARS", 11);
private static final String ALPHANUMERIC = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+ private static final String PROFILE_RESOURCE = "/signing-profiles/";
/** The create-only properties the profile was minted from, so an update can tell whether it is replaced. */
private static final String CREATE_ONLY_ATTR = "FlociSigningProfileCreateOnly";
+ /**
+ * The tags an in-place update is about to replace, with the region they live in, so a rollback
+ * can put them back. Present only while a tag change is pending: a provision that would write
+ * the set already stored removes it.
+ */
+ private static final String PRIOR_TAGS_ATTR = "FlociSigningProfilePriorTags";
+ private static final ObjectMapper MAPPER = new ObjectMapper();
+
+ private final SignerService signerService;
+
+ @Inject
+ public SignerCfnProvisioner(SignerService signerService) {
+ this.signerService = signerService;
+ }
@Override
public Set resourceTypes() {
@@ -52,7 +78,7 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
TYPE + " ProfileName must be 2 to 64 characters from [0-9a-zA-Z_], got " + explicitName, 400);
}
JsonNode period = ctx.engine().resolveNodeOmittingNoValue(props.path("SignatureValidityPeriod"));
- validatePeriod(period, ctx);
+ Integer validityValue = validatePeriod(period, ctx);
String createOnly = platformId + "|" + Objects.toString(explicitName, "") + "|"
+ period.path("Type").asText() + "|" + period.path("Value").asText();
if (!createOnly.equals(r.getAttributes().get(CREATE_ONLY_ATTR))) {
@@ -61,7 +87,9 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
"CloudFormation cannot update a stack when a custom-named resource requires "
+ "replacing. Rename " + explicitName + " and update the stack again.", 400);
}
- mint(r, ctx, explicitName, createOnly);
+ mint(r, ctx, platformId, explicitName, period, validityValue, createOnly, tags(ctx, props));
+ } else {
+ replaceTags(r, ctx, tags(ctx, props));
}
ReplacementCleanup.record(r, ctx, attributesBefore);
}
@@ -70,9 +98,9 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
* Signer's checks on a supplied validity period, in its order and with its messages: a known unit,
* then a value above zero and at most the unit's cap. An omitted period keeps Signer's default.
*/
- private static void validatePeriod(JsonNode period, ProvisionContext ctx) {
+ private static Integer validatePeriod(JsonNode period, ProvisionContext ctx) {
if (period.isMissingNode()) {
- return;
+ return null;
}
String type = period.path("Type").asText(null);
if (type == null || !MAX_VALIDITY.containsKey(type)) {
@@ -87,22 +115,159 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
throw new AwsException("ValidationError", "Signature validity period value for " + type
+ " must be less than or equal to " + MAX_VALIDITY.get(type), 400);
}
+ return value;
}
- private static void mint(StackResource r, ProvisionContext ctx, String explicitName, String createOnly) {
+ private void mint(StackResource r, ProvisionContext ctx, String platformId, String explicitName,
+ JsonNode period, Integer validityValue, String createOnly, Map tags) {
String name = explicitName != null ? explicitName
: r.getLogicalId().substring(0, Math.min(r.getLogicalId().length(), 51)) + "_" + random(12);
- String arn = AwsArnUtils.Arn.of("signer", ctx.region(), ctx.accountId(), "/signing-profiles/" + name)
- .toString();
- String version = random(10);
- r.setPhysicalId(arn);
- r.getAttributes().put("Arn", arn);
- r.getAttributes().put("ProfileName", name);
- r.getAttributes().put("ProfileVersion", version);
- r.getAttributes().put("ProfileVersionArn", arn + "/" + version);
+ if (explicitName != null && signerService.findSigningProfile(explicitName, ctx.region()).isPresent()) {
+ throw new AwsException("ValidationError", TYPE + " " + explicitName
+ + " already exists in " + ctx.region()
+ + "; a stack cannot take over a signing profile it did not create.", 400);
+ }
+ SigningProfile profile = signerService.putSigningProfile(
+ name,
+ platformId,
+ period.isMissingNode() ? null : period.path("Type").asText(null),
+ validityValue,
+ tags,
+ ctx.region());
+ r.setPhysicalId(profile.getArn());
+ r.getAttributes().put("Arn", profile.getArn());
+ r.getAttributes().put("ProfileName", profile.getProfileName());
+ r.getAttributes().put("ProfileVersion", profile.getProfileVersion());
+ r.getAttributes().put("ProfileVersionArn", profile.getProfileVersionArn());
r.getAttributes().put(CREATE_ONLY_ATTR, createOnly);
}
+ /**
+ * A tags-only update. CloudFormation sets the resource's tags to exactly what the template
+ * declares, so this replaces the set rather than merging into it, and it does not mint a profile
+ * version: on AWS, tagging a signing profile is not a change to the profile.
+ */
+ private void replaceTags(StackResource r, ProvisionContext ctx, Map tags) {
+ String name = r.getAttributes().get("ProfileName");
+ if (name == null) {
+ return;
+ }
+ Optional stored = signerService.findSigningProfile(name, ctx.region());
+ if (stored.isEmpty()) {
+ adopt(r, ctx, name);
+ signerService.replaceTags(name, tags, ctx.region());
+ return;
+ }
+ if (stored.get().getTags().equals(tags)) {
+ r.getAttributes().remove(PRIOR_TAGS_ATTR);
+ return;
+ }
+ snapshotTags(r, ctx, stored.get().getTags());
+ signerService.replaceTags(name, tags, ctx.region());
+ }
+
+ /**
+ * Writes the service record for a resource this stack provisioned before the service existed,
+ * keeping the identifiers the stack already handed out. The create-only property string the
+ * provisioner recorded carries the platform and the validity period, which is all a later tag
+ * update needs.
+ */
+ private void adopt(StackResource r, ProvisionContext ctx, String name) {
+ String createOnly = r.getAttributes().get(CREATE_ONLY_ATTR);
+ String[] parts = createOnly == null ? new String[0] : createOnly.split("\\|", -1);
+ String platformId = parts.length > 0 ? parts[0] : null;
+ if (platformId == null || SignerPlatforms.find(platformId).isEmpty()) {
+ return;
+ }
+ String validityType = parts.length > 2 && !parts[2].isEmpty() ? parts[2] : null;
+ Integer validityValue = null;
+ if (validityType != null && parts.length > 3) {
+ try {
+ validityValue = Integer.valueOf(parts[3]);
+ } catch (NumberFormatException ignored) {
+ validityValue = null;
+ }
+ }
+ signerService.adoptSigningProfile(name, platformId, r.getAttributes().get("ProfileVersion"),
+ validityType, validityValue, ctx.region());
+ }
+
+ private static void snapshotTags(StackResource r, ProvisionContext ctx, Map tags) {
+ ObjectNode snapshot = MAPPER.createObjectNode();
+ snapshot.put("region", ctx.region());
+ ObjectNode stored = snapshot.putObject("tags");
+ tags.forEach(stored::put);
+ try {
+ r.getAttributes().put(PRIOR_TAGS_ATTR, MAPPER.writeValueAsString(snapshot));
+ } catch (JsonProcessingException e) {
+ throw new AwsException("ValidationError", "Could not record the profile's prior tags: "
+ + e.getMessage(), 400);
+ }
+ }
+
+ private void restorePriorTags(StackResource r, String snapshotJson) {
+ try {
+ JsonNode snapshot = MAPPER.readTree(snapshotJson);
+ String region = snapshot.path("region").asText(null);
+ String name = r.getAttributes().get("ProfileName");
+ if (region == null || name == null) {
+ return;
+ }
+ Map tags = new LinkedHashMap<>();
+ snapshot.path("tags").fields().forEachRemaining(entry -> tags.put(entry.getKey(), entry.getValue().asText()));
+ signerService.replaceTags(name, tags, region);
+ } catch (JsonProcessingException e) {
+ throw new AwsException("ValidationError", "Could not restore the profile's prior tags: "
+ + e.getMessage(), 400);
+ }
+ }
+
+ /**
+ * The template's {@code Tags}, with every key and value resolved: a {@code Ref}, an
+ * {@code Fn::Sub} or a {@code Fn::If} inside a tag is a reference to something the engine owns,
+ * and reading the raw node would store the intrinsic document as the tag.
+ */
+ private static Map tags(ProvisionContext ctx, JsonNode props) {
+ JsonNode tags = ctx.engine().resolveNodeOmittingNoValue(props.path("Tags"));
+ if (tags.isMissingNode() || tags.isNull() || !tags.isArray()) {
+ return new LinkedHashMap<>();
+ }
+ Map resolved = new LinkedHashMap<>();
+ for (JsonNode tag : tags) {
+ String key = ctx.engine().resolveNodeOmittingNoValue(tag.path("Key")).asText(null);
+ if (key == null || key.isEmpty()) {
+ continue;
+ }
+ resolved.put(key, ctx.engine().resolveNodeOmittingNoValue(tag.path("Value")).asText(""));
+ }
+ return resolved;
+ }
+
+ @Override
+ public void delete(String resourceType, String physicalId, String region) {
+ String name = profileNameOf(physicalId);
+ if (name == null) {
+ return;
+ }
+ CfnDeletes.safeDelete("Signing profile", physicalId,
+ () -> signerService.cancelSigningProfile(name, region),
+ "ResourceNotFoundException");
+ }
+
+ /** The profile name the ARN names, so a delete driven by a physical id alone can cancel it. */
+ private static String profileNameOf(String physicalId) {
+ if (physicalId == null) {
+ return null;
+ }
+ int at = physicalId.indexOf(PROFILE_RESOURCE);
+ if (at < 0) {
+ return null;
+ }
+ String remainder = physicalId.substring(at + PROFILE_RESOURCE.length());
+ int slash = remainder.indexOf('/');
+ return slash < 0 ? remainder : remainder.substring(0, slash);
+ }
+
@Override
public boolean hasReplacementUpdate(StackResource resource) {
return ReplacementCleanup.hasReplacement(resource);
@@ -115,6 +280,7 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
@Override
public UpdateCleanupResult completeUpdate(StackResource resource) {
+ resource.getAttributes().remove(PRIOR_TAGS_ATTR);
return ReplacementCleanup.complete(resource, this::delete);
}
@@ -123,9 +289,15 @@ public class SignerCfnProvisioner implements CfnResourceProvisioner {
ReplacementCleanup.clear(resource);
}
- /** A replacement points back to the prior profile; a tags-only update changed nothing Floci holds. */
+ /** A replacement points back to the prior profile and cancels the one this update created. */
@Override
public boolean rollbackUpdate(StackResource resource) {
+ String pendingTags = resource.getAttributes().get(PRIOR_TAGS_ATTR);
+ if (!ReplacementCleanup.hasReplacement(resource) && pendingTags != null) {
+ restorePriorTags(resource, pendingTags);
+ resource.getAttributes().remove(PRIOR_TAGS_ATTR);
+ return true;
+ }
ReplacementCleanup.rollback(resource, this::delete);
return true;
}
diff --git a/src/main/java/io/floci/aws/services/signer/SignerController.java b/src/main/java/io/floci/aws/services/signer/SignerController.java
new file mode 100644
index 0000000000..1b0ccea84b
--- /dev/null
+++ b/src/main/java/io/floci/aws/services/signer/SignerController.java
@@ -0,0 +1,364 @@
+package io.floci.aws.services.signer;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import io.floci.aws.core.common.JsonErrorResponseUtils;
+import io.floci.aws.core.common.RegionResolver;
+import io.floci.aws.services.signer.model.SigningJob;
+import io.floci.aws.services.signer.model.SigningProfile;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.DELETE;
+import jakarta.ws.rs.GET;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.PUT;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.Context;
+import jakarta.ws.rs.core.HttpHeaders;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+
+import java.util.List;
+
+/**
+ * The REST JSON routes AWS Signer publishes, mounted under {@link SignerRouteFilter#INTERNAL_PREFIX}.
+ *
+ * Signer's public paths are literal ({@code /signing-profiles}, {@code /signing-jobs},
+ * {@code /signing-platforms}, {@code /revocations}) and S3's path-style routes would otherwise claim
+ * them as buckets, so {@link SignerRouteFilter} rewrites a request signed for {@code signer} onto the
+ * internal prefix before route matching. The shared {@code /tags/{resourceArn}} routes are served by
+ * {@code SharedTagsController} through {@link SignerService} as a {@code TagHandler}.
+ */
+@Path(SignerRouteFilter.INTERNAL_PREFIX)
+@Produces(MediaType.APPLICATION_JSON)
+@Consumes(MediaType.APPLICATION_JSON)
+public class SignerController {
+
+ private final SignerService signerService;
+ private final RegionResolver regionResolver;
+ private final ObjectMapper objectMapper;
+
+ @Inject
+ public SignerController(SignerService signerService, RegionResolver regionResolver,
+ ObjectMapper objectMapper) {
+ this.signerService = signerService;
+ this.regionResolver = regionResolver;
+ this.objectMapper = objectMapper;
+ }
+
+ @PUT
+ @Path("/signing-profiles/{profileName}")
+ public Response putSigningProfile(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ SigningProfile profile = signerService.putSigningProfile(profileName, readTree(body), region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("arn", profile.getArn());
+ response.put("profileVersion", profile.getProfileVersion());
+ response.put("profileVersionArn", profile.getProfileVersionArn());
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-profiles/{profileName}")
+ public Response getSigningProfile(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ return Response.ok(profileNode(signerService.getSigningProfile(profileName, region), true))
+ .build();
+ }
+
+ @GET
+ @Path("/signing-profiles")
+ public Response listSigningProfiles(@Context HttpHeaders headers,
+ @QueryParam("platformId") String platformId,
+ @QueryParam("statuses") List statuses,
+ @QueryParam("includeCanceled") Boolean includeCanceled,
+ @QueryParam("maxResults") Integer maxResults,
+ @QueryParam("nextToken") String nextToken) {
+ String region = regionResolver.resolveRegion(headers);
+ SignerService.Page page = signerService.listSigningProfiles(
+ region, platformId, statuses, includeCanceled, maxResults, nextToken);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode profiles = response.putArray("profiles");
+ for (SigningProfile profile : page.items()) {
+ profiles.add(profileNode(profile, false));
+ }
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
+ return Response.ok(response).build();
+ }
+
+ @DELETE
+ @Path("/signing-profiles/{profileName}")
+ public Response cancelSigningProfile(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ signerService.cancelSigningProfile(profileName, region);
+ return Response.ok().build();
+ }
+
+ @PUT
+ @Path("/signing-profiles/{profileName}/revoke")
+ public Response revokeSigningProfile(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ signerService.revokeSigningProfile(profileName, readTree(body), region);
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("/signing-profiles/{profileName}/permissions")
+ public Response addProfilePermission(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ String revisionId = signerService.addProfilePermission(profileName, readTree(body), region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("revisionId", revisionId);
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-profiles/{profileName}/permissions")
+ public Response listProfilePermissions(@PathParam("profileName") String profileName,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ List permissions =
+ signerService.listProfilePermissions(profileName, region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("revisionId", signerService.getSigningProfile(profileName, region)
+ .getRevisionId());
+ response.put("policySizeBytes", permissions.size() * 128);
+ ArrayNode entries = response.putArray("permissions");
+ for (SigningProfile.ProfilePermission permission : permissions) {
+ ObjectNode entry = entries.addObject();
+ entry.put("action", permission.getAction());
+ entry.put("principal", permission.getPrincipal());
+ entry.put("statementId", permission.getStatementId());
+ entry.put("profileVersion", permission.getProfileVersion());
+ }
+ return Response.ok(response).build();
+ }
+
+ @DELETE
+ @Path("/signing-profiles/{profileName}/permissions/{statementId}")
+ public Response removeProfilePermission(@PathParam("profileName") String profileName,
+ @PathParam("statementId") String statementId,
+ @QueryParam("revisionId") String revisionId,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ String newRevisionId = signerService.removeProfilePermission(
+ profileName, statementId, revisionId, region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("revisionId", newRevisionId);
+ return Response.ok(response).build();
+ }
+
+ @POST
+ @Path("/signing-jobs")
+ public Response startSigningJob(@Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ SigningJob job = signerService.startSigningJob(readTree(body), region);
+ ObjectNode response = objectMapper.createObjectNode();
+ response.put("jobId", job.getJobId());
+ response.put("jobOwner", job.getJobOwner());
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-jobs")
+ public Response listSigningJobs(@Context HttpHeaders headers,
+ @QueryParam("status") String status,
+ @QueryParam("platformId") String platformId,
+ @QueryParam("isRevoked") Boolean isRevoked,
+ @QueryParam("maxResults") Integer maxResults,
+ @QueryParam("nextToken") String nextToken) {
+ String region = regionResolver.resolveRegion(headers);
+ SignerService.Page page = signerService.listSigningJobs(
+ region, status, platformId, isRevoked, maxResults, nextToken);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode jobs = response.putArray("jobs");
+ for (SigningJob job : page.items()) {
+ jobs.add(jobNode(job, false));
+ }
+ if (page.nextToken() != null) {
+ response.put("nextToken", page.nextToken());
+ }
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-jobs/{jobId}")
+ public Response describeSigningJob(@PathParam("jobId") String jobId,
+ @Context HttpHeaders headers) {
+ String region = regionResolver.resolveRegion(headers);
+ return Response.ok(jobNode(signerService.describeSigningJob(jobId, region), true)).build();
+ }
+
+ @PUT
+ @Path("/signing-jobs/{jobId}/revoke")
+ public Response revokeSignature(@PathParam("jobId") String jobId,
+ @Context HttpHeaders headers, String body) {
+ String region = regionResolver.resolveRegion(headers);
+ signerService.revokeSignature(jobId, readTree(body), region);
+ return Response.ok().build();
+ }
+
+ @GET
+ @Path("/revocations")
+ public Response getRevocationStatus(@Context HttpHeaders headers) {
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode revokedEntities = response.putArray("revokedEntities");
+ for (String entity : signerService.getRevocationStatus()) {
+ revokedEntities.add(entity);
+ }
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-platforms")
+ public Response listSigningPlatforms(@Context HttpHeaders headers,
+ @QueryParam("category") String category,
+ @QueryParam("partner") String partner,
+ @QueryParam("target") String target) {
+ List platforms = signerService.listSigningPlatforms(category);
+ ObjectNode response = objectMapper.createObjectNode();
+ ArrayNode entries = response.putArray("platforms");
+ for (SignerPlatforms.Platform platform : platforms) {
+ if (partner != null && !partner.equals(platform.partner())) {
+ continue;
+ }
+ if (target != null && !target.equals(platform.target())) {
+ continue;
+ }
+ entries.add(platformNode(platform));
+ }
+ return Response.ok(response).build();
+ }
+
+ @GET
+ @Path("/signing-platforms/{platformId}")
+ public Response getSigningPlatform(@PathParam("platformId") String platformId,
+ @Context HttpHeaders headers) {
+ return Response.ok(platformNode(signerService.getSigningPlatform(platformId))).build();
+ }
+
+ private ObjectNode profileNode(SigningProfile profile, boolean detail) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("profileName", profile.getProfileName());
+ node.put("profileVersion", profile.getProfileVersion());
+ node.put("profileVersionArn", profile.getProfileVersionArn());
+ node.put("arn", profile.getArn());
+ node.put("platformId", profile.getPlatformId());
+ node.put("platformDisplayName", profile.getPlatformDisplayName());
+ node.put("status", profile.getStatus());
+ if (profile.getSigningMaterialCertificateArn() != null) {
+ node.putObject("signingMaterial")
+ .put("certificateArn", profile.getSigningMaterialCertificateArn());
+ }
+ if (profile.getSignatureValidityPeriodType() != null) {
+ ObjectNode period = node.putObject("signatureValidityPeriod");
+ period.put("type", profile.getSignatureValidityPeriodType());
+ period.put("value", profile.getSignatureValidityPeriodValue());
+ }
+ if (profile.getOverrides() != null) {
+ node.set("overrides", profile.getOverrides());
+ }
+ node.set("signingParameters", objectMapper.valueToTree(profile.getSigningParameters()));
+ node.set("tags", objectMapper.valueToTree(profile.getTags()));
+ if (detail) {
+ if (profile.getStatusReason() != null) {
+ node.put("statusReason", profile.getStatusReason());
+ }
+ if (profile.getRevokedAt() != null) {
+ ObjectNode record = node.putObject("revocationRecord");
+ record.put("revocationEffectiveFrom", profile.getRevocationEffectiveFrom());
+ record.put("revokedAt", profile.getRevokedAt());
+ record.put("revokedBy", profile.getRevokedBy());
+ }
+ }
+ return node;
+ }
+
+ private ObjectNode jobNode(SigningJob job, boolean detail) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("jobId", job.getJobId());
+ node.put("jobArn", job.getJobArn());
+ ObjectNode sourceS3 = node.putObject("source").putObject("s3");
+ sourceS3.put("bucketName", job.getSourceBucketName());
+ sourceS3.put("key", job.getSourceKey());
+ sourceS3.put("version", job.getSourceVersion());
+ if (job.getSignedObjectBucketName() != null) {
+ ObjectNode signed = node.putObject("signedObject").putObject("s3");
+ signed.put("bucketName", job.getSignedObjectBucketName());
+ signed.put("key", job.getSignedObjectKey());
+ }
+ node.put("profileName", job.getProfileName());
+ node.put("profileVersion", job.getProfileVersion());
+ node.put("platformId", job.getPlatformId());
+ node.put("platformDisplayName", job.getPlatformDisplayName());
+ node.put("status", job.getStatus());
+ node.put("isRevoked", job.isRevoked());
+ node.put("createdAt", job.getCreatedAt());
+ node.put("jobOwner", job.getJobOwner());
+ node.put("jobInvoker", job.getJobInvoker());
+ if (job.getSignatureExpiresAt() != null) {
+ node.put("signatureExpiresAt", job.getSignatureExpiresAt());
+ }
+ if (detail) {
+ if (job.getCompletedAt() != null) {
+ node.put("completedAt", job.getCompletedAt());
+ }
+ if (job.getStatusReason() != null) {
+ node.put("statusReason", job.getStatusReason());
+ }
+ if (job.getRequestedBy() != null) {
+ node.put("requestedBy", job.getRequestedBy());
+ }
+ if (job.isRevoked()) {
+ ObjectNode record = node.putObject("revocationRecord");
+ record.put("reason", job.getRevocationReason());
+ record.put("revokedAt", job.getRevokedAt());
+ record.put("revokedBy", job.getRevokedBy());
+ }
+ }
+ return node;
+ }
+
+ private ObjectNode platformNode(SignerPlatforms.Platform platform) {
+ ObjectNode node = objectMapper.createObjectNode();
+ node.put("platformId", platform.platformId());
+ node.put("displayName", platform.displayName());
+ node.put("partner", platform.partner());
+ node.put("target", platform.target());
+ node.put("category", platform.category());
+ ObjectNode configuration = node.putObject("signingConfiguration");
+ ObjectNode encryption = configuration.putObject("encryptionAlgorithmOptions");
+ encryption.set("allowedValues", objectMapper.valueToTree(platform.encryptionAlgorithms()));
+ encryption.put("defaultValue", platform.defaultEncryptionAlgorithm());
+ ObjectNode hash = configuration.putObject("hashAlgorithmOptions");
+ hash.set("allowedValues", objectMapper.valueToTree(platform.hashAlgorithms()));
+ hash.put("defaultValue", platform.defaultHashAlgorithm());
+ ObjectNode imageFormat = node.putObject("signingImageFormat");
+ imageFormat.set("supportedFormats", objectMapper.valueToTree(platform.imageFormats()));
+ imageFormat.put("defaultFormat", platform.defaultImageFormat());
+ node.put("maxSizeInMB", platform.maxSizeInMB());
+ node.put("revocationSupported", platform.revocationSupported());
+ return node;
+ }
+
+ private JsonNode readTree(String body) {
+ try {
+ return objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
+ } catch (Exception e) {
+ throw new WebApplicationException(JsonErrorResponseUtils.createSerializationErrorResponse());
+ }
+ }
+}
diff --git a/src/main/java/io/floci/aws/services/signer/SignerPlatforms.java b/src/main/java/io/floci/aws/services/signer/SignerPlatforms.java
new file mode 100644
index 0000000000..b31ae58503
--- /dev/null
+++ b/src/main/java/io/floci/aws/services/signer/SignerPlatforms.java
@@ -0,0 +1,101 @@
+package io.floci.aws.services.signer;
+
+import java.util.List;
+import java.util.Optional;
+
+/**
+ * The signing platforms AWS publishes, with the configuration and image formats each accepts.
+ *
+ * Signer does not discover platforms from AWS: the list is fixed for a given API version and the
+ * AWS SDK never sends it, so a profile names one of these ids and Floci answers the matching
+ * description. The values follow the published platform descriptions; only the three platforms an
+ * emulated workflow can reach are listed.
+ */
+public final class SignerPlatforms {
+
+ /** One published signing platform and the options a profile may override. */
+ public record Platform(
+ String platformId,
+ String displayName,
+ String partner,
+ String target,
+ String category,
+ List hashAlgorithms,
+ String defaultHashAlgorithm,
+ List encryptionAlgorithms,
+ String defaultEncryptionAlgorithm,
+ List imageFormats,
+ String defaultImageFormat,
+ int maxSizeInMB,
+ boolean revocationSupported,
+ /**
+ * The period Signer applies when a profile sets none: 135 months on the platforms that
+ * expire signatures. Zero on a platform whose signatures do not carry a validity.
+ */
+ int defaultValidityMonths) {
+ }
+
+ public static final Platform AWS_LAMBDA = new Platform(
+ "AWSLambda-SHA384-ECDSA",
+ "AWS Lambda",
+ "AWS",
+ "Lambda",
+ "AWSLambda",
+ List.of("SHA-256", "SHA-384"),
+ "SHA-384",
+ List.of("ECDSA"),
+ "ECDSA",
+ List.of("JSON"),
+ "JSON",
+ 50,
+ true,
+ 135);
+
+ public static final Platform NOTATION_OCI = new Platform(
+ "Notation-OCI-SHA384-ECDSA",
+ "Notation OCI",
+ "AWS",
+ "OCI",
+ "Notation-OCI",
+ List.of("SHA-384"),
+ "SHA-384",
+ List.of("ECDSA"),
+ "ECDSA",
+ List.of("JSON"),
+ "JSON",
+ 500,
+ true,
+ 135);
+
+ public static final Platform IOT_SHA256 = new Platform(
+ "AWSIoTDeviceManagement-SHA256-ECDSA",
+ "AWS IoT Device Management SHA256 ECDSA",
+ "AWS",
+ "IoT",
+ "AWSIoT",
+ List.of("SHA-256"),
+ "SHA-256",
+ List.of("ECDSA"),
+ "ECDSA",
+ List.of("JSONEmbedded", "JSONDetached"),
+ "JSONEmbedded",
+ 50,
+ false,
+ 0);
+
+ private static final List ALL = List.of(AWS_LAMBDA, NOTATION_OCI, IOT_SHA256);
+
+ private SignerPlatforms() {
+ }
+
+ public static List all() {
+ return ALL;
+ }
+
+ public static Optional find(String platformId) {
+ if (platformId == null) {
+ return Optional.empty();
+ }
+ return ALL.stream().filter(platform -> platform.platformId().equals(platformId)).findFirst();
+ }
+}
diff --git a/src/main/java/io/floci/aws/services/signer/SignerRouteFilter.java b/src/main/java/io/floci/aws/services/signer/SignerRouteFilter.java
new file mode 100644
index 0000000000..1d8103e8d1
--- /dev/null
+++ b/src/main/java/io/floci/aws/services/signer/SignerRouteFilter.java
@@ -0,0 +1,43 @@
+package io.floci.aws.services.signer;
+
+import io.floci.aws.core.common.ResolvedServiceCatalog;
+import io.floci.aws.core.common.SignedServiceRoute;
+import jakarta.inject.Inject;
+import jakarta.ws.rs.container.ContainerRequestContext;
+import jakarta.ws.rs.container.ContainerRequestFilter;
+import jakarta.ws.rs.container.PreMatching;
+import jakarta.ws.rs.ext.Provider;
+
+import java.util.function.Predicate;
+
+/**
+ * Rewrites Signer requests to an internal prefix before JAX-RS route matching.
+ *
+ * Signer's paths are literal and S3's path-style routes claim any first segment as a bucket, so a
+ * request for {@code /signing-profiles} would otherwise read as bucket {@code signing-profiles}. The
+ * rewrite is keyed on the SigV4 credential scope, so a request signed for S3 keeps its path and
+ * reaches S3: only a request signed for {@code signer} is moved.
+ */
+@Provider
+@PreMatching
+public class SignerRouteFilter implements ContainerRequestFilter {
+
+ static final String INTERNAL_PREFIX = "/_signer";
+
+ private static final Predicate PUBLIC_PATHS = SignedServiceRoute.under("/signing-profiles")
+ .or(SignedServiceRoute.under("/signing-jobs"))
+ .or(SignedServiceRoute.under("/signing-platforms"))
+ .or(SignedServiceRoute.under("/revocations"));
+
+ private final SignedServiceRoute route;
+
+ @Inject
+ public SignerRouteFilter(ResolvedServiceCatalog catalog) {
+ this.route = new SignedServiceRoute(catalog, "signer", INTERNAL_PREFIX, PUBLIC_PATHS);
+ }
+
+ @Override
+ public void filter(ContainerRequestContext ctx) {
+ route.apply(ctx);
+ }
+}
diff --git a/src/main/java/io/floci/aws/services/signer/SignerService.java b/src/main/java/io/floci/aws/services/signer/SignerService.java
new file mode 100644
index 0000000000..a77c432f78
--- /dev/null
+++ b/src/main/java/io/floci/aws/services/signer/SignerService.java
@@ -0,0 +1,905 @@
+package io.floci.aws.services.signer;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.JsonNode;
+import io.floci.aws.config.EmulatorConfig;
+import io.floci.aws.core.common.AwsArnUtils;
+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.TagHandler;
+import io.floci.aws.core.storage.AccountAwareStorageBackend;
+import io.floci.aws.core.storage.StorageFactory;
+import io.floci.aws.services.signer.model.SigningJob;
+import io.floci.aws.services.signer.model.SigningProfile;
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.inject.Inject;
+import org.jboss.logging.Logger;
+
+import java.security.SecureRandom;
+import java.time.Instant;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.UUID;
+import java.util.regex.Pattern;
+
+/**
+ * The AWS Signer control plane: signing profiles, their cross-account permissions, and the signing
+ * jobs started against a profile.
+ *
+ * Signing profiles and jobs are metadata. Floci keeps the platform, the certificate a profile
+ * signs with, the overrides and the S3 source and destination a job names, so SDK calls and
+ * infrastructure-as-code round-trip, but no cryptographic signature is produced. A job started here
+ * therefore ends as {@code Failed} with a {@code statusReason} saying so, and carries no
+ * {@code signedObject}: nothing that has not been signed is reported as signed. Setting
+ * {@code floci.services.signer.mock-signing-jobs=true} (or
+ * {@code FLOCI_SERVICES_SIGNER_MOCK_SIGNING_JOBS}) opts into the other behaviour, where the job ends
+ * {@code Succeeded} with the destination recorded as its signed object and no object is written to
+ * S3. Both are documented on the service page and asserted by the service tests.
+ */
+@ApplicationScoped
+public class SignerService implements Resettable, TagHandler {
+
+ private static final Logger LOG = Logger.getLogger(SignerService.class);
+ private static final String SERVICE = "signer";
+ private static final String PROFILE_RESOURCE = "/signing-profiles/";
+ private static final String JOB_RESOURCE = "/signing-jobs/";
+
+ private static final Pattern PROFILE_NAME = Pattern.compile("[0-9a-zA-Z_]{2,64}");
+ private static final Pattern PROFILE_VERSION = Pattern.compile("[0-9a-zA-Z]{10}");
+ private static final Pattern TAG_KEY = Pattern.compile("^(?!aws:)[a-zA-Z+-=._:/]+$");
+ private static final Pattern STATEMENT_ID = Pattern.compile("[a-zA-Z0-9_-]{1,64}");
+ private static final Pattern CERTIFICATE_ARN = Pattern.compile(
+ "arn:" + AwsArnUtils.PARTITION_REGEX + ":acm:[a-z0-9-]+:[0-9]+:certificate/.+");
+
+ private static final Set VALIDITY_TYPES = Set.of("DAYS", "MONTHS", "YEARS");
+ private static final Map MAX_VALIDITY =
+ Map.of("DAYS", 4105, "MONTHS", 135, "YEARS", 11);
+ private static final Set PROFILE_STATUSES = Set.of("Active", "Canceled", "Revoked");
+ private static final Set JOB_STATUSES = Set.of("InProgress", "Failed", "Succeeded");
+ private static final Set CATEGORIES = Set.of("AWSIoT", "AWSLambda", "Notation-OCI");
+ /**
+ * The actions AWS lets a profile permission name. {@code signer:SignPayload} is grantable even
+ * though the operation itself is not served: a policy that allows signing a payload is valid,
+ * and refusing the grant would break templates that provision it.
+ */
+ private static final Set PROFILE_PERMISSION_ACTIONS = Set.of("signer:StartSigningJob",
+ "signer:SignPayload", "signer:GetSigningProfile", "signer:RevokeSignature");
+
+ private static final int MAX_TAGS = 50;
+ /** botocore caps both list operations' {@code maxResults} at 25, which is also their page size. */
+ private static final int MAX_PAGE_SIZE = 25;
+ private static final String ALPHANUMERIC =
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
+
+ private final AccountAwareStorageBackend profiles;
+ private final AccountAwareStorageBackend jobs;
+ private final boolean mockSigningJobs;
+ private final SecureRandom random = new SecureRandom();
+
+ @Inject
+ public SignerService(StorageFactory storageFactory, EmulatorConfig config) {
+ this(storageFactory.create(SERVICE, "signer-signing-profiles.json",
+ new TypeReference