/errors/github-actions/resource-not-accessible-by-integration
GitHub Actions: Resource not accessible by integration (HTTP 403)
- tool
- GitHub Actions
- exit code
- 1
- versions
- GitHub Actions
- os
- any
Every workflow run gets a GITHUB_TOKEN. Its permissions come from the permissions: key, or from the repository default when the key is missing. When a step calls the GitHub API (through gh, actions/github-script or an action) with a scope the token does not have, the API answers 403 and the step fails with Resource not accessible by integration.
Fix: grant the scope the job needs
name: PR comment
on: pull_request
permissions:
contents: read
pull-requests: write # needed to comment on or label pull requests
jobs:
comment:
runs-on: ubuntu-latest
steps:
- run: gh pr comment "$PR" --body "Thanks!"
env:
GH_TOKEN: ${{ github.token }}
PR: ${{ github.event.pull_request.html_url }}When you set permissions, every scope you do not list becomes none, so list contents: read too if the job checks out code.
Scopes for common tasks
| Task | Permission |
|---|---|
| comment on or label a pull request | pull-requests: write |
| comment on or label an issue | issues: write |
| push commits or tags, create releases | contents: write |
| publish to GitHub Packages / ghcr.io | packages: write |
| set commit statuses | statuses: write |
| request an OIDC token for cloud login | id-token: write |
| upload code scanning results | security-events: write |
Pull requests from forks
For pull_request events from forks, GITHUB_TOKEN is read-only and secrets are not available, whatever the workflow requests. This protects the repository from code in the pull request. If such runs must write (for example to post test results), split the work: run the tests on pull_request, then post the results from a workflow_run workflow that does not execute the PR's code.
Sources
- docs.github.comdocs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
- docs.github.comdocs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#permissions
- docs.github.comdocs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#pull_request