Add buildSecrets config for passing secrets to image builds#486
Merged
Conversation
Contributor
Author
|
CI is a flaky failure, this should be good to go. |
bschwedler
reviewed
Apr 24, 2026
6ea6ae7 to
7f512ed
Compare
Introduces an Image.buildSecrets list of {id, envVar} entries that are
translated into --secret options for both sequential docker builds and
bake plans. Missing envVars are skipped with a warning, deferring any
required-secret enforcement to Docker via the Containerfile mount.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers the BuildSecret model, Image.buildSecrets parsing, env resolution into `--secret` options (including the unset-envVar warning path), and that resolved secrets flow through to both docker.build's `secrets` kwarg and the bake target's `secret` field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds pattern validators so BuildSecret rejects values containing CLI metacharacters (commas, equals, whitespace, shell specials) that could otherwise inject extra `--secret` sub-options like `src=/etc/passwd`. The id pattern allows alphanumerics, underscores, dots, and hyphens (disallowing leading `-`/`.`); envVar enforces POSIX env-var naming. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
7f512ed to
0d05011
Compare
Pulls the env-var resolution + warning logic into a single ImageTarget.resolved_build_secrets property, and adds BuildSecret.as_bake_json() to mirror as_cli_option(). Each build path now just maps the resolved secrets through the matching formatter, keeping bake.py free of os/logging concerns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2 tasks
Add an optional build secret (`github_token`) to the `RUN` step that installs TinyTeX, and export it as `GH_TOKEN` when present. Quarto's TinyTeX installer uses this token to avoid GitHub API rate limits when resolving release metadata. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Move the --mount=type=secret,id=github_token,required=false flag into a dedicated macro so the mount option can be referenced consistently and documented alongside the shell-side read in install_tinytex_command. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Align the expected Containerfile in test_patch_version_with_dependencies_macros with the new github_token secret mount and GH_TOKEN export emitted by the Quarto install macro. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Replace the shell `if [ -s ... ]; then export GH_TOKEN=...; fi` block with an inline `GH_TOKEN="$([ -s ... ] && cat ...)"` prefix on the `quarto install tinytex` command so the variable is scoped to that one process and not exported into the surrounding shell. When the secret is not mounted the substitution yields an empty string, which Quarto treats the same as an unset token. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Introduces an Image.buildSecrets list of {id, envVar} entries that are
translated into --secret options for both sequential docker builds and
bake plans. Missing envVars are skipped with a warning, deferring any
required-secret enforcement to Docker via the Containerfile mount.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Covers the BuildSecret model, Image.buildSecrets parsing, env resolution into `--secret` options (including the unset-envVar warning path), and that resolved secrets flow through to both docker.build's `secrets` kwarg and the bake target's `secret` field. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds pattern validators so BuildSecret rejects values containing CLI metacharacters (commas, equals, whitespace, shell specials) that could otherwise inject extra `--secret` sub-options like `src=/etc/passwd`. The id pattern allows alphanumerics, underscores, dots, and hyphens (disallowing leading `-`/`.`); envVar enforces POSIX env-var naming. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Pulls the env-var resolution + warning logic into a single ImageTarget.resolved_build_secrets property, and adds BuildSecret.as_bake_json() to mirror as_cli_option(). Each build path now just maps the resolved secrets through the matching formatter, keeping bake.py free of os/logging concerns. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
721c8c6 to
f480e7a
Compare
…ecret Mount GitHub token secret for Quarto TinyTeX install
bschwedler
approved these changes
Apr 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Image.buildSecrets— a list of{id, envVar}entries — that is translated into--secret id=<id>,env=<envVar>options for sequentialdocker buildx buildand into{type: env, id, env}per-target entries for Docker Bake plans.BuildSecret.idandBuildSecret.envVarare pattern-validated to safe character sets (alphanumerics +_/./-for ids; POSIX env-var names for envVar) to prevent CLI argument injection likeid=foo,src=/etc/passwd.ImageTarget.resolved_build_secretsproperty; sequential and bake paths callas_cli_option()/as_bake_json()on the resolved entries.envVaris unset are skipped with a warning; required-secret enforcement stays with Docker viaRUN --mount=type=secret,id=<id>[,required=true]in the Containerfile.GITHUB_TOKENintoquarto install tinytex(and similar) to avoid unauthenticated GitHub API rate limiting.Example config
Containerfile usage:
Test plan
🤖 Generated with Claude Code