Skip to content

ci: least-privilege permissions for all workflows + harden spellcheck install#1451

Open
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/workflow-permissions-hardening
Open

ci: least-privilege permissions for all workflows + harden spellcheck install#1451
bmehta001 wants to merge 2 commits into
microsoft:mainfrom
bmehta001:bhamehta/workflow-permissions-hardening

Conversation

@bmehta001
Copy link
Copy Markdown
Contributor

@bmehta001 bmehta001 commented May 27, 2026

What

Adds an explicit least-privilege permissions: block to every workflow in .github/workflows/ that previously lacked one, and hardens spellcheck.yml's misspell install.

(Originally two PRs — #1451 for the 6 build/test workflows, #1450 for the spellcheck hardening. Folded into this one PR per maintainer request to ease review.)

Why

  • Least-privilege GITHUB_TOKEN. Without an explicit permissions: block, workflows inherit the repo default scope (typically read+write on most APIs), which is far broader than any of these jobs need. None of the affected workflows post PR comments, deploy artifacts via GITHUB_TOKEN, or otherwise write through it.
  • Mitigates actions/missing-workflow-permissions CodeQL findings if Actions analysis is later added to the matrix here (already part of the modules-repo CodeQL config).
  • Mirrors the same hardening already shipped in the sister modules repo (commits 8d26e4882 and decc96501 on PR microsoft/cpp_client_telemetry_modules#320).
  • spellcheck.yml install was a supply-chain risk. The prior curl https://git.io/misspell | sh pattern executed a shell script from the master branch of an external repo via a git.io redirect — both non-reproducible and trivially modifiable upstream without notice.

Changes

Workflows getting a new permissions: contents: read block (6 files)

Workflow Reason contents: read is sufficient
build-android.yml Build only; actions/upload-artifact@v4 uses its own per-run SAS URL, not GITHUB_TOKEN
build-ios-mac.yml Build only
build-posix-latest.yml Build only
build-ubuntu-2204.yml Build only
build-windows-vs2022.yaml Build only
test-win-latest.yml Test only

Each file gets a short explanatory comment naming the CodeQL rule it satisfies.

spellcheck.yml (1 file) — three fixes

  1. Add permissions: contents: read. misspell only reads .md / .txt / examples/** / lib/** (excluding json.hpp) / tests/** and prints typos to stdout.
  2. Replace curl https://git.io/misspell | sh with a pinned tarball download of misspell v0.3.4 from GitHub releases.
  3. Verify the tarball SHA256 against the published checksum (afd95caf1eecc72ff382791e00b3b11523a20b0579d95e2295c1c043688743d5, linux_64bit). Any tampering or unexpected upstream change fails CI rather than silently running.

The set of files scanned by misspell is unchanged.

Workflows deliberately NOT touched

Workflow Why
codeql-analysis.yml Already has a permissions: block
deploy-docs-pages.yml Already has a permissions: block (and legitimately needs pages: write / id-token: write)

Testing

  • All 6 + 1 workflow files YAML-parse cleanly.
  • Build for Android > Checkout step succeeded in CI on the original bhamehta/workflow-permissions-hardening push → confirms contents: read is sufficient for actions/checkout@v4.
  • The spellcheck run on the original bhamehta/spellcheck-hardening push passed end-to-end with the pinned tarball + SHA verification.

CI signal on this branch (after consolidation)

The two PRs separately reproduced two pre-existing infra flakes that are unrelated to the changes here:

  • Analyze (cpp) (CodeQL) has been timing out across main and most PRs (4–6 h runtimes); see runs 26551009149, 26302618182, 26393096056 on main. The error is CodeQL is out of memory on the Windows runner — a runner-sizing/CodeQL-version issue, not a code defect.
  • build (release, ubuntu-latest) hit a 6 h job-timeout cancellation on one of the prior runs; the same path passed on the other PR's run.

Both are well-known infra flakes; not caused by anything in this diff. Happy to re-run after consolidation if needed.

@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.

bmehta001 and others added 2 commits May 28, 2026 10:23
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>
Three hardening fixes for .github/workflows/spellcheck.yml, ported
from the same audit applied to the sister modules repo:

1. Add top-level 'permissions: contents: read'. Without an explicit
   block, the GITHUB_TOKEN inherits the repo default (typically
   read+write across most APIs), which is far more than misspell
   needs. misspell only walks .md/.txt/lib/tests files and prints
   typos to stdout; it never comments on PRs, posts statuses, or
   writes packages. This also satisfies CodeQL rule
   'actions/missing-workflow-permissions' if Actions analysis is
   enabled here later (it isn't in the current codeql-analysis.yml
   matrix, but no reason to wait for that).

2. Replace the unpinned bootstrap install with a pinned tarball
   download. The prior 'curl https://git.io/misspell | sh' pattern
   executed a shell script from the master branch of an external
   repo via a git.io redirect — a supply-chain risk that also made
   CI non-reproducible. Now we download a specific release artifact
   (v0.3.4) directly from GitHub releases.

3. Verify the tarball SHA256 against the published checksum
   'afd95caf1eecc72ff382791e00b3b11523a20b0579d95e2295c1c043688743d5'
   (linux_64bit). Any tampering or unexpected upstream change will
   fail CI rather than silently execute.

Scope of misspell unchanged: still scans .md, .txt, examples/**, all
of lib/ (excluding json.hpp), and tests/**.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@bmehta001 bmehta001 force-pushed the bhamehta/workflow-permissions-hardening branch from 974b610 to a4885a4 Compare May 28, 2026 15:23
@bmehta001 bmehta001 changed the title ci: add least-privilege permissions to remaining workflows ci: least-privilege permissions for all workflows + harden spellcheck install May 28, 2026
@bmehta001 bmehta001 requested a review from Copilot May 28, 2026 17:23
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

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

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