# Pass Docker build credentials through dedicated secret mounts

> Build arguments and environment variables can leave credentials in the resulting image.

- Canonical URL: https://update.dsesecurity.com/updates/pass-docker-build-credentials-through-dedicated-secret-mounts/
- Publisher: Detection Systems & Engineering (DSE Security)
- Author: DSE Security Editorial Team
- Published: 2026-10-20T18:15:19+00:00
- Modified: 2026-10-20T18:34:33+00:00
- Last reviewed by DSE: 2026-10-20
- Resource type: Guide
- DSE priority: Information
- Topics: IT, Networks & Infrastructure
- Reading time: 2 minutes

## What you need to know

Build arguments and environment variables can leave credentials in the resulting image.

## Potentially affected

Review credentials consumed during image build through Docker's secret or SSH mount workflow.

## DSE recommendation

DSE recommends inventorying private package, repository, and signing access used by the build.

## Article

Build arguments and environment variables can leave credentials in the resulting image.

## Source facts

Docker documents build arguments and environment variables as inappropriate ways to pass build secrets because they persist in the image. Secret mounts or SSH mounts are the supported alternatives. The workflow has two parts: pass the secret to the build command, then consume it in the Dockerfile. A secret mount is temporarily available for the relevant build instruction.

Source: [Docker documentation — Build secrets](https://docs.docker.com/build/building/secrets/).

## Applicability

Review credentials consumed during image build through Docker’s secret or SSH mount workflow.

## DSE recommendation

DSE recommends inventorying private package, repository, and signing access used by the build. Replace embedded credentials with the supported mount mechanism and keep secret values out of Dockerfile arguments, logs, and diagnostic traces. Review the build instruction to ensure it does not write the credential into an artifact that is later copied into the final image. Assign rotation and access ownership to the build identity. Separate the credential’s lifecycle from the generated image’s deployment lifecycle.

## Verification

In an isolated build using a disposable credential, inspect the final image’s intended files and relevant metadata without printing secret values. Confirm the build succeeds only through its approved secret input and that the credential is unavailable to ordinary runtime processes. Revoke the disposable credential after verification. Retain the reviewed instruction and a sanitized inventory of the final artifact. Have the build owner identify any intermediate output that could copy sensitive material, and verify its disposition before accepting the credential-handling change.

## Official reference

[Docker documentation — Build secrets](https://docs.docker.com/build/building/secrets/). Reviewed October 20, 2026.

## Primary reference

- Name: Docker documentation — Build secrets
- Authority: docs.docker.com
- URL: https://docs.docker.com/build/building/secrets/
- Source publication date: Not stated by the source

## Citation and use

Preferred citation: “Pass Docker build credentials through dedicated secret mounts,” DSE Security, https://update.dsesecurity.com/updates/pass-docker-build-credentials-through-dedicated-secret-mounts/
Publishing principles: https://update.dsesecurity.com/updates/dse-updates-editorial-methodology/
Usage and citation policy: https://update.dsesecurity.com/usage/
Copyright © 2026 Detection Systems & Engineering. All rights reserved.
