question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to push to cross-account AWS ECR registry

See original GitHub issue

Behaviour

Reference: https://github.com/davidski/test-docker/runs/1552032319?check_suite_focus=true

Pushes to AWS ECR work when the authenticating user is in the same AWS account as the repository, but do not work when the repository is in a different account (but the calling account has permissions).

I realize there is a containerd debug approach recommended, but I’m unsure how to apply that procedure to an AWS ECR location with its particular auth dance of AWS credentials for a docker login. If there’s guidance on how to do that, I’m happy to apply it and confirm where the problem lies.

Steps to reproduce this issue

  1. Setup a static user in ACCOUNT A with full permissions to ECR.
  2. Setup a repository in ACCOUNT B, giving ACCOUNT A full permissions at the account ID (root) level.
  3. Push process fails with a 401.

I have confirmed that using these static credentials (from ACCOUNT A) I can push to ACCOUNT B repos from a local Docker (MacOS) installation, verifying that permissions are correct.

Expected behaviour

Push should work, just as it does if the repository is in ACCOUNT A.

Actual behaviour

Push fails with a 401.

Configuration

name: Docker Image

on:
  push:
    branches:
      - master
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - name: Checkout
      uses: actions/checkout@v2
    - name: Docker meta
      id: docker_meta
      uses: crazy-max/ghaction-docker-meta@v1
      with:
        images: ${{ secrets.AWS_ECR_REPOSITORY }}/docker-image
        tag-sha: true
    - name: Set up QEMU
      uses: docker/setup-qemu-action@v1
    - name: Set up Docker Buildx
      uses: docker/setup-buildx-action@v1
      with:
        buildkitd-flages: --debug
                -
      name: Set up containerd
      uses: crazy-max/ghaction-setup-containerd@v1
    - name: Login to AWS Elastic Container Registry
      uses: docker/login-action@v1
      with:
        registry: ${{ secrets.AWS_ECR_REPOSITORY }}
        username: ${{ secrets.AWS_ACCESS_KEY_ID }}
        password: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
    - name: Build and push
      id: docker_build
      uses: docker/build-push-action@v2
      with:
        push: ${{ github.event_name != 'pull_request' }}
        tags: ${{ steps.docker_meta.outputs.tags }}
        labels: ${{ steps.docker_meta.outputs.labels }}
    - name: Dump context
      if: always()
      uses: crazy-max/ghaction-dump-context@v1

Logs

logs_2.zip

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
michaelb990commented, Dec 16, 2020

Hi @davidski!

It seems like this line is the issue in the docker/login-action command. get-login without a registry-id passed in will log you into the default registry for the user. So, if I’m reading this correctly, your action (when using aws-cli-v1) is logging into your default registry, in this case ACCOUNT A, instead of the registry that you’re trying to login to in ACCOUNT B.

We can look into the best way to fix the issue with the docker/login-action, but in the meantime, you may want to try using the amazon-ecr-login action which shouldn’t have this issue.

1reaction
jtoberoncommented, Dec 16, 2020

Just pinged the ECR team.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Allow secondary accounts to push or pull images in Amazon ...
I want to allow a secondary account to push or pull images in my Amazon Elastic Container Registry (Amazon ECR) image repository.
Read more >
Cross-Account Amazon Elastic Container Registry (ECR ...
Deploying containerized applications on Amazon ECS using cross-account elastic container registries. This is an updated version of a post, ...
Read more >
How can I allow a secondary account to push or pull images in ...
Amazon ECR Cross Region / Cross Account replication - Example uses # ... Private Repository explained | Registry on AWS - Docker in...
Read more >
Can't push image to Amazon ECR - fails with "no basic auth ...
So when I did aws ecr get-login it was returning a login for the wrong account. I failed to notice that the account...
Read more >
Problems with cross account ECR permission | AWS re:Post
When trying to interact with an ECR registry, we are running in to ... Problems with cross account ECR permission ... Unable to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found