Sub topic 9
Reading permission errors
This chapter assumes you can read a workflow log, you know the permissions key from the earlier chapters, and you can use the gh CLI or call the GitHub REST API. It covers what a token permission error looks like, how to map it to the permission that is missing, and which failures a permissions change cannot fix.
What the error means
When a job calls the GitHub API and the GITHUB_TOKEN lacks the permission the endpoint needs, GitHub answers with HTTP 403 and the message Resource not accessible by integration. The "integration" is the GitHub App that issues the token for your workflow run. The message does not name the missing permission, so you have to work it out from context.
The text looks different depending on the tool:
| Tool | Typical output |
|---|---|
| `gh` CLI | `HTTP 403: Resource not accessible by integration (https://api.github.com/repos/o/r/issues/7/comments)` |
| `gh pr comment` | `GraphQL: Resource not accessible by integration (addComment)` |
| `actions/github-script` | `RequestError [HttpError]: Resource not accessible by integration` |
| `git push` | `remote: Permission to o/r.git denied to github-actions[bot].` followed by `fatal: ... error: 403` |
Treat the failing step as the starting point. The message tells you that a permission is missing, and the step tells you which API call needed it.
A worked failure
This workflow sets read-only access and then tries to comment on a pull request.
name: comment
on: pull_request
permissions:
contents: read
jobs:
hello:
runs-on: ubuntu-latest
steps:
- run: gh pr comment "$PR" --body "Thanks for the pull request"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}The step fails with GraphQL: Resource not accessible by integration (addComment). The permissions block lists only contents, so every other scope is none. Commenting on a pull request needs pull-requests: write.
Finding the missing permission
Use the same procedure each time:
- Open the failed step and find the exact call that returned 403. Note the endpoint or the GraphQL mutation name.
- Look up that endpoint in the GitHub REST API reference. Each endpoint page has a section on fine-grained access tokens that lists the permissions it accepts and the level required.
- Add the smallest accepted permission to the job that runs the step.
- Re-run the job and check that the step passes.
Check what the job actually received
Open the "Set up job" step in the log and expand the GITHUB_TOKEN Permissions group. It lists the permissions the job was given after defaults, the workflow block, and the job block were combined. Compare this list with what the endpoint needs. This tells you whether the problem is your YAML or a policy outside it.
Ask the API what it accepts
Responses from the REST API carry an x-accepted-github-permissions header. It names the permissions that the endpoint accepts. It describes the endpoint, not your token, so a mismatch between this header and the log group above is the cause of the failure. You can print it in a workflow:
name: inspect-headers
on: workflow_dispatch
permissions:
contents: read
jobs:
inspect:
runs-on: ubuntu-latest
steps:
- name: Show accepted permissions
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
run: |
gh api --include "repos/${GH_REPO}/issues?per_page=1" \
| grep -i '^x-accepted-github-permissions'The output has the form x-accepted-github-permissions: issues=read. The exact value depends on the endpoint. Some endpoints accept more than one permission. For example, commenting on a pull request through the issues API accepts either issues=write or pull_requests=write. Choose the one that fits the job, and prefer the one you would have to grant anyway.
Common causes beyond a missing scope
A permissions block is the most frequent fix, but not the only one.
Setting any key sets the rest to none
Once a permissions block lists any scope, every scope you do not list becomes none. A job that writes issues: write and also checks out code now fails at checkout, because contents is none. The checkout error usually reads repository not found, which is misleading. Add contents: read to the job.
Wrong status code: 404 instead of 403
For private repositories, GitHub often returns 404 instead of 403 when a token has no read access. If a call returns Not Found for a resource you know exists, check read permissions before you suspect the URL.
Forks and Dependabot
Workflows triggered by pull_request from a fork get a read-only token. A permissions: pull-requests: write line does not change that. Dependabot-triggered runs also default to a read-only token. In both cases the failing comment or label step needs a different design, such as a separate workflow_run workflow. The "Forks, Dependabot, and event-specific behavior" chapter covers those options.
Policy above the workflow
An organization or enterprise can cap the maximum permissions that workflows may request. If the log group shows less than your YAML asks for, the cap is the reason. Edit the policy, not the workflow.
The `workflows` permission does not exist for this token
The GITHUB_TOKEN cannot be given permission to modify files under .github/workflows. A push that changes a workflow file is rejected with a message about the workflows permission, even if contents: write is set. Use a GitHub App token or a personal access token for those cases.
A different token in the failing call
If the step passes a personal access token or an app token, the error is about that credential, not the GITHUB_TOKEN. Messages such as Resource not accessible by personal access token name the credential type. Changing the permissions block will not help.
Fixing the example
Move the write permission to the job that needs it, and leave the workflow-level default at read.
name: comment
on: pull_request
permissions:
contents: read
jobs:
hello:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- run: gh pr comment "$PR" --body "Thanks for the pull request"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
PR: ${{ github.event.pull_request.number }}The job block replaces the workflow block for this job, so it repeats contents: read. Without that line, the job would have no read access to repository contents.
A quick symptom table
| Symptom | Likely cause | First check |
|---|---|---|
| 403 on a write call in a normal push or pull request | Scope is `none` or `read` | The "Set up job" permissions group |
| 403 only on pull requests from forks | Fork tokens are read-only | The event type and source repository |
| 403 only on Dependabot pull requests | Dependabot token is read-only | The actor and event |
| Checkout fails after adding a `permissions` block | `contents` fell to `none` | Add `contents: read` |
| Push touching `.github/workflows` is rejected | `workflows` cannot be granted to this token | Use an app token |
| Log group shows less than the YAML requests | Organization or enterprise cap | Policy settings |
| 404 on a private resource | Missing read access | Read scopes first |
Exercise
A job has permissions: issues: write and nothing else. Its first step is actions/checkout@v4, and it fails with "repository not found" on a private repository. What is the cause, and what is the smallest fix?
Show answer
Setting any key in a permissions block sets every unlisted scope to none, so contents is none and checkout cannot read the private repository. The smallest fix is to add contents: read to the job's permissions, keeping issues: write.
Exercise
A step posts a comment on a pull request and fails with Resource not accessible by integration. The "Set up job" log shows Pull requests: write, but the failure happens only on pull requests opened from forks. Why does the log show write, and what does this tell you about the fix?
Show answer
The log reflects what the workflow requested, but for pull_request events from forks GitHub reduces the token to read-only, so the write is denied at run time. A bigger permissions block cannot fix this. The comment needs a different design, such as a separate workflow_run workflow that posts it.