Skip to content

Restrict the workflow token permissions and pass only the needed secrets - #80

Merged
ThoSap merged 1 commit into
mainfrom
harden-workflows
Oct 23, 2026
Merged

ThoSap merged 1 commit into
mainfrom
harden-workflows

Conversation

@ThoSap

@ThoSap ThoSap commented Oct 23, 2026

Copy link
Copy Markdown
Member

The GitHub Actions workflows had no permissions: block, passed all secrets to the reusable test workflow, and used an input expression directly in a run: script.
This PR fixes the findings of zizmor that we can fix in the YAML alone.

What changed

  1. Explicit GITHUB_TOKEN permissions. Without a permissions: block, the token gets the default permissions of the repository or the org. Now:
    • release.yml sets permissions: {} at the top, so each job must ask for what it needs.
    • The build-and-release job gets contents: write to create the GitHub release and packages: write to push to GHCR.
    • The test jobs get contents: read.
    • The tag push and the README push use GH_PERSONAL_ACCESS_TOKEN, so they do not need more permissions on GITHUB_TOKEN.
  2. Only the needed secret goes to test.yml. secrets: inherit gave all secrets to the test workflow, including GH_PERSONAL_ACCESS_TOKEN in the release workflow. test.yml now declares GRADLE_ENCRYPTION_KEY as a workflow_call secret, and main.yml and release.yml pass only that secret. The secret is optional, because the build works without it: setup-gradle then only skips the save and restore of the configuration cache. Pull requests from forks and from Dependabot also receive no secrets. Note: the CI logs show that GRADLE_ENCRYPTION_KEY is empty today, also for runs from this repository, so CI never caches the configuration cache. To change this, an admin must create the secret, for example with openssl rand -base64 16.
  3. persist-credentials: false in test.yml. The test job does not push, so the token does not need to stay in .git/config.
  4. The increment input goes through env:. release.yml used ${{ github.event.inputs.increment }} directly in the script. It is now INCREMENT in env:, as GitHub recommends for inline scripts (Use an intermediate environment variable). The real risk was low, because only users with write access can start the workflow and the input is a choice.

Not in this PR

  • GH_PERSONAL_ACCESS_TOKEN in the release checkout. actions/checkout stores the PAT in .git/config for the whole release job, so every later step can read it. The job needs it for pushRelease and the README push to main. A fine-grained PAT limited to this repository, or a GitHub App token from actions/create-github-app-token, reduces the risk. This needs a change in the repository or org settings.
  • SHA pins for actions. The actions use tags such as @v5. GitHub recommends a full commit SHA for third-party actions. With SHA pins, we also need Dependabot for the github-actions ecosystem, so the pins stay current.

Relation to #79

#79 added a Helm chart push to GHCR in the release job. The packages: write permission of this PR covers that push too.

Tests

  • Ruby parses all three workflow files without errors.
  • zizmor 1.16.3 in default mode reports 15 findings instead of 24. No excessive-permissions, secrets-inherit, or template-injection error or warning remains. The remaining findings are the PAT checkout and 6 tag references, see "Not in this PR", and 8 informational or help findings for our own values (env.* and steps.*).
  • I set the permissions from the definitions of the actions that the jobs use. The workflows did not run with this change. The test workflow runs on this PR. A missing permission in the release job shows only at the next release.

GRADLE_ENCRYPTION_KEY is optional in test.yml, because pull requests
from forks receive no secrets.

Assisted-by: Claude:claude-opus-5-5
@ThoSap ThoSap self-assigned this Oct 23, 2026
@ThoSap
ThoSap merged commit 68398be into main Oct 23, 2026
4 checks passed
@ThoSap
ThoSap deleted the harden-workflows branch October 23, 2026 21:47
@ThoSap ThoSap added the enhancement New feature or request label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant