Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
628 views
in Technique[技术] by (71.8m points)

amazon web services - Using different aws credentials in Bitbucket pipeline

I've a bitbucket pipeline that must have multiple aws credentials for different duties.

In the first lines, I have custom ECR image. To pull it, I created an AWS user for only ECR read only permissions. access-key and secret-key parameters are the keys of that user.

And in this ECR image, I embedded another AWS user's credentials to do the rest of the work (image push etc). But somehow, the credentials that I used for pulling base image running in steps too. Because of this situation, image push is being denied.

I tried to use export AWS_PROFILE=deployment but it doesn't help.

Is the credentials for base image pull being applied pipeline-wide?

And how can I overcome with this situation?

Thank you.

image: 
name: <ECR Image>
  aws:  
    access-key: $AWS_ACCESS_KEY_ID 
    secret-key: $AWS_SECRET_ACCESS_KEY

pipelines:   
  - step: 
      name: "Image Build & Push" 
      services: 
        -docker 
        script: 
         - export AWS_PROFILE=deployment
         - export ENVIRONMENT=beta 
         - echo "Environment is ${ENVIRONMENT}" 
         - export DOCKER_IMAGE_BUILDER="${BITBUCKET_REPO_SLUG}:builder" 
         - make clean 
         - make build BUILD_VER=${BITBUCKET_TAG}.${BITBUCKET_BUILD_NUMBER}   APP_NAME=${BITBUCKET_REPO_SLUG}  
    DOCKER_IMAGE_BUILDER=${DOCKER_IMAGE_BUILDER} 
         - make test
         - docker tag ....
         - docker push .....

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What I would do here instead of baking credentials inside the images:

Use one credential for pulling/pushing/taggin the image, why not use the same for pushing the image.

If that is something you don't wanna do:

Create an IAM role and give that permission to tag/push the images and assume this role from the earlier credentials being exported, No need to bake credentials in the images.

I found the following example in the documentation

    script:

    # build the image
    - docker build -t my-docker-image .

    # use the pipe to push to AWS ECR
    - pipe: atlassian/aws-ecr-push-image:1.2.2
        variables:
        AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
        AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
        AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
        IMAGE_NAME: my-docker-image
        TAGS: '${BITBUCKET_TAG} latest'G

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...