Sub topic 5
Permission scopes you will use most
This chapter assumes you can read a workflow file and know that the permissions key sets what the GITHUB_TOKEN may do. Earlier chapters covered the key and its access levels. This one covers what each common scope allows, which actions need it, and how to pick the right one.
How scopes and levels fit together
Each scope names one area of the GitHub API, such as contents or issues. Each scope takes one of three levels:
nonegrants no access.readgrants read-only access.writegrants read and write access. Write includes read, so you never declare both.
Two rules matter in every example below:
- Once you declare any scope in a
permissionsblock, every scope you leave out becomesnone. - The token always has read access to repository metadata, even when everything else is
none. You never need to declare it.
The scopes at a glance
| Scope | `read` allows | `write` allows | Typical user |
|---|---|---|---|
| `contents` | Checking out code, reading releases | Pushing commits and tags, creating releases | `actions/checkout`, release jobs |
| `pull-requests` | Reading pull requests and reviews | Commenting, labeling, requesting reviews, merging | Labelers, bots that comment |
| `issues` | Reading issues | Creating, commenting on, labeling, closing issues | Triage bots, stale-issue closers |
| `packages` | Pulling from GitHub Packages | Pushing to GitHub Container Registry and other registries | Image and package publishing |
| `actions` | Listing runs, artifacts, and caches of other runs | Cancelling runs, deleting caches and artifacts | Cleanup and monitoring jobs |
| `checks` | Reading check runs | Creating and updating check runs | Custom CI reporters |
| `statuses` | Reading commit statuses | Setting commit statuses | Older integrations that report status |
| `security-events` | Reading code scanning alerts | Uploading SARIF results | CodeQL and other scanners |
| `deployments` | Reading deployments | Creating deployments and their statuses | Deployment tooling |
| `pages` | Reading Pages configuration | Deploying to GitHub Pages | `actions/deploy-pages` |
| `id-token` | Not available | Requesting an OIDC token | Cloud logins without stored secrets |
Other scopes exist, including attestations, discussions, models, and repository-projects. You will use them less often. The id-token scope accepts only write or none, and a later chapter covers it in detail.
contents
contents is the scope you will declare most often. contents: read lets actions/checkout download your code. A workflow that only builds and tests needs nothing more.
contents: write is a much bigger grant. It lets a step push to branches, create tags, and publish releases. Give it only to jobs that must do those things, such as a job that runs gh release create. A job that merely reads the repository should not have it.
In a private repository, even checkout needs contents: read. If you set permissions: {} and then add a checkout step, the step fails.
pull-requests and issues
Pull requests and issues share part of the API, which causes confusion. Comments and labels on a pull request go through the issues endpoints, but GitHub accepts either pull-requests: write or issues: write for pull request comments and labels. Use pull-requests: write for jobs that act on pull requests. Use issues: write for jobs that act on issues only.
This job comments on a pull request and nothing else:
name: welcome
on: pull_request
permissions: {}
jobs:
comment:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/github-script@v7
with:
script: |
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
body: 'Thanks for the contribution. A maintainer will review it soon.'
});The job has no contents permission and no checkout step, so it never reads the code. That is deliberate: the job only needs to talk to the API.
packages
packages: write lets a job push images to GitHub Container Registry (ghcr.io) or publish packages. Pulling a private package needs packages: read. Keep this scope on the job that publishes, not at workflow level, because every step in a job with packages: write can overwrite your published artifacts.
If the package is linked to your repository, the GITHUB_TOKEN can usually push to it. A package created outside the repository may need its access settings adjusted in the package settings.
actions
Many people add actions: write to a workflow by habit. Usually it is unnecessary. These tasks need no actions permission:
- Uploading and downloading artifacts within the same run with
actions/upload-artifactandactions/download-artifact. - Saving and restoring caches with
actions/cache.
You need the scope for operations that touch other runs, such as gh run list, gh run cancel, deleting old caches, or downloading an artifact from a different run.
security-events, checks, and statuses
These three report results back to GitHub:
security-events: writelets a job upload SARIF files, which is how code scanning shows alerts in the Security tab.checks: writelets a job create check runs, the entries with annotations in the pull request checks list.statuses: writesets the older commit status, a single colored dot with a description.
A CodeQL job looks like this:
name: codeql
on:
push:
branches: [main]
permissions: {}
jobs:
analyze:
runs-on: ubuntu-latest
permissions:
contents: read
security-events: write
actions: read
steps:
- uses: actions/checkout@v4
- uses: github/codeql-action/init@v3
with:
languages: python
- uses: github/codeql-action/analyze@v3security-events: write uploads the results. contents: read allows checkout. actions: read lets the CodeQL action read workflow run details in private repositories. Public repositories often run fine without it, but declaring it does no harm.
deployments, pages, and id-token
Deploying to GitHub Pages with actions/deploy-pages needs two scopes together: pages: write to publish and id-token: write so the action can prove the deployment comes from your workflow. Without both, the deploy step fails.
deployments: write is for tools that create deployment records through the API. A job that uses an environment: key does not need it just to run, because environments are handled by the workflow engine.
Choosing the scope from the task
Work from the action you want to perform, then pick the narrowest scope that covers it.
Common mistakes
- Writing
writefor a read task. Reading a pull request's files needspull-requests: read, notwrite. - Forgetting that omitted scopes become
none. If you add onlypull-requests: writeand then a step needs to check out code, it fails in a private repository. - Confusing
issuesandpull-requests. If a comment on a pull request fails with one scope, check that the job has either scope atwrite. - Putting
writeat workflow level. Every job inherits it. Declare write scopes on the job that needs them.
A complete example of the last point is the image publishing job, where only the publishing job holds the write scope:
name: publish-image
on:
push:
tags: ['v*']
permissions:
contents: read
jobs:
push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}Exercise
A job runs on pull requests in a private repository. It checks out the code, then uses a script to add a label to the pull request. Which permissions block should it declare, and why would permissions: { pull-requests: write } alone fail?
Show answer
It should declare contents: read and pull-requests: write. Declaring any scope sets every omitted scope to none, so a block with only pull-requests: write leaves contents at none. The checkout step then cannot read the private repository and fails.
Exercise
Which scopes does a job need to deploy a site with actions/deploy-pages, and which scope would you expect to need for uploading and downloading artifacts between jobs of the same run?
Show answer
The deploy job needs pages: write and id-token: write. Passing artifacts between jobs of the same run needs no actions scope, because actions/upload-artifact and actions/download-artifact work within the run without it.