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

kaniko issue with multiple AWS ECR registries using aws profiles #2628

Open
papillon88 opened this issue Jul 18, 2023 · 3 comments
Open

kaniko issue with multiple AWS ECR registries using aws profiles #2628

papillon88 opened this issue Jul 18, 2023 · 3 comments
Labels
area/authentication area/aws area/registry For all bugs having to do with pushing/pulling into registries kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy registry/ecr

Comments

@papillon88
Copy link

papillon88 commented Jul 18, 2023

Refernce link - https://wadehuang36.medium.com/use-aws-ecr-credential-helper-with-multiple-accounts-4c38b7ee37d

First create the kaniko image -
dockerfile to create a custom kaniko image from the upstream kaniko image

FROM gcr.io/kaniko-project/executor:debug AS kaniko

FROM our-custom-openjdk8-image-with-aws:latest

COPY --from=kaniko /kaniko/executor /kaniko/executor

COPY --from=kaniko /kaniko/docker-credential-ecr-login /kaniko/docker-credential-ecr-login

COPY --from=kaniko /kaniko/warmer /kaniko/warmer

COPY --from=kaniko /kaniko/ssl/certs/ca-certificates.crt /kaniko/ssl/certs/ca-certificates.crt

COPY --from=kaniko /kaniko/.docker /kaniko/.docker

ENV PATH $PATH:/usr/local/bin:/kaniko

ENV DOCKER_CONFIG /kaniko/.docker/

Now run the image and exec into it -
docker run -it --entrypoint=/busybox/sh my-custom-kaniko-image:latest

Now inside the container :
Now below is the config.json -
/kaniko/.docker/config.json file

{
    "credHelpers": {
        "1234.dkr.ecr.region.amazonaws.com": "ecr-login-1234",
        "5678.dkr.ecr.region.amazonaws.com": "ecr-login-5678"
    }
}

Below is the aws credential file -
~/.aws/credentials file

cat ~/.aws/credentials
[account1]
aws_access_key_id = ABCD
aws_secret_access_key = WXYZ
[account2]
aws_access_key_id = EFGH
aws_secret_access_key = PQRS

Now I created 2 shell scripts under /kaniko dir
script #1 - docker-credential-ecr-login-1234.sh

#contents
#!/bin/sh
export AWS_PROFILE=account1
docker-credential-ecr-login "$@"

script #2 - docker-credential-ecr-login-5678.sh

#contents
#!/bin/sh
export AWS_PROFILE=account2
docker-credential-ecr-login "$@"

I now run

/kaniko/executor --destination "1234.dkr.ecr.us-east-1.amazonaws.com/test-reporsitory:cbs-sample-springboot-ms-v1-0-0-929194337" --context "empty" --dockerfile "dockerfile" -v debug

The "context" is a directory that is empty.
The "dockerfile" is below -

FROM 1234.dkr.ecr.us-east-1.amazonaws.com/test-reporsitory:cbs-sample-springboot-ms-v1-0-0-929194337
RUN apk update
RUN apk update

I get below error

....
DEBU[0000] Checking file cache                           registry=834930510981
DEBU[0000] Calling ECR.GetAuthorizationToken             registry=834930510981
error checking push permissions -- make sure you entered the correct tag name, and that you are authenticated correctly, and try again: checking push permission for "834930510981.dkr.ecr.us-east-1.amazonaws.com/test-reporsitory:cbs-sample-springboot-ms-v1-0-0-929194337": POST https://834930510981.dkr.ecr.us-east-1.amazonaws.com/v2/test-reporsitory/blobs/uploads/: unexpected status code 401 Unauthorized: Not Authorized

Expected behavior is that I should not get Not authorized error and kaniko should be able to build and push this image.

@aaron-prindle aaron-prindle added area/aws registry/ecr area/authentication area/registry For all bugs having to do with pushing/pulling into registries kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy labels Jul 18, 2023
@papillon88
Copy link
Author

Hi, Any updates on this ?

@dev-whoan
Copy link

Hi, Any updates on this?

@Ankhas
Copy link

Ankhas commented Dec 12, 2023

Hi, I have successfully achieved to do this by setting AWS environment variables (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN) instead of using the file .aws/credentials with AWS_PROFILE.

For example, in your script 1 docker-credential-ecr-login-1234.sh:

#!/bin/sh
export AWS_ACCESS_KEY_ID=$aws_access_key_id
export AWS_SECRET_ACCESS_KEY=$aws_secret_access_key
export AWS_SESSION_TOKEN=$aws_session_token
docker-credential-ecr-login "$@"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/authentication area/aws area/registry For all bugs having to do with pushing/pulling into registries kind/bug Something isn't working priority/p2 High impact feature/bug. Will get a lot of users happy registry/ecr
Projects
None yet
Development

No branches or pull requests

4 participants