user7898461
user7898461

Reputation:

How to add credentials to Docker ADD command

I have this:

ADD https://bitbucket.org/teros/vana/raw/"$commit"/mw/requirements.txt  'requirements.txt'

but the HTTP request won't work since I need creds. I do know that this curl command works:

bitbucket_curl(){
   curl -H 'Authorization:Basic YW1bGx..plM2JyKg==' "https://api.bitbucket.org$@"
}

(token was modified, but the command is o/w right)

So maybe there's a token I can included as a url parameter with Bitbucket?

Upvotes: 0

Views: 4748

Answers (2)

stackprotector
stackprotector

Reputation: 13452

Do neither use --build-arg with ARG/ENV nor COPY to pass secrets to your build. In both cases, the secrets can be exposed later. To not expose your secrets inside your image, you should use Docker build secrets instead. Example for curl:

Build command:

export CURL_CREDS="machine bitbucket.org login MY_USERNAME password MY_PASSWORD"
docker build --secret id=curl,env=CURL_CREDS .

Docker command in your dockerfile:

RUN --mount=type=secret,id=curl \
    curl -o /tmp/requirements.txt --netrc-file /run/secrets/curl https://bitbucket.org/teros/vana/raw/$commit/mw/requirements.txt

Upvotes: 0

user7898461
user7898461

Reputation:

Should just be as simple as:

ARG bitbucket_pwd
ARG commit

ADD "https://[email protected]:[email protected]/teros/vana/raw/$commit/mw/requirements.txt"  '/temp/requirements.txt'

you can pass the ARGs in using --build-arg

docker build --build-arg bitbucket_pwd="$bitbucket_password"

Upvotes: 3

Related Questions