Skip to content

fix: grant contents permission in job-level permission blocks - #47

Merged
zepeng811 merged 1 commit into
circlefin:masterfrom
polochang-circle:fix/restore-job-contents-permission
Nov 13, 2026
Merged

zepeng811 merged 1 commit into
circlefin:masterfrom
polochang-circle:fix/restore-job-contents-permission

Conversation

@polochang-circle

@polochang-circle polochang-circle commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The pr-scan and attach-release-assets jobs declare a job-level permissions block that lists id-token: write only. GitHub uses a job-level block as the full permission set for that job. The workflow-level permissions block does not apply.

The GITHUB_TOKEN of these jobs therefore holds metadata: read only. This breaks two cases:

  1. pr-scan: actions/checkout cannot clone a private calling repository. The step fails with fatal: repository '<owner>/<repo>' not found. The dependency review step also cannot post its pull request comment.
  2. attach-release-assets: the job cannot create a release or upload assets, because the token has no contents: write.

A public calling repository does not show the first failure, because actions/checkout can clone a public repository without a token.

v1.3.5 has no job-level block, so every job inherits the workflow-level permissions. The v1 tag points to v1.3.5 today, so current @v1 callers do not see this defect. Callers see it after the v1 tag moves to a later version.

Change

This PR adds the permissions that each job needs to its job-level block:

Workflow Job Before After
pr-scan.yaml scan id-token: write contents: read, pull-requests: write, id-token: write
attach-release-assets.yaml release_attach_assets id-token: write contents: write, id-token: write
  • contents: read lets actions/checkout clone the calling repository.
  • pull-requests: write lets the dependency review step post its summary comment. The step sets comment-summary-in-pr: always.
  • contents: write lets the release job create a release and upload assets.
  • id-token: write stays for the step-security/harden-runner step.

The README now states that a calling job must grant id-token: write. GitHub does not let a reusable workflow request more permission than its caller grants. Without that grant, the run fails before any job starts.

Relation to #37

#37 adds a workflow-level permissions: contents: read block to pr-scan.yaml. That block does not reach the scan job, because the job declares its own block. I tested the head commit of #37 from a private calling repository. The token still held metadata: read only, and actions/checkout failed.

Scope

actions-lint.yaml and conventional-commit-release.yaml use the same job-level pattern. This PR does not change them, because I cannot test them from a calling repository. They may need the same fix.

Testing

I tested commit 5765788 from a private calling repository. The calling jobs used the permissions blocks from the README example.

Check Before (#37 head) After (this PR)
Token permissions in scan Metadata: read Contents: read, Metadata: read, PullRequests: write
Checkout Source failed, repository not found passed
Dependency review step did not run passed
Summary comment on the pull request not posted posted

The calling workflow referenced the commit through the fork. GitHub Actions does not resolve a fork commit through the parent repository, so a circlefin/...@5765788 reference fails before the run starts.

I did not run attach-release-assets from a calling repository. That job runs only on a push to the default branch. The change to that job uses the same rule as the scan job.

The checks of this repository pass on this PR.

🤖 Generated with Claude Code

The pr-scan and attach-release-assets jobs declare a job-level
permissions block with id-token: write only. A job-level block replaces
the full token permission set, so the workflow-level permissions do not
apply to these jobs.

As a result, the token has metadata: read only. actions/checkout cannot
clone a private calling repository, and the release job cannot upload
assets.

Add the permissions that each job needs to its job-level block:

- pr-scan: contents: read, pull-requests: write, id-token: write
- attach-release-assets: contents: write, id-token: write

Document in the README that a calling job must grant id-token: write.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zepeng811
zepeng811 merged commit cc86511 into circlefin:master Nov 13, 2026
6 checks passed
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