Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

ci: Replace docker build args with secret mounts #181

Merged
merged 1 commit into from
Sep 14, 2023

Conversation

konrad-ohms
Copy link
Contributor

While analyzing the docker build process, I noticed a potential risky transfer of secrets in the docker build process.

docker buildx build --no-cache \
  --build-arg DOWNLOAD_KEY="${DOWNLOAD_KEY}" \
  --platform="${TARGETPLATFORM}" \
  --build-arg "TARGETPLATFORM=${TARGETPLATFORM}" \
  -t containers.instana.io/instana/release/agent/static \
  .

The build-args of a docker build are persisted in the docker image history.
As of now, this is not a problem, as the mentioned image is using a multi-staged build and only the last image (parts after the last FROM statement) are persisted. But, if statements in the Dockerfile are rearranged or the DOWNLOAD_KEY variable is used somewhere in the last stage, it could be present in the docker image metadata and everyone could fetch them via checking the docker history output.

This was a common problem in lots of projects, but buildkit implemented a solution for that problem.
Instead of using build-args, buildkit offers dedicated secret mounts which we should incorporate instead.

https://github.com/moby/buildkit/blob/master/frontend/dockerfile/docs/reference.md#run---mounttypesecret

I propose to switch to the secret mounts to avoid potential risks going forward, it should be implemented in the concourse since v0.10.0 (concourse/oci-build-task#88).

@konrad-ohms konrad-ohms requested a review from a team as a code owner September 14, 2023 13:51
Copy link
Contributor

@FelixMarxIBM FelixMarxIBM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@konrad-ohms konrad-ohms merged commit e10998e into main Sep 14, 2023
@konrad-ohms konrad-ohms deleted the docker-build-secret-mounts branch September 14, 2023 14:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants