Skip to content

GHA: add explicit "permissions: contents: read" to all read-only workflows - #3357

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gha-permissions-tighten
Jun 8, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gha-permissions-tighten

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Summary

GitHub's default GITHUB_TOKEN permissions are wide-open (write to most scopes) unless a workflow explicitly narrows them. This PR adds a workflow-level permissions: contents: read block to all 10 OSHI workflows that only need to clone the repo and run tests / external-service uploads.

None of these workflows push to GitHub (no PR comments, no labels, no releases, no security events). Third-party uploads (Codecov, Sonar, Coverity, Sonatype) all use their own dedicated tokens, not GITHUB_TOKEN. So contents: read is the tightest minimum that still lets every job clone the repo.

Files changed (10): benchmarks.yaml, cfarm.yaml, coverity.yaml, linux.yaml, macos.yaml, pr.yaml, sonar.yaml, sonatype.yaml, unix.yaml, windows.yaml.

Unchanged (intentionally):

  • codeql-analysis.yml — already has per-job permissions including security-events: write for the CodeQL upload.
  • site.yaml — already has workflow-level contents: write for the gh-pages publish.

Why

GitHub treats the default GITHUB_TOKEN generously to keep onboarding easy, which means any compromised third-party action could write to the repo even when it didn't need to. Tightening per-workflow permissions: limits the blast radius. CodeRabbit flagged this on PR #3350's benchmark AIX job — this PR closes the broader gap.

Test plan

  • All workflows still parse (Spotless / actionlint would catch syntax issues; the structure follows the existing site.yaml pattern).
  • No workflow actually performs GitHub writes — verified by grep for gh pr/issue/release, PR-commenter actions, label-bot actions, artifact uploads, and release-action uses.
  • CI green on this PR (the workflows themselves are exercised here).

Summary by CodeRabbit

  • Chores
    • Enhanced security configurations across all CI/CD workflows by implementing explicit, minimal-privilege permission scopes for automated processes.

…flows

GitHub's default `GITHUB_TOKEN` permissions are wide-open (write to most
scopes) unless the workflow explicitly narrows them. Adds a workflow-level
`permissions: contents: read` block to all 10 OSHI workflows that only
need to clone the repo and run tests / external-service uploads. None of
them push to GitHub (no PR comments, no labels, no releases, no security
events); third-party uploads (Codecov, Sonar, Coverity, Sonatype) all use
their own tokens, not GITHUB_TOKEN.

Affects: `benchmarks.yaml`, `cfarm.yaml`, `coverity.yaml`, `linux.yaml`,
`macos.yaml`, `pr.yaml`, `sonar.yaml`, `sonatype.yaml`, `unix.yaml`,
`windows.yaml`.

Unchanged:

* `codeql-analysis.yml` — already has per-job permissions block
  (uses `security-events: write` for the CodeQL upload).
* `site.yaml` — already has workflow-level `contents: write` for the
  gh-pages publish.

No behavioural change; tightens the blast radius if a third-party action
were ever compromised.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: a3cfdf02-01f8-436d-822c-427717c8eda3

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdb8c9 and 1643f5d.

📒 Files selected for processing (10)
  • .github/workflows/benchmarks.yaml
  • .github/workflows/cfarm.yaml
  • .github/workflows/coverity.yaml
  • .github/workflows/linux.yaml
  • .github/workflows/macos.yaml
  • .github/workflows/pr.yaml
  • .github/workflows/sonar.yaml
  • .github/workflows/sonatype.yaml
  • .github/workflows/unix.yaml
  • .github/workflows/windows.yaml
