Skip to content

chore(ci): add explicit GITHUB_TOKEN permissions to workflows#116

Merged
cbullinger merged 4 commits into
mainfrom
chore/workflow-permissions
Jun 8, 2026
Merged

chore(ci): add explicit GITHUB_TOKEN permissions to workflows#116
cbullinger merged 4 commits into
mainfrom
chore/workflow-permissions

Conversation

@cbullinger

@cbullinger cbullinger commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Summary

Resolves 8 open CodeQL actions/missing-workflow-permissions findings by declaring minimal GITHUB_TOKEN scopes on every workflow.

Changes

  • Audit workflows (audit-tanstack, audit-python-fastapi): contents: read
  • Test workflows (TanStack, Python, Express, Java): contents: read, actions: write (required for upload-artifact)
  • Security-Notification: contents: read (checkout only; Dependabot API uses DEPENDABOT_PAT)
  • new-issue-notify: permissions: {} (no GITHUB_TOKEN usage; Slack via secret only)

Test plan

Related

Made with Cursor

Set minimal permissions on all workflows to resolve CodeQL
actions/missing-workflow-permissions findings (#1-#8).

Co-authored-by: Cursor <cursoragent@cursor.com>
@cbullinger cbullinger force-pushed the chore/workflow-permissions branch from e0af6b8 to b4b4425 Compare June 4, 2026 18:21
@cbullinger cbullinger changed the base branch from development to main June 4, 2026 18:21
@cbullinger cbullinger requested a review from Copilot June 5, 2026 13:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses CodeQL actions/missing-workflow-permissions findings by explicitly declaring minimal GITHUB_TOKEN permissions across all GitHub Actions workflows in the repo.

Changes:

  • Added permissions: { contents: read } to workflows that only need repository read access (checkout/audits/security notification).
  • Added permissions: { contents: read, actions: write } to test workflows that upload artifacts via actions/upload-artifact.
  • Set permissions: {} on the issue-to-Slack notification workflow to explicitly disable GITHUB_TOKEN access.

Reviewed changes

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

Show a summary per file
File Description
.github/workflows/Security-Notification.yml Adds contents: read for checkout while using a PAT for Dependabot API calls.
.github/workflows/run-tanstack-tests.yml Adds contents: read + actions: write for artifact upload in test workflow.
.github/workflows/run-python-tests.yml Adds contents: read + actions: write for artifact upload in test workflow.
.github/workflows/run-java-spring-boot-tests.yml Adds contents: read + actions: write for artifact upload in test workflow.
.github/workflows/run-express-tests.yml Adds contents: read + actions: write for artifact upload in test workflow.
.github/workflows/new-issue-notify.yml Sets permissions: {} since the job posts to Slack without needing GitHub API access.
.github/workflows/audit-tanstack.yml Adds contents: read for checkout-only dependency audit workflow.
.github/workflows/audit-python-fastapi.yml Adds contents: read for checkout-only dependency audit workflow.

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

@dacharyc

dacharyc commented Jun 5, 2026

Copy link
Copy Markdown
Collaborator

Nice, tightly-scoped least-privilege change — the permissions: {} on new-issue-notify and contents: read on the audit/Security-Notification workflows all look correct. One thing worth double-checking before merge:

actions: write on the 4 test workflows is likely unnecessary

The PR notes actions: write is "required for upload-artifact", but I don't think that's the case. actions/upload-artifact@v4 uploads via GitHub's Results service authenticated by ACTIONS_RUNTIME_TOKEN — a separate token from GITHUB_TOKEN. The actions: write scope governs the /repos/.../actions/* REST endpoints (cancelling runs, deleting artifacts, managing workflows), none of which upload/download-artifact touch. GitHub's upload-artifact docs also list no permissions requirement, and these workflows otherwise only run actions/checkout (needs contents: read).

If that holds, all four can drop to:

permissions:
  contents: read

which keeps the change fully aligned with the least-privilege goal (granting an unused write scope is the kind of thing CodeQL nudges against).

Suggested verification: since these test workflows are heavy (Atlas CLI, sample-data restore, etc.) and only trigger on development/frameworks-tanstack, the cheapest way to confirm is a throwaway workflow on a matching branch — just checkout + write a file + upload-artifact@v4 under permissions: { contents: read } — and confirm the upload step succeeds. (Note: act/local runners can't verify this — they don't enforce GITHUB_TOKEN permission scoping at all.) If it passes, drop actions: write from all four.

upload-artifact@v4 authenticates via ACTIONS_RUNTIME_TOKEN, not
GITHUB_TOKEN actions: write. Keep contents: read only per review.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cbullinger

Copy link
Copy Markdown
Collaborator Author

Good catch — dropped actions: write from all four test workflows in d878893's follow-up commit (b4b4425 → latest).

actions/upload-artifact@v4 uploads via ACTIONS_RUNTIME_TOKEN (Results service), not the GITHUB_TOKEN actions: write scope. These workflows only need contents: read for checkout.

All four test workflows now use:

permissions:
  contents: read

@cbullinger

Copy link
Copy Markdown
Collaborator Author

Correction on commit hash above — the permissions change is in 1940d78.

Minimal checkout + upload-artifact job with contents: read only to
confirm actions: write is unnecessary. Remove after PR #116 merges.

Co-authored-by: Cursor <cursoragent@cursor.com>
@cbullinger

Copy link
Copy Markdown
Collaborator Author

Added a minimal verification workflow (verify-artifact-permissions.yml) — checkout + upload-artifact@v4 under permissions: { contents: read } only.

Result: run succeeded in 11s — https://github.com/mongodb/docs-sample-apps/actions/runs/27133317095

This confirms actions: write is not needed for artifact upload. The workflow is marked temporary in-file; we can delete it in a follow-up commit before merge (or right after merge).

Verified upload-artifact@v4 succeeds with contents: read only (run
27133317095). No need to keep the throwaway workflow in the repo.

Co-authored-by: Cursor <cursoragent@cursor.com>

@dacharyc dacharyc left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM - thanks for updating the perms! ✅

@cbullinger cbullinger merged commit 569a7b3 into main Jun 8, 2026
6 checks passed
@cbullinger cbullinger deleted the chore/workflow-permissions branch June 8, 2026 13:56
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