Sub topic 3
Scanning Images for Vulnerabilities
Assume you can build Docker images, use the AWS CLI, and understand IAM roles. ECR scanning checks image layers against vulnerability databases. Basic scanning uses a CVE database and can scan on push or when requested. Enhanced scanning uses Amazon Inspector and supports continuous rescanning as new vulnerabilities are disclosed.
Review findings in the ECR console or with the AWS CLI. Prioritize exploitable findings in production images, then rebuild from a current base image. Scanning does not make an image safe by itself. It reports known issues in the exact image contents.
Cleaning Up with Lifecycle Policies
Lifecycle policies remove images that no longer need to remain in a repository. A common rule expires untagged images after a retention period. Test rules with a preview before applying them, and keep production tags separate from temporary build tags.
{
"rules": [
{
"rulePriority": 1,
"description": "Expire untagged images after 14 days",
"selection": {
"tagStatus": "untagged",
"countType": "sinceImagePushed",
"countUnit": "days",
"countNumber": 14
},
"action": {
"type": "expire"
}
}
]
}Encryption at Rest
ECR encrypts stored image data by default with AES-256. You can instead use a customer managed AWS KMS key when you need control over key rotation, grants, or audit events. The IAM principals and ECR service must be allowed to use that key.
Replication Across Regions and Accounts
ECR replication copies images to repositories in other AWS Regions or accounts. It reduces pull latency and provides a regional recovery path. Configure replication rules at the registry level. Cross-account replication also requires permission in the destination registry. Replication copies image manifests and layers, but it does not replace deployment authorization.
Pull-Through Cache
A pull-through cache rule maps a local ECR namespace to an upstream registry such as Docker Hub. The first request downloads the image into ECR. Later requests use the cached copy. Configure credentials for private upstream registries and review cache freshness before relying on an image version.
ECS and EKS Pull Permissions
ECS uses the task execution role to obtain an ECR token and download layers. EKS nodes usually use the node role, while pod identity mechanisms can provide more targeted permissions. Pull access commonly includes ecr:GetAuthorizationToken, ecr:BatchGetImage, and ecr:GetDownloadUrlForLayer.
Exercise
Why should a production deployment prefer an image digest over a mutable tag?
Show answer
A digest identifies immutable image content, so every deployment pulls the same image even if a tag is later changed.