📜 Recent review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3307
File: .github/workflows/netbsd.yaml:4-8
Timestamp: 2026-05-30T02:28:01.891Z
Learning: In the oshi/oshi repository, the `.github/workflows/netbsd.yaml` CI workflow intentionally triggers only on `push` to the `netbsd-port` branch during development. Before the final merge to master, NetBSD CI will be integrated into the main Unix CI workflow (e.g., `.github/workflows/pr.yaml` or equivalent). Do not flag the limited trigger scope as an issue on this PR.
📚 Learning: 2026-05-31T05:53:04.246Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3311
File: .github/workflows/site.yaml:21-21
Timestamp: 2026-05-31T05:53:04.246Z
Learning: When a GitHub Actions workflow verifies that a pinned commit SHA matches a version tag, dereference annotated tags before comparing to a commit SHA. The API `GET /repos/{owner}/{repo}/git/refs/tags/{tag}` returns the tag *object* SHA for annotated tags (not the underlying commit SHA), so comparing it directly to a commit SHA will cause false mismatches. Instead: (1) fetch the tag object SHA via `GET /repos/{owner}/{repo}/git/refs/tags/{tag}`; (2) resolve that tag object to the underlying commit by calling `GET /repos/{owner}/{repo}/git/tags/{tag_object_sha}`; (3) compare the pinned commit SHA to the resolved commit at `.object.sha`.

Applied to files:

  • .github/workflows/pr.yaml
  • .github/workflows/coverity.yaml
  • .github/workflows/sonatype.yaml
  • .github/workflows/benchmarks.yaml
  • .github/workflows/unix.yaml
  • .github/workflows/linux.yaml
  • .github/workflows/sonar.yaml
  • .github/workflows/cfarm.yaml
  • .github/workflows/macos.yaml
  • .github/workflows/windows.yaml
🔇 Additional comments (10)
.github/workflows/linux.yaml (1)

14-16: LGTM!

.github/workflows/macos.yaml (1)

14-16: LGTM!

.github/workflows/windows.yaml (1)

14-16: LGTM!

.github/workflows/unix.yaml (1)

14-16: LGTM!

.github/workflows/cfarm.yaml (1)

14-16: LGTM!

.github/workflows/coverity.yaml (1)

8-10: LGTM!

.github/workflows/sonar.yaml (1)

12-14: LGTM!

.github/workflows/benchmarks.yaml (1)

17-19: LGTM!

.github/workflows/sonatype.yaml (1)

12-14: LGTM!

.github/workflows/pr.yaml (1)

11-13: LGTM!


📝 Walkthrough

Walkthrough

This PR adds explicit GitHub Actions permissions blocks with contents: read to ten workflow files across CI, security scanning, and deployment automation. Each workflow now declares minimal read-only token scope instead of relying on GitHub's default permissions.

Changes

GitHub Actions Workflow Permissions

Layer / File(s) Summary
CI platform workflows permissions
.github/workflows/linux.yaml, .github/workflows/macos.yaml, .github/workflows/windows.yaml, .github/workflows/unix.yaml, .github/workflows/cfarm.yaml
CI workflows for all supported platforms (Linux, macOS, Windows, Unix, cfarm) each declare a workflow-level permissions block restricting the GitHub token to read-only repository contents access.
Security and analysis workflows permissions
.github/workflows/coverity.yaml, .github/workflows/sonar.yaml, .github/workflows/benchmarks.yaml
Coverity Scan, SonarCloud, and benchmarks workflows explicitly set contents: read permissions at the workflow level, limiting token scope for security scanning operations.
Deployment and PR workflows permissions
.github/workflows/sonatype.yaml, .github/workflows/pr.yaml
Sonatype Snapshot Deployment and pull request workflows add explicit permissions blocks declaring read-only repository contents access for their GitHub tokens.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Ten workflows now stand proud and tall,
With permissions small, the safest of all,
Read-only tokens, locked down tight,
Security practice shining bright! 🔐✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: adding explicit permissions blocks with contents: read to multiple GitHub Actions workflows.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dbwiddis dbwiddis changed the title GHA: add explicit to all read-only workflows GHA: add explicit "permissions: contents: read" to all read-only workflows Jun 8, 2026
@dbwiddis
dbwiddis merged commit ecb7c4c into oshi:master Jun 8, 2026
2 checks passed
@dbwiddis
dbwiddis deleted the gha-permissions-tighten branch June 8, 2026 04:43
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.

1 participant