Day 13: Build Secrets with BuildKit
Goal: Pass tokens that only the build needs via
RUN --mount=type=secretand prove that they end up in no layer and no history. · Duration: approx. 75 min · Prerequisite: Day 12
Briefing
- A build secret exists only during a single
RUN: as a file under/run/secrets/<id>or, withenv=, as an environment variable. Afterwards it’s gone. - You pass it with
docker build --secret id=…,src=<file>or,env=<variable>. The Dockerfile only contains the ID, never the value. - Today the
artifact-serverplays your private artifact repository: it only delivers a file withAuthorization: Bearer lab-artifact-token-123. - Watch the cache: a changed secret value doesn’t rebuild anything (Drill 6).
docker build --secret id=artifact_token,env=ARTIFACT_TOKEN
│ value only in the build's memory
▼
RUN --mount=type=secret,…,env=ARTIFACT_TOKEN ── Bearer ──► notes-artifacts:8081
│ after the RUN: token gone, downloaded file stays
▼
Layer: /usr/share/notes/banner.txt (no token, no trace in the history)
Drill 1: The private artifact repository
source ~/docker-lab/setup/env.sh
mkdir -p ~/docker-lab/tag13 && cd ~/docker-lab/tag13
cp -R "$LAB/code/notes/." . && cp -R "$LAB/code/tag12/notes/." .The second copy lays the state from the end of Day 12 on top – even
if you skipped it. You keep secrets for the build in a folder of their
own that Git ignores. printf '%s' writes without a newline;
otherwise the token gets a trailing \n:
mkdir -p secrets
grep -qxF 'secrets/' .gitignore || echo 'secrets/' >> .gitignore
printf '%s' 'lab-artifact-token-123' > secrets/artifact_token.txt
wc -c secrets/artifact_token.txtExpected:
22 secrets/artifact_token.txt
Now build and start the artifact-server. It is in the
companion code, an http.server from the Python standard
library with its own small Dockerfile:
docker build -q -t notes-artifacts:tag13 "$LAB/code/tag13/artifact-server"
docker run -d --name notes-artifacts -p 127.0.0.1:8081:8081 \
-e ARTIFACT_TOKEN_FILE=/run/token -v "$PWD/secrets/artifact_token.txt:/run/token:ro" \
notes-artifacts:tag13
curl -s -o /dev/null -w '%{http_code}\n' localhost:8081/tools/notes-banner.txt
curl -s -H 'Authorization: Bearer lab-artifact-token-123' \
localhost:8081/tools/notes-banner.txtExpected (abbreviated, may vary by version):
sha256:3f0a…
4c1d…
401
notes – privates Artefakt vom artifact-server (Lab, Tag 13)
Without a token 401, with a token the file. That’s
exactly how a private npm, PyPI or Artifactory repository behaves. The
server logs path and status, never headers.
Save your progress? Sign up for free
Drill 2: Where is the secret during the build?
Before the token moves into notes-api, you watch a secret mount at work. The probe Dockerfile mounts the same secret in three ways and then checks what’s left:
cat "$LAB/code/tag13/probe/Dockerfile"Expected:
# syntax=docker/dockerfile:1
# probe – zeigt, wie ein Build-Secret im RUN ankommt und wieder verschwindet (Tag 13)
# in Produktion: @sha256:… pinnen, siehe Tag 8
FROM golang:1.27-alpine
# 1) Standard: Datei unter /run/secrets/<id>, root, 0400
RUN --mount=type=secret,id=artifact_token \
ls -ln /run/secrets
# 2) eigener Pfad, eigene Rechte
RUN --mount=type=secret,id=artifact_token,target=/tmp/token,mode=0440,uid=65532 \
ls -ln /tmp/token
# 3) nur als Umgebungsvariable (dann ohne Datei)
RUN --mount=type=secret,id=artifact_token,env=ARTIFACT_TOKEN \
echo "ARTIFACT_TOKEN hat ${#ARTIFACT_TOKEN} Zeichen" \
&& test ! -e /run/secrets/artifact_token && echo "keine Datei unter /run/secrets"
# 4) ohne Mount: nichts mehr da
RUN test ! -s /run/secrets/artifact_token && test ! -s /tmp/token \
&& echo "ohne Mount: kein Secret-Inhalt im Dateisystem"docker build --no-cache --progress=plain -t notes-probe:tag13 \
--secret id=artifact_token,src=secrets/artifact_token.txt \
"$LAB/code/tag13/probe" 2>&1 | grep -E '^#[0-9]+ [0-9.]+ 'Expected (abbreviated, may vary by version):
#5 0.112 total 4
#5 0.112 -r-------- 1 0 0 22 Oct 29 09:14 artifact_token
#6 0.098 -r--r----- 1 65532 0 22 Oct 29 09:14 /tmp/token
#7 0.087 ARTIFACT_TOKEN hat 22 Zeichen
#7 0.087 keine Datei unter /run/secrets
#8 0.071 ohne Mount: kein Secret-Inhalt im Dateisystem
The options come from the Dockerfile reference:
| Option | Default | Effect |
|---|---|---|
id |
base name of target |
name under which --secret supplies the value |
target |
/run/secrets/<id> (if env is also
missing) |
path of the file |
env |
– | value as an environment variable, with or without
target |
required |
false |
the build aborts if the secret is missing |
mode, uid, gid |
0400, 0, 0 |
permissions and owner of the file |
env= has existed since Dockerfile frontend 1.10. With
# syntax=docker/dockerfile:1 you have it. With
env= alone no file is created; if you want both, set
env and target together.
Save your progress? Sign up for free
Drill 3: notes-api downloads the artifact
notes-api gets a stage of its own, artifacts, that only
fetches the artifact. The token comes via env= into the
variable ARTIFACT_TOKEN, which only this one
RUN sees. The final stage copies only the file:
cat > notes-api/Dockerfile <<'EOF'
# syntax=docker/dockerfile:1
# check=error=true
# notes-api – state at the end of Day 13
ARG GO_VERSION=1.27
# in production: pin @sha256:…, see Day 8
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS base
WORKDIR /src
COPY go.mod go.sum ./
RUN --mount=type=cache,target=/go/pkg/mod go mod download
COPY . .
FROM base AS test
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
go vet ./... && go test ./...
# Day 13: download a private artifact with a build secret. The token only exists
# during this RUN as an environment variable – in no layer, in no history.
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine AS artifacts
ARG ARTIFACT_URL=http://127.0.0.1:8081
RUN --mount=type=secret,id=artifact_token,env=ARTIFACT_TOKEN,required=true \
wget -q --header "Authorization: Bearer ${ARTIFACT_TOKEN}" \
-O /notes-banner.txt "${ARTIFACT_URL}/tools/notes-banner.txt"
FROM base AS build
ARG TARGETOS TARGETARCH VERSION=dev
RUN --mount=type=cache,target=/go/pkg/mod \
--mount=type=cache,target=/root/.cache/go-build \
CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=$TARGETARCH \
go build -trimpath -ldflags="-s -w -X main.version=${VERSION}" \
-o /out/notes-api .
FROM scratch AS final
ARG VERSION=dev REVISION=unknown CREATED=unknown
LABEL org.opencontainers.image.title="notes-api" \
org.opencontainers.image.description="Notiz-API aus dem Trainingslager" \
org.opencontainers.image.source="https://example.com/docker-lab/notes" \
org.opencontainers.image.version="${VERSION}" \
org.opencontainers.image.revision="${REVISION}" \
org.opencontainers.image.created="${CREATED}"
COPY --link --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --link --from=artifacts /notes-banner.txt /usr/share/notes/banner.txt
COPY --link --from=build --chmod=555 /out/notes-api /notes-api
EXPOSE 8080
USER 65532:65532
HEALTHCHECK --interval=10s --timeout=2s --start-period=5s --start-interval=1s \
CMD ["/notes-api", "healthcheck"]
STOPSIGNAL SIGTERM
ENTRYPOINT ["/notes-api"]
EOF
hadolint notes-api/Dockerfile && docker build --check notes-apiExpected (abbreviated, may vary by version):
Check complete, no warnings found.
You build with the token from an environment variable.
--network=host is only needed for the lab: otherwise the
RUN steps run in their own network and can’t reach
127.0.0.1:8081.
export ARTIFACT_TOKEN="$(cat secrets/artifact_token.txt)"
docker build --network=host --secret id=artifact_token,env=ARTIFACT_TOKEN \
-t notes-api:tag13 notes-api
docker logs notes-artifacts | tail -1Expected (abbreviated, may vary by version):
[+] Building 14.2s (19/19) FINISHED docker:colima
=> [artifacts 2/2] RUN --mount=type=secret,id=artifact_token,env=ARTIFACT_T 0.4s
=> [build 1/1] RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cac 9.8s
=> [final 2/3] COPY --link --from=artifacts /notes-banner.txt /usr/share/ 0.0s
172.17.0.1 "GET /tools/notes-banner.txt HTTP/1.1" 200 -
Build times, sizes and digests will differ on your machine. The
artifacts stage doesn’t depend on base;
BuildKit builds it in parallel with the Go build.
Tip: If the build reports that the entitlement
network.hostis missing, add--allow network.host. In CI the artifact repository has a real hostname, and then--network=hostisn’t needed at all.
There are three ways to write --secret:
| Call | Source |
|---|---|
--secret id=artifact_token,src=secrets/artifact_token.txt |
file |
--secret id=artifact_token,env=ARTIFACT_TOKEN |
environment variable |
--secret id=artifact_token |
variable artifact_token, otherwise file
artifact_token |
According to the buildx reference, the short form first looks for an
environment variable named after the ID and otherwise falls back to a
file of the same name in the current folder. Spell out src=
or env=, then there are no surprises.
Save your progress? Sign up for free
Drill 4: required=true and the
wrong token
Without required=true, the RUN would simply
continue without the secret, and wget would get an empty
header. This way the build aborts immediately with a clear message:
docker build --network=host --no-cache-filter artifacts \
-t notes-api:tag13 notes-api 2>&1 | grep -i -m1 errorExpected (abbreviated, may vary by version):
ERROR: failed to solve: secret artifact_token: not found
And with a wrong token the server responds as it should:
ARTIFACT_TOKEN=lab-falsch-000 docker build --network=host \
--no-cache-filter artifacts --secret id=artifact_token,env=ARTIFACT_TOKEN \
-t notes-api:tag13 notes-api 2>&1 | grep -m1 'wget:'Expected (abbreviated, may vary by version):
#12 0.031 wget: server returned error: HTTP/1.0 401 Unauthorized
--no-cache-filter artifacts rebuilds only this stage.
Drill 6 shows why that’s needed here.
Save your progress? Sign up for free
Drill 5: Proof – no token in the image
Day 11 showed where a secret gets stuck: history, config, layers. You search the layers as in Day 11, Drill 8:
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-api:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-artifact-token-123
docker history --no-trunc --format '{{.CreatedBy}}' notes-api:tag13 | head -4Expected (abbreviated, may vary by version):
0
ENTRYPOINT ["/notes-api"]
STOPSIGNAL SIGTERM
HEALTHCHECK &{["CMD" "/notes-api" "healthcheck"] "10s" "2s" "5s" "1s" '\x00'}
USER 65532:65532
Zero matches in the layers, and the history shows no token. The
artifacts stage doesn’t appear in the history at all, only
its result via COPY --from. The artifact itself is in
there:
docker create --name notes-probe notes-api:tag13 >/dev/null
docker cp notes-probe:/usr/share/notes/banner.txt - | tar -xO
docker rm notes-probe >/dev/nullExpected:
notes – privates Artefakt vom artifact-server (Lab, Tag 13)
docker cp with - returns a tar archive;
that’s how you read files from scratch.
Security: A secret mount only protects the transport. If the
RUNwrites the token into a file, a log or a configuration in the image, it’s in there anyway. That’s exactly today’s challenge.
Save your progress? Sign up for free
Drill 6: The cache trap
Rotate the token on the server and rebuild with the old token:
docker rm -f notes-artifacts >/dev/null
printf '%s' 'lab-artifact-token-456' > secrets/artifact_token_neu.txt
docker run -d --name notes-artifacts -p 127.0.0.1:8081:8081 \
-e ARTIFACT_TOKEN_FILE=/run/token \
-v "$PWD/secrets/artifact_token_neu.txt:/run/token:ro" notes-artifacts:tag13
docker build --network=host --progress=plain \
--secret id=artifact_token,env=ARTIFACT_TOKEN -t notes-api:tag13 notes-api \
2>&1 | grep -A1 'artifacts 2/2'
docker logs notes-artifacts | grep -c GETExpected (abbreviated, may vary by version):
#10 [artifacts 2/2] RUN --mount=type=secret,id=artifact_token,env=ARTIFACT_TOKEN,r…
#10 CACHED
0
The build is green even though the token is no longer valid, and the server hasn’t seen a single request. The docs say so explicitly: the content of a build secret isn’t part of the cache key; a new value invalidates nothing. The ID and mount path, on the other hand, do count. You force a reload selectively:
docker build --network=host --no-cache-filter artifacts \
--secret id=artifact_token,src=secrets/artifact_token_neu.txt \
-t notes-api:tag13 notes-api >/dev/null
docker logs notes-artifacts | tail -1Expected (abbreviated, may vary by version):
172.17.0.1 "GET /tools/notes-banner.txt HTTP/1.1" 200 -
If the artifact behind a secret changes regularly, add an
ARG with a version or checksum to the stage: build
arguments invalidate the cache, secrets don’t. But the token itself
never belongs in an ARG (Day 11).
Save your progress? Sign up for free
Drill 7: .npmrc, uv index and SSH
Private npm registries expect their token in the .npmrc.
It belongs neither in the repository nor in the image via
COPY, but as a secret mount exactly at the path where npm
looks for it. The lab has no private registry; the lab
.npmrc only points the scope @notes-lab to a
host that notes-web doesn’t need, so npm ci keeps running
against the public registry:
cat > secrets/npmrc <<'EOF'
@notes-lab:registry=https://npm.lab.invalid/
//npm.lab.invalid/:_authToken=lab-npm-token-123
EOF
cp "$LAB/code/tag13/notes/notes-web/Dockerfile" notes-web/Dockerfile
grep -n -A2 'type=secret' notes-web/DockerfileExpected:
10: --mount=type=secret,id=npmrc,target=/root/.npmrc \
11- npm ci
12-COPY . .
--
20: --mount=type=secret,id=npmrc,target=/root/.npmrc \
21- npm ci --omit=dev
22-COPY server.js ./
Without required=true the secret is optional: if it’s
missing, notes-web builds as on Day 6.
docker build -q --secret id=npmrc,src=secrets/npmrc -t notes-web:tag13 notes-web
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-web:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-npm-token-123Expected (abbreviated, may vary by version):
sha256:a71e…
0
The same pattern for Python: uv reads the credentials of a named
index from UV_INDEX_<NAME>_USERNAME and
UV_INDEX_<NAME>_PASSWORD. For an index
intern in the pyproject.toml (static, not in
the lab):
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=secret,id=pypi_user,env=UV_INDEX_INTERN_USERNAME \
--mount=type=secret,id=pypi_token,env=UV_INDEX_INTERN_PASSWORD \
uv sync --locked --no-devYou fetch private Git repositories via the SSH agent instead of with
a key in the image. --mount=type=ssh only puts the agent
socket into the RUN (default ID default, path
/run/buildkit/ssh_agent.0); the key never leaves your
machine (static):
RUN apk add --no-cache git openssh-client \
&& mkdir -p -m 0700 /root/.ssh \
&& ssh-keyscan github.com >> /root/.ssh/known_hosts
RUN --mount=type=ssh,required=true \
git clone [email protected]:example/private-lib.git /src/private-libdocker build --ssh default -t notes-api:ssh notes-apiWarning:
ssh-keyscanin the build trusts the host on first contact. In production you check in the known fingerprints asknown_hosts.
Save your progress? Sign up for free
Drill 8: Build secrets with Compose
Compose passes build secrets on to BuildKit via
build.secrets. The top-level secrets: block
defines the source, from a file or an environment variable:
cp "$LAB/code/tag13/notes/compose.yaml" compose.yaml
sed -n '/^services:/,/^ notes-worker:/p;/^secrets:/,$p' compose.yamlExpected:
services:
notes-api:
build:
context: notes-api
network: host # Lab: artifact-server auf 127.0.0.1:8081
secrets:
- artifact_token # Tag 13: Build-Secret, landet in keinem Layer
image: notes-api:tag13
container_name: notes-api
env_file: .env
ports:
- "127.0.0.1:8080:8080"
notes-worker:
secrets:
artifact_token:
environment: ARTIFACT_TOKEN
npmrc:
file: ./secrets/npmrcCompose builds via docker buildx bake, and bake requires
an explicit --allow network.host for
network: host, which docker compose build
doesn’t pass on. That’s why --print outputs the build
definition and bake builds it. A top-level secret alone doesn’t give any
build access; each service only gets what is listed under its
build.secrets. The ID in the Dockerfile is the name of the
secret (long syntax: target). The server is still running
with the new token from Drill 6:
export ARTIFACT_TOKEN="$(cat secrets/artifact_token_neu.txt)"
docker compose build --print notes-api \
| docker buildx bake -f - --no-cache --allow network.host
docker compose config | sed -n '/^secrets:/,$p'Expected (abbreviated, may vary by version):
…
#11 [artifacts 2/2] RUN --mount=type=secret,id=artifact_token,env=ARTIFACT_TOKEN,r…
…
#17 naming to docker.io/library/notes-api:tag13 done
…
secrets:
artifact_token:
name: notes_artifact_token
environment: ARTIFACT_TOKEN
npmrc:
name: notes_npmrc
file: /Users/du/docker-lab/tag13/secrets/npmrc
docker compose config shows variable names and paths,
never the value. Compare with Day 12: there, the API key from
env_file appeared in plaintext in the same output.
Clean up (also removes notes-artifacts and
notes-probe:tag13):
docker ps -a --filter name=^notes- --format '{{.Names}}' | xargs -r docker rm -f
docker image ls --format '{{.Repository}}:{{.Tag}}' \
| grep -E '^(notes-|localhost:5001/)' | xargs -r docker rmi
docker buildx prune --builder docker-lab --all --forceSave your progress? Sign up for free
Checkpoint
Before checking, rebuild once, because the cleanup removed the images:
cd ~/docker-lab/tag13
docker build -q -t notes-artifacts:tag13 "$LAB/code/tag13/artifact-server" >/dev/null
docker run -d --name notes-artifacts -p 127.0.0.1:8081:8081 \
-e ARTIFACT_TOKEN_FILE=/run/token \
-v "$PWD/secrets/artifact_token.txt:/run/token:ro" notes-artifacts:tag13 >/dev/null
export ARTIFACT_TOKEN="$(cat secrets/artifact_token.txt)"
docker build -q --network=host --secret id=artifact_token,env=ARTIFACT_TOKEN \
-t notes-api:tag13 notes-api >/dev/null
docker build -q --secret id=npmrc,src=secrets/npmrc -t notes-web:tag13 \
notes-web >/dev/nullnotes-api fetches the artifact via a secret mount:
cd ~/docker-lab/tag13
grep -c 'type=secret,id=artifact_token' notes-api/DockerfileExpected:
1
No token in ARG or ENV:
grep -Ec '^(ARG|ENV) .*(TOKEN|KEY)' notes-api/Dockerfile notes-web/DockerfileExpected:
notes-api/Dockerfile:0
notes-web/Dockerfile:0
secrets/ is in .gitignore:
grep -x 'secrets/' .gitignoreExpected:
secrets/
The artifact is in the image:
docker create --name notes-probe notes-api:tag13 >/dev/null
docker cp notes-probe:/usr/share/notes/banner.txt - | tar -xO
docker rm notes-probeExpected:
notes – privates Artefakt vom artifact-server (Lab, Tag 13)
notes-probe
No token in notes-api and notes-web:
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-api:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-artifact-token-123
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-web:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-npm-token-123Expected:
0
0
Challenge
Under ~/docker-lab/code/tag13/falle/ there is a
Dockerfile that dutifully uses --mount=type=secret and
still gets the token into the image. Build it as
notes-falle:tag13, prove the leak in the layers and fix it
so that no match remains and the image still prints the banner.
Hint: An rm in a later RUN
only deletes from the topmost layer.
Solution
The server from the checkpoint is still running. First the leak:
cd ~/docker-lab/tag13
grep -n RUN "$LAB/code/tag13/falle/Dockerfile"
docker build -q --network=host \
--secret id=artifact_token,src=secrets/artifact_token.txt \
-t notes-falle:tag13 "$LAB/code/tag13/falle" >/dev/null
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-falle:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-artifact-token-123Expected:
8:RUN --mount=type=secret,id=artifact_token cp /run/secrets/artifact_token /app/.token
9:RUN TOKEN_FILE=/app/.token python3 fetch.py \
11:RUN rm /app/.token
1
The mount was clean, but cp wrote the content into a
layer of its own, and the rm two steps later only hides it.
The fix reads the secret directly in the only RUN that
needs it:
# syntax=docker/dockerfile:1
# Solution to the challenge (Day 13): secret only in the RUN that needs it, never copy it.
# in production: pin @sha256:…, see Day 8
FROM python:3.13-slim
WORKDIR /app
COPY fetch.py ./
RUN --mount=type=secret,id=artifact_token,required=true \
TOKEN_FILE=/run/secrets/artifact_token python3 fetch.py \
http://127.0.0.1:8081/tools/notes-banner.txt /app/banner.txt
USER 65532:65532
CMD ["cat", "/app/banner.txt"]docker build -q --network=host -f "$LAB/code/tag13/falle/Dockerfile.fix" \
--secret id=artifact_token,src=secrets/artifact_token.txt \
-t notes-falle:tag13 "$LAB/code/tag13/falle" >/dev/null
rm -rf /tmp/img && mkdir /tmp/img
docker save notes-falle:tag13 | tar -x -C /tmp/img
for l in /tmp/img/blobs/sha256/*; do tar -xOf "$l" 2>/dev/null; done \
| grep -ac lab-artifact-token-123
docker run --rm notes-falle:tag13
rm -rf /tmp/img
docker ps -a --filter name=^notes- --format '{{.Names}}' | xargs -r docker rm -f
docker image ls --format '{{.Repository}}:{{.Tag}}' \
| grep -E '^(notes-|localhost:5001/)' | xargs -r docker rmi
docker buildx prune --builder docker-lab --all --forceExpected (abbreviated, names, IDs and sizes differ):
0
notes – privates Artefakt vom artifact-server (Lab, Tag 13)
notes-artifacts
Untagged: notes-falle:tag13
Deleted: sha256:…
…
Total: …
Save your progress? Sign up for free
Enterprise Note
- In CI the token comes from the pipeline’s secret store (GitLab CI/CD
variables marked “masked”, GitHub Actions
secrets) and goes into the build via--secret id=…,env=…, never as--build-arg.docker/build-push-actionhas a dedicatedsecretsinput for this. - Short-lived tokens (job tokens, OIDC exchange) instead of long-lived service accounts. Then the cache trap from Drill 6 is also a feature: an expired token doesn’t disturb a cached build.
- Remote builders and a shared registry cache (Day 4) contain no
secret values, but the results of the
RUNs. Whatever aRUNdownloads with the token is readable by anyone allowed to read the cache. - For Go modules from private repositories:
GOPRIVATEplusGIT_AUTH_TOKENor--mount=type=ssh. The concept behind it, issuing and rotating secrets centrally, is covered in depth in “OpenBao secrets hands-on”. - Secret scans (Day 11) still run on every image. They catch exactly the mistake from the challenge.