As it stands aws-ecr-push-image only supports either Access Keys or OIDC. OIDC is overkill for our scenarios and Access Keys are limited and insecure, even if encrypted, plus you have to support multiple keys for multiple scenarios. Instead please add support for either of the following.
1.-The ability to specify an Account ID to log in against its docker registry in ECR, right now the code simply picks it up from the Access Keys and there's no way to change that. This was already requested here, and the developer dropped from the community since April 2020.
Solved: AWS ECR Push Image Specify Registry ID (atlassian.com)
About Alexander Zhukov - Atlassian Community
2.-The ability to specify standard AWS STS Assume Role for cross account access. If you already have OIDC support which is way too complex for a simple AWS IAM operation you can add STS Assume Role as well. As a matter of fact you can see how the underlying boto SDK is skipping over that sts:assumeRole API call in the current pipe's logs.
Why this request?
Because you can have a bitbucket runner in an account not accessible to your users but you still want to push images over to an account that they do have access to so they can have visibility for things like Scan Results, etc. Option 1 can be matched by a Resource Policy in the ECR repository while Option 2 allows to log into the actual AWS account where the repo lives.
Also, it would be nice to have a Jira ticket to track this issue for us customers to see its progress and to know it was actually picked up.
Hi all,
I ran into the same issue — the official atlassian/aws-ecr-push-image pipe doesn't support pushing Docker images to an ECR registry in a different AWS account. When using OIDC authentication, there's no way to specify a target account, so the pipe always pushes to the registry of the account you're authenticated with.
I've forked the pipe and added an AWS_ACCOUNT_ID parameter that enables cross-account ECR push. The forked image is publicly available on Docker Hub:
docker://jotytgat/aws-ecr-push-image:cross-account
What was changed
The only meaningful change is that when AWS_ACCOUNT_ID is provided, the pipe calls get_authorization_token(registryIds=[AWS_ACCOUNT_ID]) instead of get_authorization_token(). This retrieves the auth token for the target account's ECR registry rather than the one you're authenticated with. When AWS_ACCOUNT_ID is not set, the pipe behaves identically to the official version.
- step:
oidc: true
script:
- docker build -t my-app .
- pipe: docker://jotytgat/aws-ecr-push-image:cross-account
variables:
AWS_DEFAULT_REGION: 'eu-west-1'
AWS_OIDC_ROLE_ARN: 'arn:aws:iam::111111111111:role/my-oidc-role'
AWS_ACCOUNT_ID: '999999999999'
IMAGE_NAME: my-app
TAGS: 'latest $BITBUCKET_COMMIT'
Replace 111111111111 with the account where your OIDC role lives, and 999999999999 with the target account that owns the ECR repository.
Prerequisites
Your OIDC role needs the following permissions on the target account's ECR repository:
Source
The fork is based on the official pipe at aws-ecr-push-image (v2.6.0). I've submitted the change to Atlassian for inclusion in the official pipe, but in the meantime this Docker Hub image is available for anyone who needs cross-account support.
Hope this helps!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.