Skip to content

Commit 196fbfc

Browse files
l2yshoclaude
andcommitted
fix: leave GITHUB_TOKEN unset when the secret is absent
Review feedback from vladfrangu on #309. `GITHUB_TOKEN="$(cat ... 2>/dev/null || true)"` always set the variable, exporting an empty string to `camoufox fetch` when no secret was mounted. Both consumers treat "" as absent today (camoufox-js 0.12.0 `pkgman.js:24`, camoufox 0.5.6 `pkgman.py:467` both test truthiness), so nothing was broken, but the behaviour depended on that check. Read the secret only when it is readable, so an absent or unreadable file leaves the variable unset. `-r` rather than `-e` also covers the non-root node stage losing `mode=0444`, which previously degraded to an empty token instead of no token. Assignment and export are split to keep shellcheck SC2155 quiet. Also trims the comment blocks in both Dockerfiles. Verified in buildkit on a non-root stage: no secret -> unset; secret mounted -> token present; `mode=0444` removed -> unset, not empty. hadolint matches baseline on both files, zero new findings. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 5d99792 commit 196fbfc

2 files changed

Lines changed: 14 additions & 11 deletions

File tree

node-playwright-camoufox/Dockerfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,17 @@ RUN if [ "$SLIM" = "1" ]; then mv package.slim.json package.json; else rm packag
136136

137137
# Install default dependencies, print versions of everything
138138
#
139-
# `camoufox-js fetch` reads api.github.com, where the whole matrix shares one 60/hour budget.
140-
# GITHUB_TOKEN lifts it to 1000/hour; a secret, not a build arg, keeps it out of the layers.
141-
# mode=0444 because this stage runs as myuser and secrets default to root-owned 0400.
142-
# Without it the build stays unauthenticated and still works.
139+
# GITHUB_TOKEN raises the api.github.com rate limit for `camoufox-js fetch`. A secret, not a build
140+
# arg, keeps it out of the layers; mode=0444 because this stage runs as myuser. Optional.
143141
RUN --mount=type=secret,id=github_token,mode=0444 \
144142
npm --quiet set progress=false \
145143
\
146144
# Install Camoufox browser
147-
&& GITHUB_TOKEN="$(cat /run/secrets/github_token 2>/dev/null || true)" \
148-
PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0 npx camoufox-js fetch \
145+
&& if [ -r /run/secrets/github_token ]; then \
146+
GITHUB_TOKEN="$(cat /run/secrets/github_token)"; \
147+
export GITHUB_TOKEN; \
148+
fi \
149+
&& PLAYWRIGHT_SKIP_BROWSER_DOWNLOAD=0 npx camoufox-js fetch \
149150
# Overrides the dynamic library used by Firefox to determine trusted root certificates with p11-kit-trust.so, which loads the system certificates.
150151
&& rm -f /home/myuser/.cache/camoufox/libnssckbi.so \
151152
&& ln -s $(ls -d /usr/lib/*-linux-gnu)/pkcs11/p11-kit-trust.so /home/myuser/.cache/camoufox/libnssckbi.so \

python-playwright-camoufox/Dockerfile

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,8 @@ ENV PATH="/root/.local/bin:/home/myuser/.local/bin:$PATH"
104104
# - Installs the specified version of Playwright and Camoufox
105105
# - Fetches the Camoufox browser
106106
#
107-
# `camoufox fetch` reads api.github.com, where the whole matrix shares one 60/hour budget.
108-
# GITHUB_TOKEN lifts it to 1000/hour; a secret, not a build arg, keeps it out of the layers.
109-
# Without it the build stays unauthenticated and still works.
107+
# GITHUB_TOKEN raises the api.github.com rate limit for `camoufox fetch`. A secret, not a build
108+
# arg, keeps it out of the layers. Optional.
110109
RUN --mount=type=secret,id=github_token \
111110
python -m pip install --upgrade \
112111
pip \
@@ -115,8 +114,11 @@ RUN --mount=type=secret,id=github_token \
115114
playwright~=${PLAYWRIGHT_VERSION} \
116115
camoufox[geoip]~=${CAMOUFOX_VERSION} \
117116
# Fetch the Camoufox browser
118-
&& GITHUB_TOKEN="$(cat /run/secrets/github_token 2>/dev/null || true)" \
119-
python -m camoufox fetch \
117+
&& if [ -r /run/secrets/github_token ]; then \
118+
GITHUB_TOKEN="$(cat /run/secrets/github_token)"; \
119+
export GITHUB_TOKEN; \
120+
fi \
121+
&& python -m camoufox fetch \
120122
# `camoufox fetch` swallows sync errors and exits 0, so check what the runtime checks
121123
# rather than ship an image that only fails at launch.
122124
&& python -c "from camoufox.pkgman import installed_verstr; print('Camoufox installed:', installed_verstr())" \

0 commit comments

Comments
 (0)