Skip to content

ci: add least-privilege permissions to remaining workflows#1451

Open
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/workflow-permissions-hardening
Open

ci: add least-privilege permissions to remaining workflows#1451
bmehta001 wants to merge 1 commit into
microsoft:mainfrom
bmehta001:bhamehta/workflow-permissions-hardening

Conversation

@bmehta001
Copy link
Copy Markdown
Contributor

What

Adds top-level permissions: { contents: read } to the six sister workflows that lacked an explicit GITHUB_TOKEN scope, scoping the token to the minimum needed for actions/checkout.

File Job purpose Scope
build-android.yml Android build + artifact upload contents: read
build-ios-mac.yml iOS/macOS build matrix contents: read
build-posix-latest.yml Linux/Mac build matrix contents: read
build-ubuntu-2204.yml Ubuntu 22.04 build contents: read
build-windows-vs2022.yaml Visual Studio 2022 build contents: read
test-win-latest.yml Windows unit/functional tests contents: read

Why

Carry-forward from #1450 (which hardened spellcheck.yml). Without an explicit permissions: block, GITHUB_TOKEN inherits the repo default — broader than needed. None of these jobs:

  • Post PR comments or status updates.
  • Deploy artifacts via the token (actions/upload-artifact@v4 uses its own per-run SAS, not GITHUB_TOKEN).
  • Write to releases, packages, or pages.

So contents: read (just enough for actions/checkout@v4) is sufficient everywhere.

Each comment also names the CodeQL rule it satisfies (actions/missing-workflow-permissions) if Actions language analysis is later added to this repo's codeql-analysis.yml matrix — currently it's [cpp, javascript, python] + Java only, which is why these don't appear as code-scanning alerts today.

Mirrors the analogous modules-repo commit decc96501 (in modules PR #320), which closed 4 outstanding missing-workflow-permissions alerts there.

Not touched

Validation

  • All six files YAML-parse cleanly with permissions: {contents: read} at the top level.
  • No behavior change: triggers, jobs, runners, steps unchanged.
  • Per-file line-ending convention preserved (build-android.yml was CRLF upstream; rest are LF; my blobs match).
  • Existing CI on this branch will exercise the workflows and confirm the token scope still allows checkout.

References

Adds top-level `permissions: { contents: read }` to the six workflow
files on `main` that lacked an explicit GITHUB_TOKEN scope:

  - .github/workflows/build-android.yml
  - .github/workflows/build-ios-mac.yml
  - .github/workflows/build-posix-latest.yml
  - .github/workflows/build-ubuntu-2204.yml
  - .github/workflows/build-windows-vs2022.yaml
  - .github/workflows/test-win-latest.yml

All six only check out source and run builds or tests; none post PR
comments, deploy artifacts via the token, or otherwise need write
scopes. `actions/upload-artifact@v4` (build-android.yml) uses its own
per-run SAS URL and does not require GITHUB_TOKEN scopes.

Carry-forward from PR microsoft#1450, which hardened spellcheck.yml the same
way, and mirrors the analogous modules-repo commit decc96501. Each
file gets an explanatory comment naming the CodeQL rule it satisfies
(actions/missing-workflow-permissions) if Actions analysis is later
enabled in this repo's code-scanning config. No behavior change.

Already-permissioned workflows (codeql-analysis.yml, deploy-docs-pages.yml)
are not touched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 requested a review from a team as a code owner May 27, 2026 13:20
@bmehta001 bmehta001 requested a review from Copilot May 27, 2026 13:20
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds top-level least-privilege permissions: { contents: read } blocks to six CI workflows that previously inherited the repo default GITHUB_TOKEN scope. None of these workflows post comments, publish releases/packages, or write via the token, so contents: read is sufficient for actions/checkout. This mirrors the hardening pattern from PR #1450 (spellcheck) and modules PR #320.

Changes:

  • Add permissions: { contents: read } top-level block to six workflows.
  • Add explanatory comments referencing the CodeQL actions/missing-workflow-permissions rule.
  • No changes to triggers, jobs, runners, or steps.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.github/workflows/build-android.yml Adds least-privilege permissions block before concurrency:
.github/workflows/build-ios-mac.yml Adds least-privilege permissions block before concurrency:
.github/workflows/build-posix-latest.yml Adds least-privilege permissions block before concurrency:
.github/workflows/build-ubuntu-2204.yml Adds least-privilege permissions block before concurrency:
.github/workflows/build-windows-vs2022.yaml Adds least-privilege permissions block before jobs:
.github/workflows/test-win-latest.yml Adds least-privilege permissions block before concurrency:

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

2 participants