Skip to content

ci: restrict GitHub Actions cache access with cache-mode - #169

Merged
nozaq merged 1 commit into
mainfrom
claude/gha-workflow-minimal-permissions-1mgnnz
Sep 17, 2026
Merged

nozaq merged 1 commit into
mainfrom
claude/gha-workflow-minimal-permissions-1mgnnz

Conversation

@nozaq

@nozaq nozaq commented Sep 17, 2026

Copy link
Copy Markdown
Member

Summary

GitHub now lets a workflow or job declare the cache access it needs with cache-mode (read, write, write-only, none), enforced by the cache service (changelog, workflow syntax, dependency caching reference). Without it, push, schedule and workflow_dispatch runs get write by default.

This applies the same least-privilege pattern already used for permissions: cache-mode: none at the workflow level of every workflow, and a job-level grant only where actions/setup-go (which caches by default) or build-push-action type=gha needs one.

Workflow Job Mode Reason
ci.yml test, lint, docs, dockerflags, dogfooding write setup-go cache saved on main, restored by pull requests
ci.yml docker write cache-to: type=gha
codeql.yml analyze write setup-go cache, CodeQL caches
pages.yml build write setup-go cache holds the Hugo tool build
release.yml build read Restores the main cache; a save scoped to a tag ref is never restored by another run
sarif-upload-check.yml upload-check read Restores only; ci.yml already saves the same key on main
everything else none

Also:

  • codeql.yml gets the workflow-level permissions: {} the other workflows already carry (the analyze job's own permissions are unchanged).
  • AGENTS.md documents the convention next to the permissions: {} rule.

Notes

  • A cache operation refused by the mode is logged and the step continues, so the read jobs skip the setup-go post-step save rather than fail.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AKZPpJJVhgvmm2GZbX3nxV


Generated by Claude Code

Set cache-mode to none at the workflow level and grant each job only
what its setup-go and build-push-action caches need: write where a
run on main saves the cache pull requests restore (ci.yml, codeql.yml,
pages.yml), read where a job only restores it (the release build and
the SARIF upload check).

codeql.yml also gets the workflow-level permissions block the other
workflows already carry, and the convention is documented next to the
permissions rule.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKZPpJJVhgvmm2GZbX3nxV
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@nozaq
nozaq marked this pull request as ready for review September 17, 2026 01:13
@nozaq
nozaq merged commit 4bc9401 into main Sep 17, 2026
33 checks passed
@nozaq
nozaq deleted the claude/gha-workflow-minimal-permissions-1mgnnz branch September 17, 2026 01:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants