mirror of
https://github.com/dockersrc/go
synced 2026-08-09 02:01:12 -04:00
🔒 Stop baking GITHUB_TOKEN into image layer history 🔒
Build and Push / build (push) Failing after 5s
Build and Push / build (push) Failing after 5s
- Dockerfile: `ARG GITHUB_TOKEN=""` and the matching `ENV GITHUB_TOKEN=`
persisted whatever value was passed via `--build-arg` into the image's
layer history, visible via `docker history` regardless of whether the
value was ever actually used — flagged by BuildKit's own
SecretsUsedInArgOrEnv check ("2 warnings found" on every build).
GITHUB_TOKEN is only ever read at build time by
rootfs/root/docker/setup/05-custom.sh to raise the GitHub API rate limit
during tool downloads; it has no reason to touch a layer at all. Replaced
both with `RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN,
required=false` on the RUN step that executes 05-custom.sh — the value is
now only visible inside that one RUN's environment and is never written to
a layer. 05-custom.sh needed no change since it already just reads
`${GITHUB_TOKEN:-}`. Added `# syntax=docker/dockerfile:1` at the top since
the secret-mount `env=` option requires Dockerfile frontend 1.4+. Callers
now pass `--secret id=github_token,env=GITHUB_TOKEN` instead of
`--build-arg GITHUB_TOKEN=...`. Verified with
`docker buildx build --check` — "Check complete, no warnings found."
Found while investigating the SecretsUsedInArgOrEnv warnings surfaced
during the entrypoint.sh functional-test rebuilds.
This commit is contained in:
+7
-5
@@ -1,3 +1,4 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
# Docker image for go using the alpine template
|
||||
ARG IMAGE_NAME="go"
|
||||
ARG PHP_SERVER="go"
|
||||
@@ -58,9 +59,6 @@ FROM ${PULL_URL}:${DISTRO_VERSION} AS build
|
||||
ARG TZ
|
||||
ARG USER
|
||||
ARG LICENSE
|
||||
# Optional: pass --build-arg GITHUB_TOKEN=$(gh auth token) to raise the API rate
|
||||
# limit from 60 to 5000 req/hr — avoids 403s in parallel multi-platform builds.
|
||||
ARG GITHUB_TOKEN=""
|
||||
ARG TIMEZONE
|
||||
ARG LANGUAGE
|
||||
ARG IMAGE_NAME
|
||||
@@ -100,7 +98,6 @@ ENV GOTOOLCHAIN="auto"
|
||||
ENV GOFLAGS="-buildvcs=false"
|
||||
ENV GOTELEMETRY="off"
|
||||
ENV GOPROXY="https://proxy.golang.org,direct"
|
||||
ENV GITHUB_TOKEN="${GITHUB_TOKEN}"
|
||||
|
||||
USER ${USER}
|
||||
WORKDIR /root
|
||||
@@ -205,7 +202,12 @@ echo ""
|
||||
COPY --from=go-toolchain /usr/local/go/ /usr/local/go/
|
||||
COPY --from=go-tools /go/bin/ /usr/local/bin/
|
||||
|
||||
RUN echo "Running custom commands"; \
|
||||
# GITHUB_TOKEN is passed as a BuildKit secret, not ARG/ENV, so its value never
|
||||
# persists in image layers or is visible via `docker history` — pass with
|
||||
# `docker buildx build --secret id=github_token,env=GITHUB_TOKEN` (optional,
|
||||
# only raises the GitHub API rate limit from 60 to 5000 req/hr).
|
||||
RUN --mount=type=secret,id=github_token,env=GITHUB_TOKEN,required=false \
|
||||
echo "Running custom commands"; \
|
||||
if [ -f "/root/docker/setup/05-custom.sh" ];then echo "Running the custom script";/root/docker/setup/05-custom.sh||{ echo "Failed to execute /root/docker/setup/05-custom.sh" && exit 10; };echo "Done running the custom script";fi; \
|
||||
echo ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user