Skip to main content

More Info:

Restrict IAM user and role access to Amazon ECR to only what is required, using least-privilege IAM policies.

Risk Level

Medium

Address

Security

Compliance Standards

  • CIS EKS

Triage and Remediation

Remediation

Manual Steps

  1. Inventory who can access ECR
    • On any machine with AWS CLI configured for the account:
    • In the AWS Console: IAM → Access Analyzer → Analyze policies (optional) to see which principals have ECR access.
  2. Identify IAM policies that grant ECR permissions
    • List all policies that mention ecr: actions:
    • For each returned policy ARN, inspect details:
  3. Review scope for over-privilege
    • For each policy, check for:
      • Wildcard actions (e.g., "Action": "ecr:*").
      • Wildcard resources (e.g., "Resource": "*", or all repositories).
      • Principals that do not need ECR access (users/roles not tied to CI/CD or workloads that pull/push images).
    • Use console: IAM → Policies → (select policy) → JSON tab; verify actions and resources are narrowed to required repositories and operations.
  4. Redesign least-privilege policies based on actual need
    • Determine for each user/role what they must do:
      • Pull only (e.g., node roles, application pods): ecr:GetAuthorizationToken, ecr:BatchCheckLayerAvailability, ecr:GetDownloadUrlForLayer, ecr:BatchGetImage.
      • Push & pull (CI/CD): above plus ecr:PutImage, ecr:InitiateLayerUpload, ecr:UploadLayerPart, ecr:CompleteLayerUpload, ecr:ListImages.
    • Create a new scoped policy (example for one repository) with the console or CLI:
  5. Attach new scoped policies and remove broad ones
    • Attach the least-privilege policy to only those users/roles that require it:
    • Detach or delete overly broad policies (after verifying no dependency):
  6. Re-verify effective access to ECR
    • Re-run the policy search to ensure no remaining broad access:
    • Optionally, use IAM → Access Analyzer (AWS Console) to confirm there are no unintended principals with ECR permissions beyond what is required.
kubectl cannot be used to change IAM user or role permissions for Amazon ECR, because those are configured at the AWS account level via IAM (console, AWS CLI, or IaC such as CloudFormation/Terraform), not through Kubernetes API objects. Please refer to the Manual Steps section for guidance on reviewing and tightening ECR-related IAM access.