Description
A policy that allows Principal: "*" on an AWS::ECR::Repository can grant access to unintended AWS principals. Signing in to the private registry requires ecr:GetAuthorizationToken in an IAM policy.
Potential impact
Read access can expose code and configuration in images. If a policy also permits uploads or deletion, deployment images can change or disappear.
Remediation
Limit Principal and Action to the identities and operations required. If you keep a wildcard, check what the Condition allows. Review explicit denies and the caller’s IAM policies for cross-account access, then test permitted and unapproved image requests.
Examples
Both excerpts use the same repository name but different logical IDs. Keep the existing logical ID for a policy-only stack update and review the change set.
Before
Resources:
MyRepository3:
Type: AWS::ECR::Repository
Properties:
RepositoryName: "test-repository"
RepositoryPolicyText:
Version: "2012-10-17"
Statement:
- Sid: AllowPushPull
Effect: Allow
Principal: "*"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
After
Resources:
MyRepository1:
Type: AWS::ECR::Repository
Properties:
RepositoryName: "test-repository"
RepositoryPolicyText:
Version: "2012-10-17"
Statement:
- Sid: AllowPushPull
Effect: Allow
Principal:
AWS:
- "arn:aws:iam::123456789012:user/Bob"
- "arn:aws:iam::123456789012:user/Alice"
Action:
- "ecr:GetDownloadUrlForLayer"
- "ecr:BatchGetImage"
- "ecr:BatchCheckLayerAvailability"
Despite the AllowPushPull label, the three listed actions read images. Replace the two example IAM user ARNs with the intended principals.