Skip to main content

More Info:

ECR repository policies should not enable global or public access to images. ECR repository policies should limit access to images to known IAM entities and AWS accounts and avoid the use of account-level wildcards.

Risk Level

High

Address

Security

Compliance Standards

  • APRA CPS 234 (Australia)
  • AWS Startup Security Baseline
  • AWS Well Architected Framework
  • BSI C5 (Germany)
  • Brazil LGPD
  • CCPA / CPRA (California)
  • CIS Critical Security Controls v8
  • CMMC 2.0
  • CSA Cloud Controls Matrix v4
  • DPDPA
  • Digital Operational Resilience Act (EU)
  • Essential 8
  • HIPAA
  • HITRUST CSF
  • ISO/IEC 27017
  • ISO/IEC 27018
  • ISO/IEC 27701
  • KSA PDPL
  • MAS Technology Risk Management (Singapore)
  • MITRE ATT&CK (Cloud)
  • NIS2 Directive
  • NIST CSF
  • NIST SP 800-171
  • NYDFS 23 NYCRR 500
  • PCI
  • SOC2
  • SWIFT Customer Security Controls Framework
  • Sarbanes-Oxley IT General Controls
  • UK NCSC Cyber Assessment Framework

Triage and Remediation

Remediation

Using Console

Sure, here are the step-by-step instructions to remediate the misconfiguration of ECR repositories not being private in AWS:
  1. Login to your AWS console.
  2. Navigate to the Amazon Elastic Container Registry (ECR) service.
  3. Select the repository that you want to make private.
  4. Click on the “Permissions” tab.
  5. Under the “Repository policy” section, click on the “Edit” button.
  6. In the JSON editor, replace the existing policy with the following policy:
Note: Replace “AWS_ACCOUNT_ID” with your AWS account ID.
  1. Click on the “Save” button to save the policy.
  2. Verify that the repository is now private by checking the “Repository visibility” under the “Overview” tab.
That’s it! You have successfully remediated the misconfiguration of ECR repositories not being private in AWS.

To remediate the misconfiguration of ECR repositories being public, you can follow the below steps using AWS CLI:
  1. Open the AWS CLI and run the following command to list all ECR repositories in your account:
  2. For each repository that is public, run the following command to modify its permissions:
    Replace <repository-name> with the name of the repository that you want to make private.
  3. Verify that the repository is now private by running the following command:
    The output should include "repositoryPolicyText": "{\"Version\": \"2008-10-17\", \"Statement\": [{\"Sid\": \"DenyPublicPull\", \"Effect\": \"Deny\", \"Principal\": \"*\", \"Action\": [\"ecr:BatchGetImage\", \"ecr:GetDownloadUrlForLayer\", \"ecr:GetAuthorizationToken\", \"ecr:DescribeRepositories\", \"ecr:ListImages\"], \"Condition\": {\"Bool\": {\"aws:SecureTransport\": \"false\"}}}]}"
  4. Repeat the above steps for all ECR repositories that are public in your account.
By following these steps, you can remediate the misconfiguration of ECR repositories being public and make them private.
To remediate the misconfiguration “ECR Repositories Should Be Private” for AWS using python, you can follow these steps:
  1. Import the necessary AWS SDK and Boto3 library in your python code.
  1. Create a Boto3 ECR client object to interact with ECR.
  1. Get a list of all the ECR repositories in your AWS account using the describe_repositories method.
  1. For each repository, check if it is public or not using the describe_images method. If the repository is public, update its permissions to make it private using the set_repository_policy method.
  1. Once the permissions have been updated, print a message to confirm that the repositories have been made private.
This code will remediate the misconfiguration “ECR Repositories Should Be Private” for AWS using python.
Removing the aws_ecr_repository_policy resource does not replace the ECR repository itself; it only deletes the policy so access is governed solely by IAM permissions, matching aws ecr delete-repository-policy.After updating the code, terraform plan should show the aws_ecr_repository_policy resource for this repository with - (destroy) and no changes to aws_ecr_repository.

Additional Reading: