Skip to content

[no-ci] ci: restrict PR metadata check token to pull-request read access - #2081

Open
arpitjain099 wants to merge 3 commits into
NVIDIA:mainfrom
arpitjain099:chore/ci-permissions
Open

[no-ci] ci: restrict PR metadata check token to pull-request read access#2081
arpitjain099 wants to merge 3 commits into
NVIDIA:mainfrom
arpitjain099:chore/ci-permissions

Conversation

@arpitjain099

Copy link
Copy Markdown

pr-metadata-check.yml runs on pull_request_target and uses gh pr view --json assignees,labels,milestone to enforce PR hygiene. It only reads PR metadata, no checkout. Adding contents: read (for the implicit checkout if it gets re-added later) plus pull-requests: read (for the gh pr view call) caps the otherwise-inherited token scope on pull_request_target.

@copy-pr-bot

copy-pr-bot Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions github-actions Bot added the CI/CD CI/CD infrastructure label May 13, 2026
Comment thread .github/workflows/pr-metadata-check.yml Outdated
@@ -17,6 +17,10 @@ on:
- reopened
- ready_for_review

permissions:
contents: read

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I asked Cursor GPT-5.4 Extra High Fast if read (in general) is sufficient. After fetching a bunch of GHA API documentation, it came back with a "yes", but it isn't sure if the contents: read is actually required.

@arpitjain099: since this workflow only reads PR metadata via gh pr view and does not check out code, do you know whether pull-requests: read alone is sufficient, or whether contents: read is also required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good question. The workflow only calls gh pr view, which goes through the REST API and doesn't touch repo contents, so pull-requests: read alone is sufficient. I left contents: read in as future-proofing in case a checkout step ever gets added, but happy to drop it for the minimum scope if you prefer. Either works for the CVE-2025-30066 hardening intent.

@leofang leofang added the triage Needs the team's attention label May 16, 2026
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@arpitjain099
arpitjain099 force-pushed the chore/ci-permissions branch from 8af3fb2 to fc6baf9 Compare June 10, 2026 07:18
@rwgk
rwgk marked this pull request as draft August 16, 2026 05:29
@rwgk rwgk changed the title chore: declare minimum scope on pr-metadata-check workflow ci: restrict PR metadata check token to pull-request read access Aug 16, 2026
@rwgk rwgk added this to the cuda.bindings next milestone Aug 16, 2026
@rwgk rwgk added the P1 Medium priority - Should do label Aug 16, 2026
@rwgk rwgk assigned arpitjain099 and unassigned rwgk Aug 16, 2026
@rwgk

rwgk commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

We (that's codex gpt-5.6-sol ultra & rwgk) took a careful second look at this PR, including the workflow's actual API use, GitHub's pull_request_target trust model, and both accidental and adversarial failure modes. We confirmed that the overall change is sound and meaningfully improves the workflow's security posture.

We also confirmed that contents: read is best removed. The workflow does not check out or read repository contents; its only authenticated operation reads PR metadata via gh pr view. Keeping only pull-requests: read therefore matches the current requirement and makes any future need for repository-content access an explicit, reviewable change.

Background considered (optional reading)

General workflow hygiene. Declaring permissions explicitly documents what the job needs, avoids inheriting broader repository defaults, and sets every unspecified configurable permission to none. This is a small, auditable allow-list rather than an implicit grant of authority.

Capability Before, in the actual latest run After merge
Read PR metadata Yes Yes
Read repository contents via GITHUB_TOKEN Yes No
Modify PRs or issues Yes No
Push repository contents or create releases Yes No
Manage Actions, checks, statuses, or packages Yes No

Preventing accidents. A mistaken command or future workflow edit cannot mutate repository state unless someone first expands the declared permissions. The failing authorization then acts as a useful review tripwire instead of allowing an accidental write.

Guarding against attacks. This is meaningful defense in depth, particularly for a pull_request_target workflow. GitHub takes the active workflow and its permissions from the trusted base repository's default branch, so a fork author cannot remove the restriction for their own run merely by changing it in their PR. If an attacker nevertheless gained code execution or stole the job token, that token would remain limited to reading PR metadata and could not promote its own permissions or write to the repository. This does not replace protection of the default branch or prevent code execution itself, but it substantially reduces the damage a compromised job could do.

The current workflow already has a small attack surface: it does not check out or execute PR code, uses no third-party Action, and exposes no separate credential. The explicit minimum permission complements those safeguards by limiting the blast radius of future regressions or supply-chain compromise.

@rwgk rwgk changed the title ci: restrict PR metadata check token to pull-request read access [no-ci] ci: restrict PR metadata check token to pull-request read access Aug 16, 2026
@rwgk
rwgk marked this pull request as ready for review August 16, 2026 06:29

@rwgk rwgk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@arpitjain099 sorry for the long delay, this totally slipped my attention.

@rwgk
rwgk enabled auto-merge (squash) August 16, 2026 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure P1 Medium priority - Should do triage Needs the team's attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants