Harden Maven/Java workflows against zizmor findings - #6546
Conversation
Address all zizmor 1.25.2 findings in the Maven/Java-themed workflows
with no behavioral change:
- template-injection: move attacker-controllable ${{ }} expressions
(matrix.*, runner.workspace, github.actor, github.base_ref,
steps.*.outputs.*, needs.*.outputs.*) out of run: script bodies into
step-level env: blocks referenced as shell/pwsh variables.
- artipacked: add persist-credentials: false to all actions/checkout
steps (none of these workflows push to git).
- excessive-permissions: add/tighten explicit permissions. Reduce
overly broad workflow-level packages:/pull-requests: grants to
contents: read, granting minimal packages: read/write only to the
specific jobs that need it.
- secrets-inherit (release.yml): remove secrets: inherit on the
test-maven-packages.yml call, which declares no workflow_call secrets.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Note: interaction with #6545 (checkout-hygiene + permissions hardening)This PR reduces Separately, #6545 re-grants |
There was a problem hiding this comment.
Pull request overview
Note
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Hardens Maven/Java GitHub Actions workflows to resolve zizmor findings by reducing token permissions, preventing credential persistence on checkouts, and avoiding attacker-controllable expression interpolation inside run: bodies.
Changes:
- Add
persist-credentials: falsetoactions/checkoutsteps to prevent token persistence. - Replace
${{ ... }}usage insiderun:blocks with stepenv:variables (bash / pwsh-safe). - Tighten GITHUB_TOKEN permissions at workflow and job scope; remove
secrets: inheriton reusable workflow call.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| .github/workflows/test-maven-packages.yml | Adds checkout hardening and moves workspace expressions into step env vars. |
| .github/workflows/test-maven-deployment.yml | Scopes permissions per job and hardens checkout; moves actor into env for run steps. |
| .github/workflows/release.yml | Removes secrets: inherit from reusable workflow invocation. |
| .github/workflows/maven-staging.yml | Drops excessive permissions, hardens checkout, and shifts run-body expressions into env vars. |
| .github/workflows/maven-build-test.yml | Reduces top-level permissions, hardens checkout, and shifts run-body expressions into env vars. |
| .github/workflows/java-implementation-test.yml | Adds explicit permissions and hardens checkout. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| - name: Checkout repository | ||
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| with: | ||
| persist-credentials: false |
Review ChecklistThis PR touches the following areas. Each needs a sign-off
|
|
Checked the Copilot comment about |
Hardens the Maven/Java-themed GitHub Actions workflows against all
zizmor1.25.2 static-analysis findings. No behavioral change: the same values and logic are preserved, just sourced viaenv:variables and explicit permissions/secrets.Findings fixed (per file)
maven-staging.ymlmaven-build-test.ymltest-maven-packages.ymljava-implementation-test.ymltest-maven-deployment.ymlrelease.ymlTotal: 77 findings resolved. Final
zizmorrun reports zero findings across all six files.What changed
${{ }}expressions used insiderun:bodies (matrix.*,runner.workspace,github.actor,github.base_ref,steps.*.outputs.*,needs.*.outputs.*) moved into step-levelenv:blocks and referenced as$NAME(bash) or$env:NAME(pwsh). Non-run-body expressions (if:,with:,uses:,env:values) left untouched.persist-credentials: falseadded to everyactions/checkoutstep. None of these workflows push to git (verified: nogit push/git commit/gh-pages/peaceiris/auto-commit/EndBug), so all checkouts were safe to harden.permissions: contents: read. Overly broad workflow-levelpackages: write/pull-requests: writereduced; minimalpackages: read/packages: writegranted only to the specific jobs that actually consume/deploy packages.maven-staging.ymlperforms only a dry-run deployment (no realmvn deploy, PR writes, or package API calls), so its top level drops tocontents: read.release.yml): the call totest-maven-packages.ymlusedsecrets: inherit, but that reusable workflow declares noworkflow_callsecrets, so the line was removed entirely.🤖 Generated with Claude Code