Scan Docker images for vulnerabilities with AWS ECR
Amazon ECR is a fully managed container registry used to store, manage and deploy container images. ECR Image Scanning assesses and identifies operating system vulnerabilities. Using automated image scans you can ensure container image vulnerabilities are found before getting pushed to production.
AWS ECR uses Common Vulnerabilities and Exposures (CVEs) databases for findings. ECR APIs notify if vulnerabilities were found when a scan completes.
You can enable the scans on push
feature for your repositories to ensure every image automatically goes through a vulnerability scanning.
Step 1: Enable automatic scan for images
You need to ensure ECR image scan on push is enabled for your repository. You can enable the scan on push
feature via the AWS Console or CLI:
AWS Console
- Log in to the AWS Management Console.
- Open the Amazon ECR console.
- Select a repository using the radio button.
- Click Edit.
- Enable the Scan on push toggle.
CLI Command
We can use the PutImageScanningConfiguration
API to update the image scanning configuration for the specified repository:
How can you enable scan on push for all your AWS repositories?
We can use the CLI to execute a bash script (a plain text file which contains a series of commands) that enables scan on push for all repos. Create a enable_scan_on_push.sh file:
- Run
chmod u+x enable_scan_on_push.sh
to change the permissions on the file and make it executable. - Run
./enable_scan_on_push.sh
to execute the bash script from the current directory
Step 2: Gather information and view the results
We can automate getting image vulnerabilities with a simple bash script and the AWS CLI:
The TAGS variable describes the tags of images that should be scanned. In our example, only images with tags ‘latest’ and ‘other’ will be scanned.
Summary
After pushing your docker images to the cloud, you can see your scan results on the AWS console in detail. After you get results, you can fix vulnerabilities with security updates. An example report can be seen below: