📋 In This Post
Lab Overview
Someone on your team ships a new version of an app. It runs. A month later a question comes up in a review: who built that exact image, and did anyone check what was inside it? Most teams cannot answer either.
The problem. AWS has a managed answer to both questions — ECR can sign every image as it arrives, and Amazon Inspector can scan it for known flaws. Both are close to one click. Neither of them stops anything. Signing writes a signature; scanning writes a finding. If nothing reads them and acts, a flawed image is signed, scanned, documented — and still deployable.
The objective. Build the part nobody writes about: the gate that reads the evidence and refuses the image.
The outcome. The managed features worked on the first apply. The gate took five attempts, and the most important failure was one most pipelines would hit on day one.
| Difficulty | Intermediate |
| Lab runtime | Ran across 6–9 October; duration not recorded |
| Measured cost | $0.2409, 99.7% of it signing |
| Deployment | Terraform via HCP Terraform with OIDC |
| Full lab guide | GitHub — prerequisites, Terraform, commands, validation, cleanup |
Cloud Services and Concepts
| Service | Purpose here | What it is |
|---|---|---|
| Amazon ECR | Stores the container images, and is where managed signing is switched on by repository filter. | A private registry for container images, with per-repository rules such as refusing to overwrite a tag that already exists. |
| AWS Signer | Produces the signature — the provenance record of who built an image. | Signs artefacts, such as container images, so a consumer can verify where they came from and that they have not changed. |
| Amazon Inspector | Scans images for known vulnerabilities. A separate service with its own bill. | Scans workloads and container images for known software vulnerabilities, continuously rather than on request. |
| EventBridge | Carries the two triggers the gate listens on: scan finished, and image pushed. | An event bus. Services and your own code publish events to it, and rules decide which events reach which targets. |
| AWS Lambda | The gate. The only component here that can stop a deployment. | Runs a piece of code on demand with no server to manage. You are billed per request and per millisecond it runs, and each in-flight request occupies one execution environment. |
| Amazon SNS | Sends the quarantine notice, and alarms when the gate itself fails. | A publish-and-subscribe topic. One message is fanned out to every subscriber — email, a queue, or a function. |
| AWS CodeBuild | Builds and pushes the images, and therefore triggers signing. | Runs build and test commands on AWS-managed machines, billed per build minute. |
Basic versus enhanced scanning is not a quality setting. ECR presents them
as two settings of one feature. Basic is ECR's own scanner, free, and reads OS packages
only. Enhanced hands the work to Inspector at $0.09 per first scan and also reads your
language dependencies — the pinned versions in requirements.txt or
package-lock.json. You switch it on in the ECR console and the charges appear under
a service you never opened.
A signature answers "who", not "whether". Holding that distinction is the whole week.
Architecture and Workflow
- CodeBuild builds and pushes an image to an ECR repository.
- ECR matches the repository against the signing filter and asks AWS Signer to sign it. The signature records provenance, nothing about content.
- Inspector scans the image under enhanced scanning, reading OS packages and language dependencies.
- EventBridge carries the result on two separate triggers: Inspector's scan-complete event, and ECR's own image-push event.
- A Lambda gate reads the findings and decides. This is the only component that can refuse anything.
- A failing image is re-tagged
quarantined-*, its deployable tags removed, and an SNS notice sent.
Design decisions
Two triggers, not one. Keying only on "newly scanned" protects only images nobody has pushed before — see Troubleshooting. The ECR push event is the second trigger and it decides from findings Inspector already holds.
Quarantine by re-tagging, never delete. Deleting the image destroys the evidence needed to answer "what shipped, and when did we know".
Scoped by repository filter, not registry-wide. With signing billed per image, a registry-wide rule would sign everything you ever push.
Prerequisites
| Requirement | Detail |
|---|---|
| AWS account | Permission for ECR, Signer, Inspector, Lambda, EventBridge, SNS and CodeBuild |
| Terraform | >= 1.10, AWS provider 6.68.0 |
| HCP Terraform | Workspace with OIDC to AWS. No static keys |
| Inspector | Enabled per account, not per stack — this matters at cleanup |
| Region | us-east-1 |
One gap you will hit immediately. ECR managed signing shipped in November 2025 and still has no resource in the Terraform AWS provider — the pull request adding it was still open when 6.68.0 shipped on 7 October 2026. Confirm it yourself rather than trusting this page:
terraform validate
# Error: Invalid resource type ... aws_ecr_signing_configuration
Cost warning before you start: Inspector enhanced scanning has a 15-day free trial per account. If yours is already used, this lab costs more than the figure below.
Implementation
Twenty-four resources — and the proportion is the point. Only four of them exist because of signing and scanning: the signing profile, the signing configuration, the Inspector enabler and the scanning configuration. The other twenty are the enforcement nobody writes about.
week-22-container-image-security/
|
+-- terraform/
| +-- environments/dev/ HCP backend, OIDC, wires the modules
| +-- modules/registry/ ECR repositories, signing and scanning configuration
| +-- modules/gate/ the Lambda, its triggers, SNS and the alarm
| +-- modules/build/ CodeBuild project and its role
|
+-- src/gate/ the only code that enforces anything
|
+-- scripts/ the push-and-check tests
The gate is 164 lines. Everything else is declaration. Two ECR repositories are created: one inside the signing filter, one deliberately outside it as a control, so the tests can show the filter actually filtering.
The build role needs signer:SignPayload as well as the ECR push
actions. Without it the push succeeds and the image is simply never signed, with no error
anywhere.
Validation and Evidence
The managed features deploying is not the same as the gate working. Each of these was run against the live pipeline.
| Test | Expected | Actual | Status |
|---|---|---|---|
| Image push is signed | Valid Signer signature | Valid signature attached | Pass |
| Repository outside the filter | Not signed | Not signed | Pass |
| Enhanced scan reads language deps | Python findings reported | 12 Python findings incl. CVE-2023-30861 on Flask, vs 4 OS findings | Pass |
| Signed but vulnerable image | Quarantined | Quarantined on 16 findings despite a valid signature | Pass |
| Re-tagged existing image | Evaluated | No scan, no event, left deployable with 7 critical findings | Fail — fixed, see below |
| Gate failure behaviour | Fails closed, alarms | Raised rather than returning allow | Pass |
quarantined-* image.
Security and Cost
Security
Immutable tags. With mutable tags an image approved as v1.2.3
can be quietly repointed after review, and the signature and scan result then describe something
that is no longer there.
The gate quarantines, never deletes. Only the deployable tags go. Deleting the image would destroy the evidence needed to answer "what shipped, and when did we know".
It fails closed, and alarms on its own errors. Observed for real: when the gate broke it raised rather than returning an allow.
Least privilege, with a silent failure mode. The build role needs
signer:SignPayload alongside the ECR push actions. Without it the push succeeds and
the image is never signed — no error anywhere.
The signing key is not yours. A Signer profile takes a platform, a validity period and tags, and no key of any kind. For container signing AWS generates and holds the key material; you control who may ask it to sign. That is a trust decision, not an absence of one.
Cost
Billed $0.2409, read by usage type — grouping by service only ever says "ECR".
| Line | Cost | Share |
|---|---|---|
| ECR managed signing — 12 signatures at $0.02 | $0.2400 | 99.7% |
| ECR storage | $0.0009 | 0.3% |
| Amazon Inspector | $0.00 | 15-day free trial |
| CodeBuild, Lambda, EventBridge, SNS | $0.00 | free tier |
I wrote, before the bill arrived, that signing was free. AWS Signer is free
with ECR — its pricing page says so. The charge is on ECR's side, as
AsyncActions-ImageSigning at $0.02 per signature, and ECR's pricing
page carries a "Managed Signing" heading with no figure under it. The bill was the only place
that number appeared.
Twelve signatures, not three, because every rebuild re-signs. Four builds during one night of debugging cost four times a single build. On a busy pipeline that is the line to watch — not storage, which came to nine hundredths of a cent.
Two controls matter more than the rates. Scope scanning and signing by repository filter rather than registry-wide, and expire untagged images with a lifecycle policy — under continuous scanning every retained image is rescanned whenever the vulnerability database updates.
Troubleshooting and Lessons
The gate missed the case that matters most
Problem. An image rebuilt byte-identically sat deployable with seven
critical findings.
Root cause. Inspector emits its scan-complete event only the first time
it sees a digest. The rebuild attached a new tag to content Inspector already knew, so
there was no new scan, no event, and no evaluation. Deleting the image from ECR first did not
help; Inspector still remembered.
Resolution. A second trigger on ECR's own push event, deciding from findings
Inspector already holds.
Lesson. This is not an edge case. Promoting an image by re-tagging it
— v1.2.3 becomes prod — is how images normally reach
production, and it pushes no new bytes. A gate keyed on first scans protects only
images nobody has pushed before.
A valid signature on an image we refused to deploy
Problem. The headline test quarantined an image carrying a complete, valid
AWS Signer signature.
Root cause. Working as intended — 16 findings, of which 12 were Python
package findings including CVE-2023-30861 on Flask, against 4 OS findings. Basic scanning would
have reported the four and stopped.
Resolution. None needed; this is the demonstration.
Lesson. A signature tells you who built an image and nothing about
whether it is safe to run. Those are different questions, and only one is answered by
the feature with "signing" in the name.
Terraform has no resource for ECR managed signing
Problem. terraform validate rejects the signing configuration
outright.
Root cause. The feature shipped in November 2025; the provider pull request was
still open when 6.68.0 shipped on 7 October 2026.
Resolution. Create it outside Terraform and document the gap, rather than
pretending the stack is complete.
Lesson. "Managed" does not imply "declarable". Check provider coverage before
designing around a new feature.
Cleanup and Key Takeaways
Inspector is enabled per account, not per stack, so it is worth being
explicit about who removes it. Here the enabler and the registry scanning configuration are
Terraform resources and terraform destroy did remove both — the teardown
script found scanning already back to BASIC and all five Inspector scan types
already DISABLED.
The script still checks, and still disables them if it finds them on. That is not superstition: in an earlier week a CloudWatch anomaly detector survived a destroy and kept billing for days, because nothing in the state file owned it. Account-level settings are the category where "the destroy probably handled it" is worth converting into a command that looks.
The script also cancels the signing profile. Signer profiles cannot be deleted, only cancelled — the documented end state rather than a leftover.
Key takeaways
- A signature says who, not whether. A valid signature on a vulnerable image is the most comfortable false assurance in this area.
- Signing and scanning stop nothing. They produce evidence. Something has to read it and act, and that something is yours to build and yours to get wrong.
- Enforcement keyed on "newly scanned" misses the normal case. Promoting an existing image pushes no new bytes and triggers no scan.
- Signing is billed per signature and the rate is not on the pricing page. $0.02 each, 99.7% of this week's bill, and every rebuild re-signs.
- Test the enforcement, not the features. The managed parts worked on the first apply; the part that actually stops a bad image took five attempts, and every fault was found by a test rather than by reading the code.
Comments