-2

How can I suppress the output of the RUN command in a Dockerfile? In the code below, I'm attempting to redirect the SSH_PRIVATE_KEY to a file using the echo command. However, during image building, the Docker logs reveal the SSH PRIVATE KEY, which I'd like to avoid. Is there a way to silence the RUN command in a Dockerfile, or is there another solution to this issue?

RUN echo "${SSH_PRIVATE_KEY}" > /home/$USER/.ssh/id_ed25519

Build log

 => CACHED [app 10/19] RUN echo "-----BEGIN OPENSSH PRIVATE KEY-----0s9               0.0s
2
  • Since anyone who gets a copy of the image can trivially extract files from it, your ssh key is already compromised if you do this. Make sure to properly revoke the key anywhere you might have used it. Do not pass credentials like this as Dockerfile ARG or otherwise supply them to the build process. Commented Jan 18, 2024 at 20:32
  • Try this RUN bash -c 'echo "${SSH_PRIVATE_KEY}" > /home/$USER/.ssh/id_ed25519' to see if it works. Commented Jan 18, 2024 at 21:43

1 Answer 1

2

A simple workaround is to have the key in a file instead in the first place.

COPY privkey /home/$USER/.ssh/id_ed_25519

with privkey obviously in a local file in the directory where you run docker build et al.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.