ecr-repository-auditor
Audits AWS ECR private repositories for public-access exposure via repositoryPolicy, image-scan configuration gaps (scanOnPush off + unscanned images), lifecycle-policy absence, tag-immutability gaps, and encryption posture. Emits a deterministic verdict (PUBLIC | NO_SCAN | NO_LIFECYCLE | CONFIG_GAP | OK) per repository with enumerated findings and specific CLI remediation. Use when reviewing ECR repository policies, checking for public image access, validating scan-on-push enablement, auditing lifecycle rules, or hardening container-image supply-chain posture before production deployment.
- License 许可
- Apache-2.0
- 最近更新
- 2026-09-24
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- ecr-repository-auditor
- license
- Apache-2.0
- metadata
- { "tags": "ecr, storage, security, container, supply-chain, image-scanning, lifecycle, tag-immutability, audit", "phase": "2", "author": "Jacky Chan — AWS Community Builder", "domain": "aws-cloudops", "family": "Storage", "version": "0.1.0", "keywords": "ECR, container registry, repository policy, scanOnPush, image scanning, lifecycle policy, tag immutability, Principal:\"*\", cross-account ECR, supply chain security, container image audit, unscanned images, ecr:GetDownloadUrlForLayer, ecr:BatchGetImage, ecr:PutImage, aws:SourceVpce, image vulnerability, KMS encryption ECR, ECR public access", "complexity": "high", "entry_point": "false", "when_to_use": "Reviewing an ECR repository before production deployment, checking for public image access via repositoryPolicy, validating scan-on-push enablement, auditing lifecycle-policy coverage, hardening tag immutability, or assessing container supply-chain posture across an account.", "requires_llm": "true", "verdict_shape": "PUBLIC | NO_SCAN | NO_LIFECYCLE | CONFIG_GAP | OK", "invocation_schema": "Input: either (a) an ECR repository configuration bundle (repositoryPolicy JSON + imageScanningConfiguration + imageTagMutability + lifecyclePolicyText + image metadata), OR (b) a repository name/ARN for live-account audit. Output: deterministic REPO/VERDICT/REASON/FINDINGS/REMEDIATION block per repository, where VERDICT is one of {PUBLIC, NO_SCAN, NO_LIFECYCLE, CONFIG_GAP, OK}.", "supports_pipeline": "true", "activation_triggers": "audit this ECR repository, is my ECR repo public, check ECR repository policy, ECR scanOnPush enabled, ECR lifecycle policy, unscanned container images, tag immutability check, ECR cross-account access, container image vulnerability scan, hardening ECR repository" }
- description
- Audits AWS ECR private repositories for public-access exposure via repositoryPolicy, image-scan configuration gaps (scanOnPush off + unscanned images), lifecycle-policy absence, tag-immutability gaps, and encryption posture. Emits a deterministic verdict (PUBLIC | NO_SCAN | NO_LIFECYCLE | CONFIG_GAP | OK) per repository with enumerated findings and specific CLI remediation. Use when reviewing ECR repository policies, checking for public image access, validating scan-on-push enablement, auditing lifecycle rules, or hardening container-image supply-chain posture before production deployment.
- compatibility
- Agent runtime that reads SKILL.md (Claude Code, Cursor, Windsurf, Codex, Gemini). No AWS CLI required for offline config classification. Live-account audits use aws ecr describe-repositories, aws ecr get-repository-policy, aws ecr describe-images, aws ecr get-lifecycle-policy, and aws ecr put-image-scanning-configuration (AWS CLI v2, SSO or key-based credentials).
02 资源文件 19
- 参考文档eval/test-cases.yaml8.9 KB
- 参考文档evals/baselines/clean-ok.md306 B
- 参考文档evals/baselines/no-lifecycle-policy.md423 B
- 参考文档evals/baselines/public-pull-sourcevpce-scoped-config-gap.md571 B
- 参考文档evals/baselines/public-pull-wildcard-no-condition.md629 B
- 参考文档evals/baselines/scan-off-unscanned-images.md479 B
- 参考文档evals/baselines/tag-mutable-config-gap.md451 B
- 参考文档evals/eval_config.yaml1.9 KB
- 参考文档evals/evals.json4.8 KB
- 参考文档evals/prompts/clean-ok.md732 B
- 参考文档evals/prompts/no-lifecycle-policy.md753 B
- 参考文档evals/prompts/public-pull-sourcevpce-scoped-config-gap.md1.1 KB
- 参考文档evals/prompts/public-pull-wildcard-no-condition.md757 B
- 参考文档evals/prompts/scan-off-unscanned-images.md838 B
- 参考文档evals/prompts/tag-mutable-config-gap.md758 B
- 参考文档examples/end-to-end.md6.1 KB
- 参考文档references/advanced-patterns.md11.3 KB
- 参考文档references/diagnostic-commands.md6.3 KB
- 参考文档skill.usf.yaml3.9 KB
03 SKILL.md 正文
ECR Repository Auditor
Mindset
One-line takeaway: the verdict is always the worst finding across all
dimensions, and repositoryPolicy with Principal: "*" is the dominant
finding — a public container image is a supply-chain attack surface that
silently spreads to every downstream deployment.
An ECR private repository is the source of truth for container images that production workloads pull and execute. Three properties make ECR audit distinct from S3 or KMS:
- A public repository policy (
Principal: "*") grants the entire internet permission to pull images — and anyone who can pull can inspect every layer for embedded secrets, application logic, and dependency versions. - scanOnPush: false creates a vulnerability blind spot: images enter the registry unscanned, and without a lifecycle policy, stale unscanned images accumulate indefinitely.
- Tag mutability (
MUTABLE) is a supply-chain integrity risk: any principal withecr:PutImagecan overwrite a production tag (:latest,:v2) with a different image digest, silently swapping what deployments pull.
Quick reference — verdict thresholds
| Condition | Verdict | Step |
|---|---|---|
Principal: "*" + pull/push action + no STRONG condition |
PUBLIC | Step 1 |
| Cross-account + pull/push action + no STRONG condition | PUBLIC | Step 1 |
Principal: "*" + pull/push action + STRONG condition (aws:SourceVpce, aws:SourceAccount) |
CONFIG_GAP | Step 1 (downgrade) |
imageScanningConfiguration.scanOnPush: false AND images with imageScanStatus null/incomplete |
NO_SCAN | Step 2 |
scanOnPush: false AND zero images in repo |
NO_SCAN | Step 2 |
No lifecyclePolicyText present |
NO_LIFECYCLE | Step 3 |
imageTagMutability: MUTABLE (all other dimensions clean) |
CONFIG_GAP | Step 4 |
| Cross-account + metadata-only actions + no condition | CONFIG_GAP | Step 4 |
| All dimensions clean | OK | Step 5 |
See the ordered steps below for edge cases. Deep ECR authorization internals (policy vs IAM intersection, lifecycle rule ordering, enhanced scanning) are in the Deep reference section at the end.
Pre-flight: repository metadata gate (run before policy classification)
Before evaluating the repository policy, classify the repository itself. Several attributes short-circuit the audit — misclassifying them produces false positives.
Multi-repo / account-wide sweep pagination guidance moved verbatim to references/diagnostic-commands.md. Load on demand when auditing every repository in an account (describe-repositories / describe-images / lifecycle-preview nextToken draining).
Live-account pre-flight checks (skip if doing offline config audit): Live-account pre-flight checks (remediation IAM permissions, CloudTrail data events, pre-edit image snapshot) moved verbatim to references/diagnostic-commands.md. Load on demand before a live-account audit that may propose remediation.
| Attribute | Value | Effect on audit |
|---|---|---|
registryId |
account ID | The 12-digit account that owns the registry. Cross-account principal detection compares this against principal ARNs in the repositoryPolicy. |
| Empty repositoryPolicy | no policy document | IAM-only access. This is the DEFAULT and MOST SECURE posture for ECR private repos. No resource-based policy means access is controlled entirely by IAM identity-based policies. Do NOT flag as a gap — proceed to scan/lifecycle/tag steps. |
imageScanningConfiguration.scanOnPush |
true |
Images are scanned automatically on push. Does NOT scan images pushed before this was enabled, nor re-scan on CVE database updates (unless enhanced scanning is on). |
imageScanningConfiguration.scanOnPush |
false |
Images are NOT scanned on push. Manual aws ecr start-image-scan is required per image. Flag in Step 2 if unscanned images exist. |
imageTagMutability |
IMMUTABLE |
Tags cannot be overwritten — each tag permanently maps to one digest. This is the secure default for supply-chain integrity. |
imageTagMutability |
MUTABLE |
Tags CAN be overwritten — any principal with ecr:PutImage can push a new image under an existing tag, silently changing what deployments pull. Flag in Step 4. |
encryptionConfiguration.encryptionType |
AES256 |
Default encryption using an AWS-managed key. Acceptable but not customer-controlled. Note as informational. |
encryptionConfiguration.encryptionType |
KMS |
Customer-managed KMS key (BYOK). Provides audit trail via CloudTrail and rotation control. |
encryptionConfiguration.encryptionType |
KMS_DSSE |
Double-layer server-side encryption (KMS + AES256). Highest encryption posture. |
encryptionConfiguration.encryptionType |
absent | Defaults to AES256. Do not flag. |
lifecyclePolicyText |
absent / empty | No lifecycle rules. Images accumulate indefinitely — cost grows unbounded and stale images remain pullable. Flag in Step 3. |
If the repositoryPolicy JSON is malformed (invalid JSON, missing
Statement, missing Principal or Action/NotAction), output:
REPO: <repo-name>
VERDICT: ERROR
REASON: Repository policy document is not valid JSON or is missing required fields — cannot classify.
REMEDIATION: Retrieve the canonical policy with `aws ecr get-repository-policy --repository-name <name> --output json` and re-audit.
Process — Classification logic (apply in order, aggregate worst)
Step 0: Expert knowledge — non-obvious ECR behaviors that change classification
These behaviors are easy to misjudge without operational ECR experience. Each changes a verdict if ignored:
Step 0 expert-knowledge behaviors moved verbatim to references/advanced-patterns.md. Load on demand when a verdict depends on non-obvious behavior (private vs public, GetAuthorizationToken scope, union/intersection, SourceVpce strength, scan staleness, rulePriority order, untagged cleanup).
Step 1: PUBLIC — repositoryPolicy exposure (highest priority)
For each Effect: Allow statement in the repositoryPolicy, classify the
principal and actions:
Principal scope:
- WILDCARD_PRINCIPAL — Principal is
"*",{"AWS": "*"}, or any construct resolving to all authenticated AWS principals. - CROSS_ACCOUNT — Principal includes an ARN whose 12-digit account ID
differs from the registry's owning account (
registryId). - SAME_ACCOUNT — All principals share the
registryId. This includes the account root, same-account roles, users, and services.
Action danger classification:
- PULL —
ecr:GetDownloadUrlForLayer,ecr:BatchGetImage,ecr:BatchCheckLayerAvailability,ecr:DescribeImages,ecr:DescribeRepositories,ecr:GetDownloadUrlForLayer. A principal with pull can download every layer — equivalent to reading all source code, secrets, and binaries. - PUSH —
ecr:PutImage,ecr:InitiateLayerUpload,ecr:UploadLayerPart,ecr:CompleteLayerUpload,ecr:BatchDeleteImage. A principal with push can inject malicious images or overwrite production tags. - ADMIN —
ecr:*,ecr:DeleteRepository,ecr:PutRepositoryPolicy,ecr:SetRepositoryPolicy. Full control of the repo including policy modification and deletion. - METADATA —
ecr:Describe*,ecr:List*,ecr:GetRepositoryPolicy. Read-only informational access. Low severity but still a data leak in aggregate (repo names, image counts, tags).
Severity matrix for repositoryPolicy (apply in order, first match wins):
| # | Principal | Action | Condition | Severity |
|---|---|---|---|---|
| 1a | WILDCARD_PRINCIPAL | PUSH or ADMIN | None/weak | PUBLIC |
| 1b | WILDCARD_PRINCIPAL | PULL | None/weak | PUBLIC |
| 1c | CROSS_ACCOUNT | PUSH or ADMIN | None/weak | PUBLIC |
| 1d | CROSS_ACCOUNT | PULL | None/weak | PUBLIC |
| 1e | WILDCARD or CROSS | PULL/PUSH | STRONG (aws:SourceVpce, aws:SourceAccount, aws:SourceArn) |
CONFIG_GAP (downgraded — fragile but scoped) |
| 1f | WILDCARD or CROSS | METADATA only | None/weak | CONFIG_GAP |
| 1g | SAME_ACCOUNT | Any | Any | Not a PUBLIC finding (proceed to other steps) |
Special case — the empty repositoryPolicy: An ECR repo with no
repositoryPolicy (the default) has NO resource-based policy. This means
access is governed ENTIRELY by IAM identity-based policies. This is the
SECURE DEFAULT. Do NOT flag an empty repo policy as a gap — it is more
secure than a permissive one. Proceed to Steps 2-4.
Special case — the account-root delegation statement: A statement with
Principal: {"AWS": "arn:aws:iam::ACCOUNT:root"} + ecr:* (or any broad
action set) is the root-delegation pattern. It delegates repository
access control to the account's IAM identity-based policies — anyone with
the right IAM permissions can use the repo, anyone without cannot. This is
the NORMAL and EXPECTED pattern for ECR repos that rely on IAM for access
control. Do NOT flag it as CONFIG_GAP or any other finding. It is functionally
equivalent to the empty repositoryPolicy (both defer to IAM). Classify this
statement as SAME_ACCOUNT / OK (row 1g) and proceed to Steps 2-4. The only
exception: if the same statement ALSO includes a wildcard or cross-account
principal alongside the root principal — classify by the WIDEST principal
(row 1a-1f apply to the wildcard/cross-account portion).
Special case — the account-root delegation statement: A statement with
Principal: {"AWS": "arn:aws:iam::ACCOUNT:root"} + ecr:* (or any broad
action set) is the root-delegation pattern. It delegates repository
access control to the account's IAM identity-based policies — anyone with
the right IAM permissions can use the repo, anyone without cannot. This is
the NORMAL and EXPECTED pattern for ECR repos that rely on IAM for access
control. Do NOT flag it as CONFIG_GAP or any other finding. It is functionally
equivalent to the empty repositoryPolicy (both defer to IAM). Classify this
statement as SAME_ACCOUNT / OK (row 1g) and proceed to Steps 2-4. The only
exception: if the same statement ALSO includes a wildcard or cross-account
principal alongside the root principal — classify by the WIDEST principal
(row 1a-1f apply to the wildcard/cross-account portion).
NotAction in an Allow statement is an inverse wildcard — it grants every ECR action EXCEPT the listed ones. Treat as ADMIN danger level (worst case) because new ECR APIs are automatically included.
Condition strength:
- STRONG (downgrade by two levels):
aws:SourceVpce(VPC endpoint ID — infrastructure-assigned, unforgeable),aws:SourceAccountwithStringEquals,aws:SourceArnwithStringEquals/StringLike. - WEAK (no downgrade):
aws:SourceIp/aws:SourceIpcontaining0.0.0.0/0(bypassable by anyone with a proxy or VPN; the entire internet if0.0.0.0/0),aws:Referer,aws:UserAgent(trivially forgeable).
Step 2: NO_SCAN — image scanning gaps
Evaluate the scanning posture:
-
scanOnPush: falseAND any image withimageScanStatus: nullorimageScanStatus.statusnot"COMPLETE"→ NO_SCAN. Images are entering the registry without vulnerability scanning. Any CVE in a base image layer or dependency goes undetected. -
scanOnPush: falseAND the repo has zero images → NO_SCAN. The repo is empty now, but the first image pushed will not be scanned. Remediate preemptively. -
scanOnPush: trueAND all images haveimageScanStatus.status: "COMPLETE"→ OK for this dimension. Note: basic scanning (non-enhanced) does not re-scan on CVE database updates — recommend enhanced scanning for production repos. -
scanOnPush: trueAND some images haveimageScanStatus: null→ NO_SCAN. These images were pushed before scanOnPush was enabled and were never manually scanned. Runaws ecr start-image-scanon each.
Step 3: NO_LIFECYCLE — lifecycle policy absence
-
No
lifecyclePolicyTextpresent (empty string or absent field) → NO_LIFECYCLE. Without lifecycle rules, images accumulate indefinitely. This means: (1) storage cost grows without bound, (2) stale images with known vulnerabilities remain pullable, (3) the repo approaches the per-repo image quota with no cleanup path. -
lifecyclePolicyTextpresent but contains only atagStatus: taggedretention rule with notagStatus: untaggedrule → still NO_LIFECYCLE (partial gap). Untagged images are not cleaned up. Emit a CONFIG_GAP-level note within the NO_LIFECYCLE finding: "Lifecycle policy exists but lacks anuntaggedcleanup rule — untagged images accumulate indefinitely." -
lifecyclePolicyTextpresent with at least one rule → OK for this dimension. Verify the rule ordering (lowestrulePriorityevaluated first) and that the rule set is logically sound (a broad early rule does not shadow a selective later rule).
Step 4: CONFIG_GAP — tag immutability, encryption, and other config gaps
If Steps 1-3 produced no PUBLIC/NO_SCAN/NO_LIFECYCLE finding, evaluate remaining configuration:
-
imageTagMutability: MUTABLE→ CONFIG_GAP. Tags can be overwritten by any principal withecr:PutImage. A supply-chain attacker who compromises a CI/CD role can push a backdoored image under the:prodtag, and the next deployment pulls the malicious image with no visible change to the tag name. Immutable tags prevent this: each tag permanently maps to one digest. -
Cross-account principal with METADATA-only actions and no condition → CONFIG_GAP. Not PUBLIC (metadata only) but still an information leak (repo inventory, image counts, tag names).
-
Cross-account PULL/PUSH with STRONG condition (already downgraded from Step 1) → the downgrade lands here as CONFIG_GAP (fragile but scoped).
-
imageTagMutability: IMMUTABLE+ no other config gaps → OK for this dimension.
Step 5: Aggregation — worst finding wins
The final verdict is the maximum severity finding across all steps, where PUBLIC > NO_SCAN > NO_LIFECYCLE > CONFIG_GAP > OK:
verdict = max(step1_finding, step2_finding, step3_finding, step4_finding)
If no findings (all dimensions clean), the verdict is OK.
Output format (per repository)
REPO: <registry-id>.dkr.ecr.<region>.amazonaws.com/<repo-name>
VERDICT: PUBLIC | NO_SCAN | NO_LIFECYCLE | CONFIG_GAP | OK
REASON: <1-2 sentences citing the worst finding and its step>
FINDINGS:
- [PUBLIC] <finding description (Step 1a)>
- [NO_SCAN] <finding description (Step 2)>
- [OK] <dimension that passed>
REMEDIATION: <specific action per finding, or "None required" if OK>
Worked example — public pull with scan off and no lifecycle
REPO: 111111111111.dkr.ecr.us-east-1.amazonaws.com/app-frontend
VERDICT: PUBLIC
REASON: Statement "PublicPull" grants ecr:BatchGetImage and
ecr:GetDownloadUrlForLayer to Principal "*" with no condition — any AWS
account holder can pull every image layer, exposing source code and embedded
secrets (Step 1b). scanOnPush is also disabled with unscanned images present.
FINDINGS:
- [PUBLIC] Principal "*" + PULL actions (BatchGetImage, GetDownloadUrlForLayer) with no condition (Step 1b)
- [NO_SCAN] scanOnPush: false + 3 images with imageScanStatus: null (Step 2)
- [NO_LIFECYCLE] No lifecyclePolicyText present (Step 3)
- [CONFIG_GAP] imageTagMutability: MUTABLE (Step 4)
REMEDIATION:
1. PUBLIC — Remove the "PublicPull" statement or add aws:SourceAccount /
aws:SourceVpce conditions to scope to trusted accounts/endpoints only.
2. NO_SCAN — Enable scan-on-push:
aws ecr put-image-scanning-configuration --repository-name app-frontend
--image-scanning-configuration scanOnPush=true --registry-id 111111111111
3. NO_LIFECYCLE — Apply a lifecycle policy that keeps the last 10 tagged
images and deletes untagged images after 1 day (see remediation CLI).
4. CONFIG_GAP — Set tag immutability:
aws ecr put-image-tag-mutability --repository-name app-frontend
--image-tag-mutability IMMUTABLE --registry-id 111111111111
Anti-Patterns — NEVER
-
NEVER classify a
Principal: "*"grant withecr:BatchGetImage/ecr:GetDownloadUrlForLayeras anything other than PUBLIC when there is no STRONG condition. Pull permissions grant access to every image layer — equivalent to reading all source code, embedded secrets, and binaries. This is not "broad access" — it is total image exposure. -
NEVER flag an empty repositoryPolicy as a security gap. An ECR repo with no resource-based policy relies on IAM identity-based policies for access control — this is the secure default and more restrictive than a permissive policy. Flagging it as a gap causes unnecessary policy churn that can introduce exposure.
-
NEVER flag
Principal: {"AWS": "arn:aws:iam::ACCOUNT:root"}+ecr:*as a CONFIG_GAP or security finding. This is the root-delegation statement — it delegates repository access to the account's IAM policies, exactly like an empty repositoryPolicy but explicit. Without it, IAM-based access patterns still work (same-account union evaluation), but its presence is NOT a sign of over-permissive access. The root principal is the account owner;ecr:*to root means "the account owner can manage this repo via IAM." Flagging it as CONFIG_GAP is a false positive that produces alert fatigue. The equivalent in KMS is the root-of-trust statement — normal and required. -
NEVER flag
Principal: {"AWS": "arn:aws:iam::ACCOUNT:root"}+ecr:*as a CONFIG_GAP or security finding. This is the root-delegation statement — it delegates repository access to the account's IAM policies, exactly like an empty repositoryPolicy but explicit. Without it, IAM-based access patterns still work (same-account union evaluation), but its presence is NOT a sign of over-permissive access. The root principal is the account owner;ecr:*to root means "the account owner can manage this repo via IAM." Flagging it as CONFIG_GAP is a false positive that produces alert fatigue. The equivalent in KMS is the root-of-trust statement — normal and required. -
NEVER treat
aws:SourceIpwith0.0.0.0/0as a real condition. This CIDR is the entire internet and provides zero restriction. Any principal with a proxy, VPN, or NAT gateway can route through an allowed CIDR. Treat the statement as if the condition is absent. -
NEVER treat
ecr:GetAuthorizationTokenin a repositoryPolicy as a meaningful grant. This action is account-scoped (returns a registry-wide auth token) and is evaluated at the IAM level, not the repo-policy level. Its presence in a repo policy is misleading — do NOT use it to escalate the verdict or classify as a PULL/PUSH/ADMIN action. -
NEVER classify a
Principal: "*"grant with a STRONG condition (aws:SourceVpce,aws:SourceAccount,aws:SourceArn) as PUBLIC. The condition narrows access to a known endpoint or account. Downgrade to CONFIG_GAP. Classifying it as PUBLIC conflates "currently restricted" with "unrestricted" and produces alert fatigue. -
NEVER overlook
NotActionin an Allow statement.NotActiongrants every ECR action EXCEPT the listed ones — the inverse of the intended scope, and almost always a misconfiguration. Treat as ADMIN danger (worst case) because new ECR APIs are automatically included. -
NEVER assume
scanOnPush: truemeans all images are scanned. Images pushed before scanOnPush was enabled are NOT retroactively scanned. Always enumerate images and check per-imageimageScanStatus— the repo-level config reflects intent, not per-image reality. -
NEVER assume a lifecycle policy with
tagStatus: taggedrules cleans up untagged images. Only atagStatus: untaggedrule deletes untagged images. Without it, untagged images persist indefinitely, consuming storage and counting against the image quota while being invisible to tag-based queries. -
NEVER recommend setting
imageTagMutability: IMMUTABLEwithout warning that existing mutable tags remain mutable until overwritten. The setting applies to future tag operations only — a tag that was overwritten before the change keeps its current digest. Re-push affected images to pin the intended digest. -
NEVER ignore lifecycle policy
rulePriorityordering. Rules are evaluated lowest-number-first and first-match-wins. A broad retention/deletion rule at priority 1 shadows all subsequent rules. The most selective rule must have the lowest priority number. -
NEVER assume cross-region replication does not propagate repository policies. ECR replication copies the source repo's repositoryPolicy to replicas in target regions. A public policy on a source repo is automatically multi-region. Audit replicas independently when replication is configured.
-
NEVER confuse ECR Private with ECR Public. ECR Private (
api.ecr.<region>.amazonaws.com) uses repositoryPolicy for access control. ECR Public (public.ecr.aws) uses catalog-level visibility — there is no per-repo policy for public access. This skill audits private repositories only. -
NEVER recommend deleting an ECR repository as remediation without first verifying that no running workloads pull from it. Repository deletion is irreversible — all images are permanently lost. Run
aws ecr describe-imagesand check ECS/EC2/EKS task definitions for references before recommending deletion. -
NEVER classify a same-account-only repositoryPolicy with named principals as PUBLIC. Same-account access is governed by IAM identity-based policies (union evaluation), which provides a second authorization layer. Flag CONFIG_GAP at worst for same-account metadata-only cross-principal access.
Pre-flight safety checks (run before any remediation CLI)
-
MANDATORY CONFIRMATION GATE. Before any state-changing operation (PutImageScanningConfiguration, PutLifecyclePolicy, PutImageTagMutability, DeleteRepositoryPolicy, DeleteRepository), the auditor MUST emit:
CONFIRM: About to <action> on repository <name> in account <account>. This affects <consequence>. Proceed? (yes/no)Do NOT execute the CLI command until the operator confirms. -
PutImageTagMutability is irreversible for existing tags. Changing from MUTABLE to IMMUTABLE prevents future overwrites but does not restore previously overwritten tags. Changing from IMMUTABLE to MUTABLE re-enables overwrites for all tags. Warn the operator about both directions.
-
PutLifecyclePolicy can delete images immediately. A lifecycle policy with
tagStatus: anyandcountNumberInList: 1evaluates on the next lifecycle evaluation cycle (within ~24 hours) and can delete images matching the rule. ALWAYS runaws ecr get-lifecycle-policy-previewto dry-run the policy before applying it. The preview shows exactly which images would be deleted. -
Confirm the repository exists and is accessible:
aws ecr describe-repositories --repository-names <name> --registry-id <id>— fail closed (skip remediation) if it returns an error. -
Capture the current configuration for rollback before any modification:
aws ecr get-repository-policy --repository-name <name> --registry-id <id> \ --output json > /tmp/<name>-policy-backup-$(date +%s).json aws ecr get-lifecycle-policy --repository-name <name> --registry-id <id> \ --output json > /tmp/<name>-lifecycle-backup-$(date +%s).json -
For PUBLIC findings (wildcard principal with pull/push, no condition), treat as incident-response. Audit CloudTrail for
ecr:BatchGetImage/ecr:GetDownloadUrlForLayerevents from external principals during the exposure window. Any pulled image should be considered potentially inspected for embedded secrets — rotate any secrets found in image layers. -
Prefer additive changes (add a Deny statement, add a condition) over destructive changes (remove an Allow statement) — additive changes are reversible and do not risk breaking existing pull workflows. The safe sequence for a PUBLIC finding is: (1) back up policy, (2) add a Deny that blocks the wildcard principal, (3) verify the Deny is effective via policy preview, (4) only then remove the offending Allow statement.
Remediation guidance
Per-verdict remediation guidance (PUBLIC, NO_SCAN, NO_LIFECYCLE, CONFIG_GAP, OK) with full CLI sequences moved verbatim to references/diagnostic-commands.md. Load on demand when emitting REMEDIATION or before executing any state-changing CLI.
Deep reference: ECR authorization and scanning internals
Deep ECR authorization and scanning internals moved verbatim to references/advanced-patterns.md. Load on demand for the policy-vs-IAM evaluation pipeline, lifecycle rule evaluation, basic vs enhanced scanning, KMS encryption internals, and replication propagation.
Recent AWS features (2024-2026)
Recent AWS features (2024-2026) moved verbatim to references/advanced-patterns.md. Load on demand when auditing enhanced scanning, pull-through caches, replication, or lifecycle enhancements.
References (load on demand)
- references/diagnostic-commands.md — live-account pre-flight checks, multi-repo sweep pagination, and per-verdict remediation CLI sequences moved from SKILL.md.
- references/advanced-patterns.md — Step 0 expert-knowledge deep dives, ECR authorization and scanning internals, and recent AWS features moved from SKILL.md.
Domain
AWS CloudOps / ECR Container Registry Security & Supply-Chain Compliance.
AWS documentation
- Amazon ECR User Guide — https://docs.aws.amazon.com/AmazonECR/latest/userguide/what-is-ecr.html
- ECR Security — https://docs.aws.amazon.com/AmazonECR/latest/userguide/security.html
- ECR API Reference — https://docs.aws.amazon.com/AmazonECR/latest/APIReference/
- ECR CLI Reference — https://docs.aws.amazon.com/cli/latest/reference/ecr/
- Enhanced scanning with Amazon Inspector — https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning-enhanced.html
04 同仓库更多 Skills
xray-tracing-deployer
Deploys AWS X-Ray distributed tracing with production-grade configuration: X-Ray daemon deployment (EC2 systemd, ECS sidecar, EKS DaemonSet, Lambda built-in), SDK instrumentation (Java, Python, Node.js, Go, .NET) with annotations and metadata, sampling rules (default reservoir + rate vs custom rules with URL / method / service-name predicates), service map generation, trace query and retrieval, groups and insights, CloudWatch ServiceLens integration, IAM permissions (PutTraceSegments, GetSamplingRules), and latest features (Lambda Powertools tracing, OpenTelemetry / ADOT Collector support, W3C trace context). Emits a READY_TO_DEPLOY checklist with every configuration item verified. Use when enabling X-Ray on a new application, adding tracing to ECS / EKS / Lambda, validating a sampling configuration, or generating daemon deployment CLI and IaC templates. Triggers: X-Ray, distributed tracing, X-Ray daemon, sampling rules, service map, X-Ray SDK, OpenTelemetry, ADOT, Lambda Powertools, CloudWatch ServiceLens.
wellarchitected-workload-auditor
Audits AWS Well-Architected Tool workloads for review staleness, per-pillar high-risk issue counts, milestone tracking gaps, and remediation plan completeness. Emits a deterministic verdict (STALE_REVIEW | HIGH_RISK | CONFIG_GAP | OK) per workload with per-pillar risk breakdown, milestone trend analysis, and specific remediation. Use when reviewing Well-Architected workloads, checking WA review freshness, auditing high-risk issues per pillar, validating milestone coverage, or tracking remediation plans.
wellarchitected-review-operator
Operates AWS Well-Architected Tool reviews end-to-end — creates workloads, runs pillar reviews (operational excellence, security, reliability, performance, cost optimization, sustainability, Prosperity), answers questions with risk-tier rationale, generates reports and improvement plans, creates milestones, and integrates with Trusted Advisor and Well-Architected Labs. Runs deterministic pre-checks (workload existence, lens availability, pillar coverage), emits the exact update-answer / get-consolidated-report CLI behind a CONFIRM gate, and verifies risk-tier transitions. Emits READY | BLOCKED | COMPLETED. Use when creating a workload, answering pillar questions, generating an improvement plan, creating a milestone, or integrating with Trusted Advisor. Triggers: well-architected tool, well architected review, workload review, pillar, operational excellence, security, reliability, performance, cost optimization, sustainability, prosperity, improvement plan, milestone, trusted advisor.
wafv2-web-acl-deployer
Provisions AWS WAFv2 Web ACLs with correct production defaults: scope selection (CLOUDFRONT vs REGIONAL), managed rule groups (AWSManagedRulesCommonRuleSet, SQLiRuleSet, LinuxRuleSet, WindowsRuleSet, IPReputationList, BotControlRuleSet, AmazonIpReputationList, ATP), custom rules (byte match, IP set, regex pattern, geo match, size constraint, rate-based), rule priority ordering, logging destinations (Kinesis Firehose, CloudWatch Logs, S3), resource association (ALB, API Gateway, CloudFront), rate-based rules with aggregate keys (IP, forwarded IP), Challenge and CAPTCHA actions, and account takeover prevention. Emits a READY_TO_DEPLOY checklist. Use when creating a Web ACL, attaching managed rules, configuring rate limiting, enabling WAF logging, associating a Web ACL with an ALB/API Gateway/CloudFront, or configuring CAPTCHA/Challenge actions. Triggers: create WAF Web ACL, WAFv2, managed rule groups, WAF rate limiting, WAF logging, WAF CAPTCHA, WAF Challenge action, bot control, ATP managed rules.
wafv2-web-acl-auditor
Audits AWS WAFv2 Web ACL configurations to determine whether the ACL provides effective protection: default-action posture (Allow vs Block), managed-rule-group coverage gaps, rule effectiveness (BLOCK vs COUNT, shadow/bypass rules, stale exclusions), rate-based rule correctness, logging and visibility configuration, and text-transformation bypass vectors. Emits a deterministic verdict per Web ACL. Use when reviewing a WAFv2 Web ACL for security posture, checking managed-rule coverage, validating rate-limit configuration, auditing WAF logging, or hardening a WAF before production deployment. Triggers: WAF, WAFv2, Web ACL, managed rule group, AWSManagedRules, rate-based rule, CAPTCHA, Challenge, OverrideAction, Count mode, forwarded IP, Bot Control, ATP, text transformation, WAF logging, WAF visibility, OWASP, SQLi, XSS, RFI.
waf-rule-deployer
Provisions AWS WAFv2 rule sets with production defaults: Web ACL creation (CloudFront scope in us-east-1 vs Regional scope), rule groups (managed vs custom) with capacity planning in WCU (Web ACL Capacity Units, 1500 default per ACL), managed rule groups (AWSManagedRulesCommonRuleSet, AWSManagedRulesSQLiRuleSet, AWSManagedRulesAmazonIpReputationList, AWSManagedRulesLinuxRuleSet, AWSManagedRulesWindowsRuleSet, AWSManagedRulesUnixRuleSet), custom rules (byte-match, regex pattern set, geo-match, rate-based), IP set and regex pattern set resources, rule priority ordering (lowest number evaluated first), action types (allow, block, count, CAPTCHA, Challenge), bot control managed rule group, account takeover. Triggers: create WAF rule, WAF managed rule group, WAF custom rule, WAF byte match, WAF geo match, WAF rate based rule, WAF IP set, WAF regex pattern set, WAF WCU budget, WAF CloudFront ACL, WAF logging Kinesis Firehose, WAF bot control, WAF ATP, WAF label matching, WAF Challenge action, WAF CAPTCHA.