Skip to content

GHA: tighten secret + permission scoping - #3359

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gha-secrets-audit-cleanup
Jun 8, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:gha-secrets-audit-cleanup

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Jun 8, 2026 •

Copy link
Copy Markdown
Member

Summary

Three small security-hardening tweaks to the workflows, continuing the audit started in #3357:

  • sonatype.yaml — deploy secrets (CI_DEPLOY_USERNAME, CI_DEPLOY_PASSWORD, NVD_API_KEY) moved from job-level env: to the Deploy to Sonatype step's env:. Same effective behavior today, but they're no longer in scope for any future step a contributor might add before the deploy.
  • codeql-analysis.yml — adds workflow-level permissions: {} so the analyze job's actions: read / contents: read / security-events: write are explicit additive grants rather than trimming from GitHub's broad default. Mirrors the default-deny pattern shipped in GHA: add explicit "permissions: contents: read" to all read-only workflows #3357 for the other workflows.
  • macos.yaml, windows.yaml — drops GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} from the test step env:. The tests don't reference it and the equivalent Linux / PR / Unix test steps don't pass it. sonar.yaml and site.yaml legitimately need it (PR decoration, gh-pages push) and are unchanged.

Audit-item progress

This PR resolves two of the three follow-ups noted on #3357's PR description:

  • per-job permission tightening (covered for codeql-analysis.yml; all other workflows are single-job with appropriate permissions: contents: read)
  • step-level secret scoping (sonatype.yaml)
  • OIDC for Sonatype publishing — deferred; needs separate research

Action SHA-pinning audit also re-confirmed clean: all 71 uses: lines in .github/workflows/ are SHA-pinned.

Test plan

  • All five modified files parse as valid YAML (yaml.safe_load)
  • CodeQL workflow trigger and job structure unchanged — only the workflow-level permissions block is added
  • Sonatype workflow's secrets are now referenced at step level; deploy command unchanged
  • macOS/Windows test commands unchanged; only the unused GITHUB_TOKEN env removed
  • PR CI passes on this branch (sanity check that none of the macOS/Windows test runs were silently depending on GITHUB_TOKEN)

Summary by CodeRabbit

  • Chores
    • Improved security infrastructure by adopting a default-deny permissions model and scoping sensitive credentials to individual workflow steps in continuous integration pipelines.
    • Refined GitHub Actions workflows for enhanced consistency and optimized performance across multiple operating system testing environments and deployment operations.

- sonatype.yaml: deploy secrets moved from job-level env to the Deploy
  step's env so they're not in scope for any future step added before
  the deploy.
- codeql-analysis.yml: add workflow-level `permissions: {}` so the
  job's elevated grants (security-events: write etc.) are explicit
  additive overrides instead of trimming from the broad default.
- macos.yaml, windows.yaml: drop unused `GITHUB_TOKEN` env from test
  steps. Other workflows' test steps don't pass it and the tests don't
  reference it.
@coderabbitai

coderabbitai Bot commented Jun 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR hardens CI workflows by applying least-privilege access controls across four GitHub Actions workflow files. CodeQL adds default-deny permissions, Sonatype scopes secrets to specific deployment steps, and macOS/Windows reorganize test steps to isolate environment variables for JDK 25 aggregate coverage runs.

Changes

Workflow Security Hardening

Layer / File(s) Summary
Workflow-level permission defaults
.github/workflows/codeql-analysis.yml
CodeQL workflow adds permissions: {} at workflow level to enforce default-deny permissions model, requiring each job to explicitly grant only the permissions it needs.
Deployment secret scoping
.github/workflows/sonatype.yaml
Sonatype workflow moves deployment secrets (CI_DEPLOY_USERNAME, CI_DEPLOY_PASSWORD, NVD_API_KEY) from job-level env to the "Deploy to Sonatype" step-level env, limiting their availability scope to that specific deployment step.
Test step environment isolation
.github/workflows/macos.yaml, .github/workflows/windows.yaml
macOS and Windows workflows refactor aggregate coverage test steps for JDK 25 to run conditionally as dedicated steps without inheriting inline GITHUB_TOKEN environment configuration, removing the previous aggregate-coverage blocks.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • oshi/oshi#3156: Main PR that introduced the JDK 25 aggregate-coverage Maven profile changes that these workflow updates now properly isolate in CI.

Poem

🐰 A rabbit hops through secrets tight,
default-deny makes workflows right,
Scope those tokens, step by step,
Least privilege keeps the castle kept!
✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'GHA: tighten secret + permission scoping' clearly and concisely summarizes the main changes: adding workflow-level default-deny permissions in CodeQL, moving deployment secrets to step-level scope in Sonatype, and removing unused GITHUB_TOKEN references.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ 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 merged commit 9bdd0ee into oshi:master Jun 8, 2026
2 checks passed
@dbwiddis
dbwiddis deleted the gha-secrets-audit-cleanup branch June 12, 2026 01:08
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