RAWS playbook · Pipelines and supply chain
Container image tampering in ECR
The attacker pushes a modified image to an ECR repository, often under an existing mutable tag such as latest or a release tag, so the next deployment or scale-out runs it. A typical run uses a stolen pipeline credential, then adds a replication rule, pull through cache rule or lifecycle policy to spread the image or remove the clean one. Block pushes and save both digests first, then point the tag back at the known-good image.
Look here
| Log | Search for |
|---|---|
| CloudTrail, pushes | Image pushes: PutImage with the tag and manifest, after InitiateLayerUpload, UploadLayerPart, CompleteLayerUpload and MountLayer. Record the principal, source IP and repository |
| CloudTrail, configuration | Changes to tag mutability, policies, replication, caching and lifecycle: PutImageTagMutability, SetRepositoryPolicy, PutRegistryPolicy, PutReplicationConfiguration, CreatePullThroughCacheRule, PutLifecyclePolicy, BatchDeleteImage, and PolicyExecutionEvent for lifecycle expirations |
| CloudTrail, pulls | Pulls after the push, by principal and source IP: BatchGetImage and GetDownloadUrlForLayer. Node roles and task execution roles show which clusters pulled |
| ECR images | The digest each tag points to and when it moved: aws ecr describe-images --repository-name <repo> --query "sort_by(imageDetails,&imagePushedAt)[].[imageDigest,imageTags,imagePushedAt]" |
| ECR registry settings | Replication destinations: aws ecr describe-registry |
| Pull through cache rules | Upstream registries the registry caches from: aws ecr describe-pull-through-cache-rules |
| Lifecycle policy | Rules that expire images in a repository: aws ecr get-lifecycle-policy --repository-name <repo> |
| Running ECS tasks | The image digest of each running container: aws ecs describe-tasks --cluster <cluster> --tasks <task-arn> --query "tasks[].containers[].[name,imageDigest]" |
| Running EKS pods | The image digest of each running container: imageID in each pod's containerStatuses |
| Amazon Inspector enhanced scanning | Findings for the digest and where it runs: ecrImageInUseCount and ecrImageLastInUseAt for ECS and EKS use. In-use data can lag up to 36 hours for a new image |
| EventBridge | Push and delete events, if a rule was already sending them to a target: ECR Image Action events with action-type, PUSH or DELETE. Delivery is best effort |
Contain
| # | Item |
|---|---|
| 1 | Save the manifests of the tampered digest and the last known-good digest, as in Evidence: aws ecr batch-get-image --repository-name <repo> --image-ids imageDigest=<digest> --query 'images[].imageManifest' --output text |
| 2 | Block pushes by all but the responder role. The repository policy denies ecr:PutImage, ecr:InitiateLayerUpload, ecr:UploadLayerPart and ecr:CompleteLayerUpload: aws ecr set-repository-policy --repository-name <repo> --policy-text file://deny-push.json |
| 3 | Load the known-good manifest into MANIFEST with the item 1 command, then point the tag back at it: aws ecr put-image --repository-name <repo> --image-tag <tag> --image-manifest "$MANIFEST" |
| 4 | Lock tags: aws ecr put-image-tag-mutability --repository-name <repo> --image-tag-mutability IMMUTABLE |
| 5 | Restore the known-good replication rules with aws ecr put-replication-configuration |
| 6 | Remove an attacker pull through cache rule destructive: aws ecr delete-pull-through-cache-rule --ecr-repository-prefix <prefix> |
| 7 | Remove an attacker lifecycle policy destructive: aws ecr delete-lifecycle-policy --repository-name <repo> |
| 8 | Replace running ECS tasks so they pull the restored image: aws ecs update-service --cluster <cluster> --service <service> --force-new-deployment |
| 9 | On EKS, set the image by digest: kubectl set image deployment/<name> <container>=<repo-uri>@<digest> |
| 10 | Delete the tampered image after the evidence is saved destructive: aws ecr batch-delete-image --repository-name <repo> --image-ids imageDigest=<digest> |
Eradicate and recover
| # | Item |
|---|---|
| 1 | Contain the identity behind PutImage with the CI/CD and OIDC trust or IAM user access keys playbook |
| 2 | Treat every host and pod that ran the digest as compromised, with the Amazon EKS or EC2 instance playbook |
| 3 | Delete the tampered digest in every replication destination and cached repository as well |
| 4 | Deploy by digest, restrict push to the pipeline role in the repository policy, and set repository creation templates to IMMUTABLE for replicated and cached repositories |
| 5 | Turn on Inspector enhanced scanning for the registry, and send ECR Image Action push events to an alert |
| 6 | Rebuild images from a known-good commit and base image, and see Supply chain |
Watch out
- ECS resolves a tag to a digest when a service deployment starts and uses that digest for later tasks. A moved tag reaches an ECS service at its next deployment, and your fix reaches it only after
--force-new-deployment. - Replication copies content pushed after the rule exists and never deletes. A tampered image stays in every destination registry until you delete it there.
- A pull through cache rule checks the upstream registry at least once every 24 hours. A poisoned upstream tag arrives on the first pull after that check.
AWS documentation: ECR CloudTrail logging, image tag mutability, retagging an image, EventBridge events, pull through cache, private image replication; Amazon Inspector ECR scanning and image in-use data; ECS Container API and service deployments with image digest resolution. Checked September 2026.