Sub topic 2
Permission scopes you will use most
Assume you know basic GitHub Actions YAML, including on, jobs, and steps. The GITHUB_TOKEN uses named permission scopes. Each scope controls one kind of repository or workflow access.
| Scope | Typical use |
|---|---|
| `contents` | Check out code or create commits |
| `pull-requests` | Read, label, or update pull requests |
| `issues` | Create or edit issues and comments |
| `packages` | Publish or download packages |
| `actions` | Manage workflow runs and artifacts |
| `id-token` | Request an OIDC token for a cloud provider |
A scope can usually be read or write. Grant write only when a step changes data.
Starting from no permissions
Use an empty permissions block when you want every job to begin with no GITHUB_TOKEN access:
permissions: {}A job can still run commands that do not need GitHub API access. For example, compiling code and running tests usually need no token permissions. Actions that call GitHub APIs will fail unless their required scope is granted.
Restricting at workflow level, elevating per job
Set the common minimum at workflow level. Then give a specific job extra access:
name: checks-and-labels
on: [pull_request]
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: make test
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/labeler@v5The test job can read repository contents. The label job also can write pull-request metadata. Repeat required permissions at job level because a job-level block defines that job's effective permissions.
Finding the minimal set for a job
Inspect every step and identify the GitHub resource it accesses. Start with permissions: {}, run the job, and add the smallest missing scope. An error such as Resource not accessible by integration usually means the token lacks the required scope, or the event provides a restricted token.
For example, checkout commonly needs contents: read; publishing to GitHub Container Registry needs packages: write. Do not grant contents: write merely because a job reads source files.
Exercise
A job checks out code, runs tests, and adds a pull-request label. What permissions should it request?
Show answer
Use contents: read and pull-requests: write. Tests need no additional GitHub permission.