Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new values for ECRAccessPolicy that include ecr:BatchImportUpstreamImage #1270

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions templates/aws-stack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ Parameters:
Default: ""

RootVolumeType:
Description: Type of root volume to use
Description: Type of root volume to use. If you are specifying `io1` or `io2`, you will most likely want to specify `RootVolumeIOPS` as well.
Type: String
Default: "gp3"

Expand Down Expand Up @@ -429,11 +429,13 @@ Parameters:

ECRAccessPolicy:
Type: String
Description: ECR access policy to give container instances
Description: ECR access policy to give instances. The `-pullthrough` variants add `ecr:CreateRepository` and `ecr:BatchImportUpstreamImage` which allows ECR pull through cache to work transparently.
AllowedValues:
- none
- readonly
- readonly-pullthrough
- poweruser
- poweruser-pullthrough
- full
Default: "none"

Expand Down Expand Up @@ -640,6 +642,11 @@ Conditions:
UseECR:
!Not [ !Equals [ !Ref ECRAccessPolicy, "none" ] ]

AddECRPullThrough:
!Or
- !Equals [ !Ref ECRAccessPolicy, "readonly-pullthrough" ]
- !Equals [ !Ref ECRAccessPolicy, "poweruser-pullthrough" ]

UseCustomerManagedParameterPath:
!Not [ !Equals [ !Ref BuildkiteAgentTokenParameterStorePath, "" ] ]
UseCustomerManagedKeyForParameterStore:
Expand Down Expand Up @@ -711,10 +718,12 @@ Conditions:

Mappings:
ECRManagedPolicy:
none : { Policy: '' }
readonly : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly' }
poweruser : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser' }
full : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess' }
none : { Policy: '' }
readonly : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly' }
readonly-pullthrough : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly' }
poweruser : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser' }
poweruser-pullthrough : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryPowerUser' }
full : { Policy: 'arn:aws:iam::aws:policy/AmazonEC2ContainerRegistryFullAccess' }

# Generated from Makefile via build/mappings.yml
AWSRegion2AMI: { linuxamd64: !Ref ImageId, linuxarm64: !Ref ImageId, windows: !Ref ImageId }
Expand Down Expand Up @@ -861,6 +870,17 @@ Resources:
- !Ref 'AWS::NoValue'
- !Ref 'AWS::NoValue'
Policies:
- !If
- AddECRPullThrough
- PolicyName: ECRPullThrough
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- ecr:CreateRepository
- ecr:BatchImportUpstreamImage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you may also want ecr:CreateRepository here. That permission is required for the first pull of a new image that's never been cached before. After that, ecr:BatchImportUpstreamImage is enough to pull new tags of the image into the repository.

Copy link
Contributor Author

@triarius triarius Dec 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh right, the docs state it as

Grants permission to create a repository in a private registry.

but the "repository" is just the part of the image w/o the tag.

- !Ref 'AWS::NoValue'
- !If
- UseCustomerManagedKeyForParameterStore
- PolicyName: DecryptAgentToken
Expand Down