PIVTR-D
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

LogSearch for
CloudTrail, pushesImage pushes: PutImage with the tag and manifest, after InitiateLayerUpload, UploadLayerPart, CompleteLayerUpload and MountLayer. Record the principal, source IP and repository
CloudTrail, configurationChanges to tag mutability, policies, replication, caching and lifecycle: PutImageTagMutability, SetRepositoryPolicy, PutRegistryPolicy, PutReplicationConfiguration, CreatePullThroughCacheRule, PutLifecyclePolicy, BatchDeleteImage, and PolicyExecutionEvent for lifecycle expirations
CloudTrail, pullsPulls after the push, by principal and source IP: BatchGetImage and GetDownloadUrlForLayer. Node roles and task execution roles show which clusters pulled
ECR imagesThe 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 settingsReplication destinations: aws ecr describe-registry
Pull through cache rulesUpstream registries the registry caches from: aws ecr describe-pull-through-cache-rules
Lifecycle policyRules that expire images in a repository: aws ecr get-lifecycle-policy --repository-name <repo>
Running ECS tasksThe image digest of each running container: aws ecs describe-tasks --cluster <cluster> --tasks <task-arn> --query "tasks[].containers[].[name,imageDigest]"
Running EKS podsThe image digest of each running container: imageID in each pod's containerStatuses
Amazon Inspector enhanced scanningFindings 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
EventBridgePush 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
1Save 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
2Block 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
3Load 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"
4Lock tags: aws ecr put-image-tag-mutability --repository-name <repo> --image-tag-mutability IMMUTABLE
5Restore the known-good replication rules with aws ecr put-replication-configuration
6Remove an attacker pull through cache rule destructive: aws ecr delete-pull-through-cache-rule --ecr-repository-prefix <prefix>
7Remove an attacker lifecycle policy destructive: aws ecr delete-lifecycle-policy --repository-name <repo>
8Replace running ECS tasks so they pull the restored image: aws ecs update-service --cluster <cluster> --service <service> --force-new-deployment
9On EKS, set the image by digest: kubectl set image deployment/<name> <container>=<repo-uri>@<digest>
10Delete 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
1Contain the identity behind PutImage with the CI/CD and OIDC trust or IAM user access keys playbook
2Treat every host and pod that ran the digest as compromised, with the Amazon EKS or EC2 instance playbook
3Delete the tampered digest in every replication destination and cached repository as well
4Deploy by digest, restrict push to the pipeline role in the repository policy, and set repository creation templates to IMMUTABLE for replicated and cached repositories
5Turn on Inspector enhanced scanning for the registry, and send ECR Image Action push events to an alert
6Rebuild 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.

Adapts material from Dynamic Incident Response: A Framework for Security Teams by Joshua Wright, © 2026 The Escal Institute of Advanced Technologies, Inc. d/b/a SANS Institute, licensed under CC BY 4.0. Figures reproduced under that license. Changes were made. Not published by, endorsed by, or affiliated with the SANS Institute.