Repository navigation
ci(workflows): fix security gaps - #226
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Nested shell expansion remains injectable, and Terraform permissions are assigned to the wrong token.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Hardens GitHub Actions workflows against token leakage, injection, permission gaps, and telemetry.
Changes:
- Masks workflow and GitHub App tokens.
- Revises pre-commit environment and ref handling.
- Adjusts automation permissions, authentication, and telemetry.
File summaries
| File | Description |
|---|---|
.github/workflows/check-nix-flake.yml |
Masks tokens and disables telemetry. |
.github/workflows/format-with-treefmt.yaml |
Masks tokens before use. |
.github/workflows/run-pre-commit-via-determinate.yaml |
Revises environment and ref handling. |
.github/workflows/run-pre-commit-via-nix.yaml |
Revises environment and ref handling. |
.github/workflows/show-nix-information.yaml |
Masks the token earlier. |
.github/workflows/update-flake-lock.yml |
Masks automation tokens. |
.github/workflows/update-nix-flake-lock.yml |
Uses and masks the App token. |
.github/workflows/update-terraform-binary-version.yaml |
Adds authentication and permissions. |
.github/workflows/validate-renovate-configuration.yaml |
Masks the workflow token. |
docs/journals/20260827T210117Z.md |
Adds an unrelated contributor-cache workaround. |
Review details
Suppressed comments (2)
.github/workflows/run-pre-commit-via-determinate.yaml:110
BASE_REFis expanded by the outer shell and inserted unquoted into the program that the inner Bash process reparses. Shell metacharacters in a target branch can therefore become commands. Defer expansion to the inner shell and quote the complete ref argument.
if [[ \"${EVENT_NAME}\" == \"pull_request\" ]]; then
pre-commit run --from-ref=origin/${BASE_REF} --to-ref=HEAD
.github/workflows/run-pre-commit-via-nix.yaml:135
BASE_REFis expanded by the outer shell and inserted unquoted into the program that the inner Bash process reparses. Shell metacharacters in a target branch can therefore become commands. Defer expansion to the inner shell and quote the complete ref argument.
if [[ \"${EVENT_NAME}\" == \"pull_request\" ]]; then
pre-commit run --from-ref=origin/${BASE_REF} --to-ref=HEAD
- Files reviewed: 10/10 changed files
- Comments generated: 4
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Escape `$` signs inside the double-quoted `bash -c "..."` strings in
run-pre-commit-via-determinate.yaml and run-pre-commit-via-nix.yaml.
The outer shell was expanding ${EVENT_NAME}, ${GIT_REF}, and
${BASE_REF} before passing the program to the inner bash process,
which allowed shell metacharacters in a branch name to become
commands. Using \${...} defers expansion to the inner shell, which
receives the values from its inherited environment.
Also reduce update-terraform-binary-version.yaml job permissions to
contents: read. The git push and all gh pr operations use GH_TOKEN
(App token), so GITHUB_TOKEN does not need contents: write or
pull-requests: write.
Addresses review feedback on #226.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
Nested shell expansion retains the injection path, and the Terraform workflow grants an ineffective, overbroad permission.
Review details
Suppressed comments (4)
Previously missed (1) — in code that hasn't changed since the last review.
.github/workflows/update-terraform-binary-version.yaml:23
- This permission applies only to
github.token; it does not grant permissions to the App token used bygh pr. The added scope therefore does not fix App authentication and instead gives thegithub.tokenpassed to the Setup Nix action pull-request write access. Keep this scope off the job and grant pull-request write permission to the GitHub App installation instead.
steps:
docs/journals/20260827T210117Z.md:1
- This contributor-cache journal is unrelated to the workflow security fixes described by this pull request and is not listed among its changed files. Remove it from this pull request and submit the operational branch-rename guidance separately so that reviewers can assess that procedure in the correct scope.
# Fix Stale GitHub Contributor Count After Force Push
.github/workflows/run-pre-commit-via-determinate.yaml:102
- The
bash -cbody remains double quoted by the runner shell, so the runner expands these environment variables before the inner shell parses the resulting text. A ref containing shell syntax can therefore become inner-shell code, which means this change does not close the injection path. Defer expansion to the inner shell and quote the ref argument.
if [[ \"\${EVENT_NAME}\" == \"push\" && \"\${GIT_REF}\" == \"refs/heads/main\" ]]; then
.github/workflows/run-pre-commit-via-nix.yaml:127
- The
bash -cbody remains double quoted by the runner shell, so the runner expands these environment variables before the inner shell parses the resulting text. A ref containing shell syntax can therefore become inner-shell code, which means this change does not close the injection path. Defer expansion to the inner shell and quote the ref argument.
if [[ \"\${EVENT_NAME}\" == \"push\" && \"\${GIT_REF}\" == \"refs/heads/main\" ]]; then
- Files reviewed: 10/10 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Replace the double-quoted `bash -c "..."` construction in both
pre-commit workflows with a single-quoted heredoc that writes the
script to a temporary file. Using `<< 'SCRIPT'` prevents the runner
shell from expanding any `${}` sequences during file creation; the
inner bash process inherits the environment and expands
`${EVENT_NAME}`, `${GIT_REF}`, and `${BASE_REF}` itself.
Also add double-quoting to the `--from-ref="origin/${BASE_REF}"`
argument so the inner bash protects the value against word splitting
and glob expansion.
Addresses review feedback on #226.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
App-token permissions remain overly broad, token files have a permission race, and the added journal contains unsafe or inaccurate guidance.
Review details
Suppressed comments (9)
Previously missed (6) — in code that hasn't changed since the last review.
.github/workflows/update-terraform-binary-version.yaml:22
- The job-level
permissionsblock limits onlygithub.token; it does not constrain the App token used for the push and pull request operations. Because the token action does not request specific permissions, v3 inherits every permission granted to the installation, contrary to this pull request's least-privilege goal. Restrict the App token to the two required write permissions.
contents: read
.github/workflows/format-with-treefmt.yaml:55
- The redirection creates this secret file with the runner's current umask, typically mode
0644, and only restricts it after the token has been written. Setumask 077before creating the file so the token is never briefly readable by other local users.
> "${HOME}/.config/nix/access-tokens.conf"
chmod 600 "${HOME}/.config/nix/access-tokens.conf"
.github/workflows/update-nix-flake-lock.yml:57
- The redirection creates this secret file with the runner's current umask, typically mode
0644, and only restricts it after the token has been written. Setumask 077before creating the file so the token is never briefly readable by other local users.
> "${HOME}/.config/nix/access-tokens.conf"
chmod 600 "${HOME}/.config/nix/access-tokens.conf"
docs/journals/20260827T210117Z.md:47
- These link labels use sentence case, but
AGENTS.md:19requires Title Case Text for links. Capitalize each new label to follow the repository's documented Markdown convention.
This issue also appears on line 48 of the same file.
- [GitHub community discussion #59921][discussion-59921]
- [GitHub community discussion #123702][discussion-123702]
- [GitHub community discussion #176218][discussion-176218]
- [GitHub community discussion #186025][discussion-186025]
- [Beyond the push: why GitHub's contributor list lagging skews your developer statistics][devactivity-post]
.github/workflows/check-nix-flake.yml:48
- The redirection creates this secret file with the runner's current umask, typically mode
0644, and only restricts it after the token has been written. Setumask 077before creating the file so the token is never briefly readable by other local users.
> "${HOME}/.config/nix/access-tokens.conf"
chmod 600 "${HOME}/.config/nix/access-tokens.conf"
docs/journals/20260827T210117Z.md:20
- This presents the branch rename as a deterministic cache invalidation, but GitHub does not document or guarantee that behavior. A default-branch rename has documented side effects, including closing pull requests that use the branch as their head and breaking workflows or action references that name it. Mark the workaround as anecdotal and document those risks, or remove the procedure.
This issue also appears on line 39 of the same file.
Renaming the default branch and immediately renaming it back forces
GitHub to rebuild its contributor index.
docs/journals/20260827T210117Z.md:1
- This contributor-cache journal is unrelated to the stated CI security scope and is omitted from the pull request's inventory of nine changed workflow files. Remove it from this pull request or explain why this operational procedure belongs in the security change.
# Fix Stale GitHub Contributor Count After Force Push
docs/journals/20260827T210117Z.md:48
- This link label uses sentence case, but
AGENTS.md:19requires Title Case Text for links.
- [JupyterLab issue #12271][jupyterlab-12271]
docs/journals/20260827T210117Z.md:39
- GitHub automatically updates branch protection policies when a branch is renamed, so instructing readers to reapply them is inaccurate and may cause unnecessary policy changes. Tell readers to verify that the transferred policy remains correct instead.
If protection rules exist, note them and reapply after the rename.
- Files reviewed: 10/10 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Set `umask 077` before writing access-tokens.conf in all three Configure Nix Authentication steps (check-nix-flake.yml, format-with-treefmt.yaml, update-nix-flake-lock.yml). The previous `>` redirect created the file with the runner's default umask (typically 0644), making the token briefly world-readable before `chmod 600` ran. Setting umask 077 first ensures the file is created with mode 0600 from the start, removing the race window. Restrict the App token in update-terraform-binary-version.yaml to the two required permissions (contents: write and pull-requests: write) via the create-github-app-token permissions input. The action previously inherited every permission granted to the installation, violating least privilege. Addresses review feedback on #226. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The undocumented journal change falls outside the stated scope and violates repository link-formatting rules.
Review details
Suppressed comments (3)
Previously missed (1) — in code that hasn't changed since the last review.
docs/journals/20260827T210117Z.md:47
- Capitalize these link texts in title case as required by
AGENTS.md:19.
This issue also appears on line 48 of the same file.
- [GitHub community discussion #59921][discussion-59921]
- [GitHub community discussion #123702][discussion-123702]
- [GitHub community discussion #176218][discussion-176218]
- [GitHub community discussion #186025][discussion-186025]
- [Beyond the push: why GitHub's contributor list lagging skews your developer statistics][devactivity-post]
docs/journals/20260827T210117Z.md:1
- This journal is unrelated to the workflow security work and contradicts the description’s statement that the pull request changes nine workflow files. Move it to a separate pull request, or explicitly include and justify it in this pull request’s scope.
# Fix Stale GitHub Contributor Count After Force Push
docs/journals/20260827T210117Z.md:48
- Capitalize this link text in title case as required by
AGENTS.md:19.
- [JupyterLab issue #12271][jupyterlab-12271]
- Files reviewed: 10/10 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Fix script injection in run-pre-commit workflows by moving github.event_name, github.ref, and github.base_ref into env vars before the bash -c string. Set environment.name unconditionally to "unstable" in both run-pre-commit workflows. The conditional form evaluated to an empty string on non-unstable refs, bypassing environment protection entirely. Set GH_TOKEN to the App token in update-nix-flake-lock.yml. The built-in github.token was used, so pushes and PR creation used the wrong identity and could not trigger downstream workflows. Add pull-requests: write permission to the terraform update job, which calls gh pr create and gh pr edit. Add Authorization header to the curl call in the terraform update job to avoid unauthenticated rate limits. Add NIX_FLAKE_CHECKER_NO_TELEMETRY and send-statistics: false to the check-nixpkgs-currency job and add timeout-minutes: 10. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Add a dedicated "Mask Tokens" step immediately after token creation in every workflow job that uses a GitHub App token or github.token in run steps. - Jobs with a GitHub App token mask both the App token output and github.token (defense-in-depth on top of the automatic masking applied by actions/create-github-app-token and the GitHub Actions runtime). - Jobs with only github.token (show-nix-information, validate-renovate-configuration) mask github.token as the first step before any run step executes. - Remove the inline ::add-mask:: call from inside the "Show Nix Configuration" step in show-nix-information.yaml; the dedicated first step covers the whole job. Affected files: check-nix-flake.yml, format-with-treefmt.yaml, run-pre-commit-via-determinate.yaml, run-pre-commit-via-nix.yaml, show-nix-information.yaml, update-flake-lock.yml, update-nix-flake-lock.yml, update-terraform-binary-version.yaml, validate-renovate-configuration.yaml. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Replace NIX_CONFIG env var token embedding with a dedicated ~/.config/nix/access-tokens.conf file in three workflows: check-nix-flake.yml, format-with-treefmt.yaml, and update-nix-flake-lock.yml. The NIX_CONFIG env var exposed the GitHub token in the process environment, making it visible via /proc/self/environ and Nix debug logs. Writing the token to a 0600-mode file and including it via an !include directive in nix.conf limits its exposure to the file system only. Pattern inspired by numtide/nix-auth. See NixOS/nix#6536 and https://github.com/numtide/nix-auth. Also remove overly broad actions: write permission from both pre-commit workflows; contents: read is sufficient. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Escape `$` signs inside the double-quoted `bash -c "..."` strings in
run-pre-commit-via-determinate.yaml and run-pre-commit-via-nix.yaml.
The outer shell was expanding ${EVENT_NAME}, ${GIT_REF}, and
${BASE_REF} before passing the program to the inner bash process,
which allowed shell metacharacters in a branch name to become
commands. Using \${...} defers expansion to the inner shell, which
receives the values from its inherited environment.
Also reduce update-terraform-binary-version.yaml job permissions to
contents: read. The git push and all gh pr operations use GH_TOKEN
(App token), so GITHUB_TOKEN does not need contents: write or
pull-requests: write.
Addresses review feedback on #226.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Replace the double-quoted `bash -c "..."` construction in both
pre-commit workflows with a single-quoted heredoc that writes the
script to a temporary file. Using `<< 'SCRIPT'` prevents the runner
shell from expanding any `${}` sequences during file creation; the
inner bash process inherits the environment and expands
`${EVENT_NAME}`, `${GIT_REF}`, and `${BASE_REF}` itself.
Also add double-quoting to the `--from-ref="origin/${BASE_REF}"`
argument so the inner bash protects the value against word splitting
and glob expansion.
Addresses review feedback on #226.
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Set `umask 077` before writing access-tokens.conf in all three Configure Nix Authentication steps (check-nix-flake.yml, format-with-treefmt.yaml, update-nix-flake-lock.yml). The previous `>` redirect created the file with the runner's default umask (typically 0644), making the token briefly world-readable before `chmod 600` ran. Setting umask 077 first ensures the file is created with mode 0600 from the start, removing the race window. Restrict the App token in update-terraform-binary-version.yaml to the two required permissions (contents: write and pull-requests: write) via the create-github-app-token permissions input. The action previously inherited every permission granted to the installation, violating least privilege. Addresses review feedback on #226. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Replace the `>-` folded block scalar with a single-quoted inline JSON string for the `permissions` input of `create-github-app-token`. The folded form caused yamlfmt to inject a `#magic___^_^___line` artifact on subsequent runs, making the file non-idempotent. A single-quoted scalar is not subject to yamlfmt folding. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
Replace the invalid `permissions` JSON blob with individual `permission-<name>` inputs as documented by `actions/create-github-app-token`. The correct syntax is: permission-contents: write permission-pull-requests: write The `permissions` key with a JSON value is not a supported input for this action and was silently ignored, meaning the token still inherited all installation permissions. Fix https://github.com/actions/create-github-app-token/tree/bcd2ba49218906704ab6c1aa796996da409d3eb1/#permission-permission-name. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
4943e3b to
64689f4
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Two update jobs still expose an unnecessary write-capable GitHub token despite using App tokens for mutations.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
- Files reviewed: 9/9 changed files
- Comments generated: 2
- Review effort level: Balanced
All repository mutations use the GitHub App token. The job-level `github.token` only needs read access for checkout and Nix store operations. Remove `contents: write` and `pull-requests: write` from both flake-lock update workflows. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The repository-scoped App token cannot reliably authenticate requests for the hashicorp/terraform repository.
Review details
Suppressed comments (1)
Previously missed (1) — in code that hasn't changed since the last review.
.github/workflows/update-terraform-binary-version.yaml:82
- This installation token is scoped to the current repository because the token step does not set
ownerorrepositories. GitHub Apps can access a public repository only when that repository is selected for the installation, so authenticating a request tohashicorp/terraformwith this token can return 404 instead of fixing the rate-limit issue. Use a credential that can read that repository, or query HashiCorp's public release index without this repository-scoped token.
--header "Authorization: Bearer ${GH_TOKEN}" \
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Replace the GitHub API call to hashicorp/terraform with HashiCorps checkpoint API for version lookup. The App token is scoped to the current repository and cannot authenticate requests to a different organization. `checkpoint-api.hashicorp.com/v1/check/terraform` is publicly accessible without a token and returns the current stable release version directly. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Cache purging lacks its required permission, and the Nix update step still exposes the App token process-wide.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review details
Suppressed comments (2)
Previously missed (1) — in code that hasn't changed since the last review.
.github/workflows/run-pre-commit-via-nix.yaml:25
- The cache job still enables
purge: truebelow, but the pinnedcache-nix-actionrequiresactions: writefor purge operations. With this permission removed, the configured cache cleanup cannot run. Restore this permission, or disable the purge inputs if cleanup is no longer intended.
permissions:
contents: read
.github/workflows/update-nix-flake-lock.yml:95
- This reintroduces the App token as a step-wide environment variable, so
nix flake updateand every other command in this step inherit the same token that the new file was meant to remove from the process environment. ScopeGH_TOKENonly to the laterghinvocations, or split the Nix update and GitHub operations into separate steps.
GH_TOKEN: ${{ steps.create-github-app-token.outputs.token }}
- Files reviewed: 9/9 changed files
- Comments generated: 1
- Review effort level: Balanced
Cache purge operations require `actions: write`. This job intentionally omits that permission to reduce token scope. Disable purge in `cache-nix-action`; GitHub evicts stale caches automatically. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
`GH_TOKEN` set at step level exposes the App token to `nix flake update` and every other command in the step. Split into two steps: "Update Nix Flake Lock" uses `GIT_PUSH_TOKEN` only for the remote URL; "Create or Update Pull Request" sets `GH_TOKEN` for `gh` calls only. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
There was a problem hiding this comment.
🔵 Needs a closer look
The Terraform updater now depends on an unsupported internal HashiCorp endpoint instead of using the authenticated GitHub API.
Review details
Suppressed comments (1)
.github/workflows/update-terraform-binary-version.yaml:82
- The Checkpoint service is an internal HashiCorp endpoint whose own client repository says it is not intended for external use, so replacing the documented GitHub Releases API with it introduces an unsupported dependency into scheduled update automation. It also leaves the request unauthenticated, contrary to the pull request description. Keep the GitHub endpoint and authenticate it with the existing App token.
https://checkpoint-api.hashicorp.com/v1/check/terraform \
| jq --raw-output '.current_version'
- Files reviewed: 9/9 changed files
- Comments generated: 0 new
- Review effort level: Balanced
The HashiCorp checkpoint endpoint is an internal service not intended for external use. Revert to the GitHub Releases API for `hashicorp/terraform`. Use `github.token` (`GITHUB_RELEASES_TOKEN`) for the authenticated request instead of the installation-scoped App token, which cannot reliably access repositories outside its configured installation. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]>
* ci(workflows): fix injection and permission gaps Fix script injection in run-pre-commit workflows by moving github.event_name, github.ref, and github.base_ref into env vars before the bash -c string. Set environment.name unconditionally to "unstable" in both run-pre-commit workflows. The conditional form evaluated to an empty string on non-unstable refs, bypassing environment protection entirely. Set GH_TOKEN to the App token in update-nix-flake-lock.yml. The built-in github.token was used, so pushes and PR creation used the wrong identity and could not trigger downstream workflows. Add pull-requests: write permission to the terraform update job, which calls gh pr create and gh pr edit. Add Authorization header to the curl call in the terraform update job to avoid unauthenticated rate limits. Add NIX_FLAKE_CHECKER_NO_TELEMETRY and send-statistics: false to the check-nixpkgs-currency job and add timeout-minutes: 10. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): mask sensitive tokens Add a dedicated "Mask Tokens" step immediately after token creation in every workflow job that uses a GitHub App token or github.token in run steps. - Jobs with a GitHub App token mask both the App token output and github.token (defense-in-depth on top of the automatic masking applied by actions/create-github-app-token and the GitHub Actions runtime). - Jobs with only github.token (show-nix-information, validate-renovate-configuration) mask github.token as the first step before any run step executes. - Remove the inline ::add-mask:: call from inside the "Show Nix Configuration" step in show-nix-information.yaml; the dedicated first step covers the whole job. Affected files: check-nix-flake.yml, format-with-treefmt.yaml, run-pre-commit-via-determinate.yaml, run-pre-commit-via-nix.yaml, show-nix-information.yaml, update-flake-lock.yml, update-nix-flake-lock.yml, update-terraform-binary-version.yaml, validate-renovate-configuration.yaml. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): secure nix auth config Replace NIX_CONFIG env var token embedding with a dedicated ~/.config/nix/access-tokens.conf file in three workflows: check-nix-flake.yml, format-with-treefmt.yaml, and update-nix-flake-lock.yml. The NIX_CONFIG env var exposed the GitHub token in the process environment, making it visible via /proc/self/environ and Nix debug logs. Writing the token to a 0600-mode file and including it via an !include directive in nix.conf limits its exposure to the file system only. Pattern inspired by numtide/nix-auth. See NixOS/nix#6536 and https://github.com/numtide/nix-auth. Also remove overly broad actions: write permission from both pre-commit workflows; contents: read is sufficient. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix nested shell expansion Escape `$` signs inside the double-quoted `bash -c "..."` strings in run-pre-commit-via-determinate.yaml and run-pre-commit-via-nix.yaml. The outer shell was expanding ${EVENT_NAME}, ${GIT_REF}, and ${BASE_REF} before passing the program to the inner bash process, which allowed shell metacharacters in a branch name to become commands. Using \${...} defers expansion to the inner shell, which receives the values from its inherited environment. Also reduce update-terraform-binary-version.yaml job permissions to contents: read. The git push and all gh pr operations use GH_TOKEN (App token), so GITHUB_TOKEN does not need contents: write or pull-requests: write. Addresses review feedback on #226. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): defer shell expansion via heredoc Replace the double-quoted `bash -c "..."` construction in both pre-commit workflows with a single-quoted heredoc that writes the script to a temporary file. Using `<< 'SCRIPT'` prevents the runner shell from expanding any `${}` sequences during file creation; the inner bash process inherits the environment and expands `${EVENT_NAME}`, `${GIT_REF}`, and `${BASE_REF}` itself. Also add double-quoting to the `--from-ref="origin/${BASE_REF}"` argument so the inner bash protects the value against word splitting and glob expansion. Addresses review feedback on #226. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): tighten token and file permissions Set `umask 077` before writing access-tokens.conf in all three Configure Nix Authentication steps (check-nix-flake.yml, format-with-treefmt.yaml, update-nix-flake-lock.yml). The previous `>` redirect created the file with the runner's default umask (typically 0644), making the token briefly world-readable before `chmod 600` ran. Setting umask 077 first ensures the file is created with mode 0600 from the start, removing the race window. Restrict the App token in update-terraform-binary-version.yaml to the two required permissions (contents: write and pull-requests: write) via the create-github-app-token permissions input. The action previously inherited every permission granted to the installation, violating least privilege. Addresses review feedback on #226. Co-authored-by: Copilot <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix app token permissions format Replace the `>-` folded block scalar with a single-quoted inline JSON string for the `permissions` input of `create-github-app-token`. The folded form caused yamlfmt to inject a `#magic___^_^___line` artifact on subsequent runs, making the file non-idempotent. A single-quoted scalar is not subject to yamlfmt folding. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): use per-permission app token inputs Replace the invalid `permissions` JSON blob with individual `permission-<name>` inputs as documented by `actions/create-github-app-token`. The correct syntax is: permission-contents: write permission-pull-requests: write The `permissions` key with a JSON value is not a supported input for this action and was silently ignored, meaning the token still inherited all installation permissions. Fix https://github.com/actions/create-github-app-token/tree/bcd2ba49218906704ab6c1aa796996da409d3eb1/#permission-permission-name. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): reduce token to read All repository mutations use the GitHub App token. The job-level `github.token` only needs read access for checkout and Nix store operations. Remove `contents: write` and `pull-requests: write` from both flake-lock update workflows. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): use checkpoint api Replace the GitHub API call to hashicorp/terraform with HashiCorps checkpoint API for version lookup. The App token is scoped to the current repository and cannot authenticate requests to a different organization. `checkpoint-api.hashicorp.com/v1/check/terraform` is publicly accessible without a token and returns the current stable release version directly. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(pre-commit): disable cache purge Cache purge operations require `actions: write`. This job intentionally omits that permission to reduce token scope. Disable purge in `cache-nix-action`; GitHub evicts stale caches automatically. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): scope token to gh steps `GH_TOKEN` set at step level exposes the App token to `nix flake update` and every other command in the step. Split into two steps: "Update Nix Flake Lock" uses `GIT_PUSH_TOKEN` only for the remote URL; "Create or Update Pull Request" sets `GH_TOKEN` for `gh` calls only. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): restore releases api lookup The HashiCorp checkpoint endpoint is an internal service not intended for external use. Revert to the GitHub Releases API for `hashicorp/terraform`. Use `github.token` (`GITHUB_RELEASES_TOKEN`) for the authenticated request instead of the installation-scoped App token, which cannot reliably access repositories outside its configured installation. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> --------- Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> Signed-off-by: Leonard Lee <[email protected]> Co-authored-by: Copilot <[email protected]>
* ci(workflows): fix injection and permission gaps Fix script injection in run-pre-commit workflows by moving github.event_name, github.ref, and github.base_ref into env vars before the bash -c string. Set environment.name unconditionally to "unstable" in both run-pre-commit workflows. The conditional form evaluated to an empty string on non-unstable refs, bypassing environment protection entirely. Set GH_TOKEN to the App token in update-nix-flake-lock.yml. The built-in github.token was used, so pushes and PR creation used the wrong identity and could not trigger downstream workflows. Add pull-requests: write permission to the terraform update job, which calls gh pr create and gh pr edit. Add Authorization header to the curl call in the terraform update job to avoid unauthenticated rate limits. Add NIX_FLAKE_CHECKER_NO_TELEMETRY and send-statistics: false to the check-nixpkgs-currency job and add timeout-minutes: 10. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): mask sensitive tokens Add a dedicated "Mask Tokens" step immediately after token creation in every workflow job that uses a GitHub App token or github.token in run steps. - Jobs with a GitHub App token mask both the App token output and github.token (defense-in-depth on top of the automatic masking applied by actions/create-github-app-token and the GitHub Actions runtime). - Jobs with only github.token (show-nix-information, validate-renovate-configuration) mask github.token as the first step before any run step executes. - Remove the inline ::add-mask:: call from inside the "Show Nix Configuration" step in show-nix-information.yaml; the dedicated first step covers the whole job. Affected files: check-nix-flake.yml, format-with-treefmt.yaml, run-pre-commit-via-determinate.yaml, run-pre-commit-via-nix.yaml, show-nix-information.yaml, update-flake-lock.yml, update-nix-flake-lock.yml, update-terraform-binary-version.yaml, validate-renovate-configuration.yaml. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): secure nix auth config Replace NIX_CONFIG env var token embedding with a dedicated ~/.config/nix/access-tokens.conf file in three workflows: check-nix-flake.yml, format-with-treefmt.yaml, and update-nix-flake-lock.yml. The NIX_CONFIG env var exposed the GitHub token in the process environment, making it visible via /proc/self/environ and Nix debug logs. Writing the token to a 0600-mode file and including it via an !include directive in nix.conf limits its exposure to the file system only. Pattern inspired by numtide/nix-auth. See NixOS/nix#6536 and https://github.com/numtide/nix-auth. Also remove overly broad actions: write permission from both pre-commit workflows; contents: read is sufficient. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix nested shell expansion Escape `$` signs inside the double-quoted `bash -c "..."` strings in run-pre-commit-via-determinate.yaml and run-pre-commit-via-nix.yaml. The outer shell was expanding ${EVENT_NAME}, ${GIT_REF}, and ${BASE_REF} before passing the program to the inner bash process, which allowed shell metacharacters in a branch name to become commands. Using \${...} defers expansion to the inner shell, which receives the values from its inherited environment. Also reduce update-terraform-binary-version.yaml job permissions to contents: read. The git push and all gh pr operations use GH_TOKEN (App token), so GITHUB_TOKEN does not need contents: write or pull-requests: write. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): defer shell expansion via heredoc Replace the double-quoted `bash -c "..."` construction in both pre-commit workflows with a single-quoted heredoc that writes the script to a temporary file. Using `<< 'SCRIPT'` prevents the runner shell from expanding any `${}` sequences during file creation; the inner bash process inherits the environment and expands `${EVENT_NAME}`, `${GIT_REF}`, and `${BASE_REF}` itself. Also add double-quoting to the `--from-ref="origin/${BASE_REF}"` argument so the inner bash protects the value against word splitting and glob expansion. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): tighten token and file permissions Set `umask 077` before writing access-tokens.conf in all three Configure Nix Authentication steps (check-nix-flake.yml, format-with-treefmt.yaml, update-nix-flake-lock.yml). The previous `>` redirect created the file with the runner's default umask (typically 0644), making the token briefly world-readable before `chmod 600` ran. Setting umask 077 first ensures the file is created with mode 0600 from the start, removing the race window. Restrict the App token in update-terraform-binary-version.yaml to the two required permissions (contents: write and pull-requests: write) via the create-github-app-token permissions input. The action previously inherited every permission granted to the installation, violating least privilege. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix app token permissions format Replace the `>-` folded block scalar with a single-quoted inline JSON string for the `permissions` input of `create-github-app-token`. The folded form caused yamlfmt to inject a `#magic___^_^___line` artifact on subsequent runs, making the file non-idempotent. A single-quoted scalar is not subject to yamlfmt folding. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): use per-permission app token inputs Replace the invalid `permissions` JSON blob with individual `permission-<name>` inputs as documented by `actions/create-github-app-token`. The correct syntax is: permission-contents: write permission-pull-requests: write The `permissions` key with a JSON value is not a supported input for this action and was silently ignored, meaning the token still inherited all installation permissions. Fix https://github.com/actions/create-github-app-token/tree/bcd2ba49218906704ab6c1aa796996da409d3eb1/#permission-permission-name. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): reduce token to read All repository mutations use the GitHub App token. The job-level `github.token` only needs read access for checkout and Nix store operations. Remove `contents: write` and `pull-requests: write` from both flake-lock update workflows. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): use checkpoint api Replace the GitHub API call to hashicorp/terraform with HashiCorps checkpoint API for version lookup. The App token is scoped to the current repository and cannot authenticate requests to a different organization. `checkpoint-api.hashicorp.com/v1/check/terraform` is publicly accessible without a token and returns the current stable release version directly. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(pre-commit): disable cache purge Cache purge operations require `actions: write`. This job intentionally omits that permission to reduce token scope. Disable purge in `cache-nix-action`; GitHub evicts stale caches automatically. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): scope token to gh steps `GH_TOKEN` set at step level exposes the App token to `nix flake update` and every other command in the step. Split into two steps: "Update Nix Flake Lock" uses `GIT_PUSH_TOKEN` only for the remote URL; "Create or Update Pull Request" sets `GH_TOKEN` for `gh` calls only. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): restore releases api lookup The HashiCorp checkpoint endpoint is an internal service not intended for external use. Revert to the GitHub Releases API for `hashicorp/terraform`. Use `github.token` (`GITHUB_RELEASES_TOKEN`) for the authenticated request instead of the installation-scoped App token, which cannot reliably access repositories outside its configured installation. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> --------- Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> Signed-off-by: Leonard Lee <[email protected]>
* ci(workflows): fix injection and permission gaps Fix script injection in run-pre-commit workflows by moving github.event_name, github.ref, and github.base_ref into env vars before the bash -c string. Set environment.name unconditionally to "unstable" in both run-pre-commit workflows. The conditional form evaluated to an empty string on non-unstable refs, bypassing environment protection entirely. Set GH_TOKEN to the App token in update-nix-flake-lock.yml. The built-in github.token was used, so pushes and PR creation used the wrong identity and could not trigger downstream workflows. Add pull-requests: write permission to the terraform update job, which calls gh pr create and gh pr edit. Add Authorization header to the curl call in the terraform update job to avoid unauthenticated rate limits. Add NIX_FLAKE_CHECKER_NO_TELEMETRY and send-statistics: false to the check-nixpkgs-currency job and add timeout-minutes: 10. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): mask sensitive tokens Add a dedicated "Mask Tokens" step immediately after token creation in every workflow job that uses a GitHub App token or github.token in run steps. - Jobs with a GitHub App token mask both the App token output and github.token (defense-in-depth on top of the automatic masking applied by actions/create-github-app-token and the GitHub Actions runtime). - Jobs with only github.token (show-nix-information, validate-renovate-configuration) mask github.token as the first step before any run step executes. - Remove the inline ::add-mask:: call from inside the "Show Nix Configuration" step in show-nix-information.yaml; the dedicated first step covers the whole job. Affected files: check-nix-flake.yml, format-with-treefmt.yaml, run-pre-commit-via-determinate.yaml, run-pre-commit-via-nix.yaml, show-nix-information.yaml, update-flake-lock.yml, update-nix-flake-lock.yml, update-terraform-binary-version.yaml, validate-renovate-configuration.yaml. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): secure nix auth config Replace NIX_CONFIG env var token embedding with a dedicated ~/.config/nix/access-tokens.conf file in three workflows: check-nix-flake.yml, format-with-treefmt.yaml, and update-nix-flake-lock.yml. The NIX_CONFIG env var exposed the GitHub token in the process environment, making it visible via /proc/self/environ and Nix debug logs. Writing the token to a 0600-mode file and including it via an !include directive in nix.conf limits its exposure to the file system only. Pattern inspired by numtide/nix-auth. See NixOS/nix#6536 and https://github.com/numtide/nix-auth. Also remove overly broad actions: write permission from both pre-commit workflows; contents: read is sufficient. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix nested shell expansion Escape `$` signs inside the double-quoted `bash -c "..."` strings in run-pre-commit-via-determinate.yaml and run-pre-commit-via-nix.yaml. The outer shell was expanding ${EVENT_NAME}, ${GIT_REF}, and ${BASE_REF} before passing the program to the inner bash process, which allowed shell metacharacters in a branch name to become commands. Using \${...} defers expansion to the inner shell, which receives the values from its inherited environment. Also reduce update-terraform-binary-version.yaml job permissions to contents: read. The git push and all gh pr operations use GH_TOKEN (App token), so GITHUB_TOKEN does not need contents: write or pull-requests: write. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): defer shell expansion via heredoc Replace the double-quoted `bash -c "..."` construction in both pre-commit workflows with a single-quoted heredoc that writes the script to a temporary file. Using `<< 'SCRIPT'` prevents the runner shell from expanding any `${}` sequences during file creation; the inner bash process inherits the environment and expands `${EVENT_NAME}`, `${GIT_REF}`, and `${BASE_REF}` itself. Also add double-quoting to the `--from-ref="origin/${BASE_REF}"` argument so the inner bash protects the value against word splitting and glob expansion. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): tighten token and file permissions Set `umask 077` before writing access-tokens.conf in all three Configure Nix Authentication steps (check-nix-flake.yml, format-with-treefmt.yaml, update-nix-flake-lock.yml). The previous `>` redirect created the file with the runner's default umask (typically 0644), making the token briefly world-readable before `chmod 600` ran. Setting umask 077 first ensures the file is created with mode 0600 from the start, removing the race window. Restrict the App token in update-terraform-binary-version.yaml to the two required permissions (contents: write and pull-requests: write) via the create-github-app-token permissions input. The action previously inherited every permission granted to the installation, violating least privilege. Addresses review feedback on #226. Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): fix app token permissions format Replace the `>-` folded block scalar with a single-quoted inline JSON string for the `permissions` input of `create-github-app-token`. The folded form caused yamlfmt to inject a `#magic___^_^___line` artifact on subsequent runs, making the file non-idempotent. A single-quoted scalar is not subject to yamlfmt folding. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(workflows): use per-permission app token inputs Replace the invalid `permissions` JSON blob with individual `permission-<name>` inputs as documented by `actions/create-github-app-token`. The correct syntax is: permission-contents: write permission-pull-requests: write The `permissions` key with a JSON value is not a supported input for this action and was silently ignored, meaning the token still inherited all installation permissions. Fix https://github.com/actions/create-github-app-token/tree/bcd2ba49218906704ab6c1aa796996da409d3eb1/#permission-permission-name. Signed-off-by: Leonard Lee <[email protected]> Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): reduce token to read All repository mutations use the GitHub App token. The job-level `github.token` only needs read access for checkout and Nix store operations. Remove `contents: write` and `pull-requests: write` from both flake-lock update workflows. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): use checkpoint api Replace the GitHub API call to hashicorp/terraform with HashiCorps checkpoint API for version lookup. The App token is scoped to the current repository and cannot authenticate requests to a different organization. `checkpoint-api.hashicorp.com/v1/check/terraform` is publicly accessible without a token and returns the current stable release version directly. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(pre-commit): disable cache purge Cache purge operations require `actions: write`. This job intentionally omits that permission to reduce token scope. Disable purge in `cache-nix-action`; GitHub evicts stale caches automatically. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(flake-lock): scope token to gh steps `GH_TOKEN` set at step level exposes the App token to `nix flake update` and every other command in the step. Split into two steps: "Update Nix Flake Lock" uses `GIT_PUSH_TOKEN` only for the remote URL; "Create or Update Pull Request" sets `GH_TOKEN` for `gh` calls only. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> * ci(terraform): restore releases api lookup The HashiCorp checkpoint endpoint is an internal service not intended for external use. Revert to the GitHub Releases API for `hashicorp/terraform`. Use `github.token` (`GITHUB_RELEASES_TOKEN`) for the authenticated request instead of the installation-scoped App token, which cannot reliably access repositories outside its configured installation. Fix #226 (review). Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> --------- Signed-off-by: Leonard Sheng Sheng Lee <[email protected]> Signed-off-by: Leonard Lee <[email protected]>
Summary
permissions, unauthenticated API calls, and telemetry opt-out
across all workflow files.
::add-mask::steps to every job that uses aGitHub App token or
github.tokenin run steps.NIX_CONFIGenv var token embedding with a dedicatedaccess-tokens.conffile to limit token exposure.actions: writefrom pre-commit workflows.Commit Groups
Fix injection and permission gaps (
a342fc7)github.event_name,github.ref, andgithub.base_refinto
env:vars before thebash -cstring inrun-pre-commit-via-determinate.yamlandrun-pre-commit-via-nix.yamlto prevent shell injection viacrafted branch names.
environment.name: unstableunconditionally in bothpre-commit workflows. The conditional form evaluated to
''onnon-
unstablerefs, bypassing environment protection entirely.GH_TOKENfromgithub.tokento the App token inupdate-nix-flake-lock.ymlso pushes and PR creation use theApp identity and can trigger downstream workflows.
pull-requests: writetoupdate-terraform-binary-version.yamlsogh pr createandgh pr edithave the required scope.Authorization: Bearerheader to thecurlcall inthe terraform update job to avoid unauthenticated rate limits.
NIX_FLAKE_CHECKER_NO_TELEMETRY: "true"andsend-statistics: falseto thecheck-nixpkgs-currencyjobin
check-nix-flake.yml.Mask sensitive tokens in all jobs (
2578645)Mask Tokensstep immediately after tokencreation in every job that uses an App token or
github.tokenin run steps.
github.tokenas defense-in-depth on top of the automaticmasking applied by
actions/create-github-app-tokenand theGitHub Actions runtime.
::add-mask::call inshow-nix-information.yamlto a dedicated first step thatcovers the whole job.
validate-renovate-configuration.yaml.Secure Nix authentication configuration (
ef442c1)Configure Nix Authenticationstep tocheck-nix-flake.yml,format-with-treefmt.yaml, andupdate-nix-flake-lock.yml. The step writes the App token to~/.config/nix/access-tokens.confwith mode0600and addsan
!includedirective to~/.config/nix/nix.conf. Thislimits the token to the file system rather than leaving it in
the process environment where it is readable via
/proc/self/environor Nix debug logs.NIX_CONFIGenv var from all affected steps.actions: writefromrun-pre-commit-via-determinate.yamland
run-pre-commit-via-nix.yaml;contents: readissufficient for cache operations.
NixOS issue #6536.
Notes
check-nix-flake.yml,format-with-treefmt.yaml,run-pre-commit-via-determinate.yaml,run-pre-commit-via-nix.yaml,show-nix-information.yaml,update-flake-lock.yml,update-nix-flake-lock.yml,update-terraform-binary-version.yaml, andvalidate-renovate-configuration.yaml.References
by using
::add-mask::VALUE." Applies to theMask Tokensstep added to every job in this pull request.
set the value of the expression to an intermediate
environment variable." Applies to moving
github.base_refand other context values into
env:vars.have the least privileges required." Applies to adding
pull-requests: writeonly where needed and removingactions: writefrom pre-commit workflows.