GitHub Actions permissions: least privilege for GITHUB_TOKEN
Last reviewed: 23 November 2026, against SecureCI CLI 1.4.0
Every job in a GitHub Actions workflow gets a GITHUB_TOKEN. Without a permissions: block it gets the repository or organisation default, which on many repositories is read/write on every scope. Set permissions: contents: read (or permissions: {}) at the top of the workflow. Then add write scopes only on the job that needs them. Finally, check it automatically, so a new workflow cannot quietly fall back to the default.
Short answer:
- Default to read-only: put
permissions: contents: readat the top level of every workflow. - Write per job: give
contents: write(or another write scope) only to the job that writes. Job-level permissions replace the top-level block. - Check:
secureci validatereports missing and over-broad permissions with the exact path. - Enforce: a pipeline contract with
permissions: { required: true, max: { contents: read } }turns those warnings into errors.
What the GITHUB_TOKEN can do by default
GitHub creates a GITHUB_TOKEN for each job. Steps use it to check out code, push tags or create releases. What it is allowed to do depends on the permissions: keys in the workflow.
If neither the workflow nor the job declares permissions:, the token gets the default set for the repository or organisation. On many repositories that default is read/write on every scope. Every step in the job can use the token, including third-party actions. So one compromised action could use that token to push code, even in a job that only runs tests.
An administrator can change the default in the repository or organisation settings. GitHub documents that setting in managing GitHub Actions settings for a repository, and the token itself in GITHUB_TOKEN. A permissions: block in the workflow file is still worth having. It puts the token’s access in the file, where every reviewer sees it in the pull request.
Set a read-only default at the top of the workflow
The top-level permissions: block applies to every job that does not declare its own. You have three restrictive choices:
# No access at all
permissions: {}
# Read access to every scope
permissions: read-all
# Only the scopes the jobs need (usually the best choice)
permissions:
contents: read
A mapping of read and none scopes is usually the best fit, because it names exactly what the jobs use. permissions: {} is tighter still, but only suits workflows where no job needs the token. read-all is simpler but still grants read on scopes no job needs. The full list of scopes is in GitHub’s workflow syntax reference.
Avoid permissions: write-all at the top level. It gives every job write access to every scope, which is the problem you are trying to fix.
Grant write scopes per job
Some jobs do need to write. A release job pushes tags. A labelling job writes to pull requests. Give those jobs their own permissions: block and leave the top level read-only.
Job-level permissions replace the top-level block
This is the detail most guides skip. Job-level permissions do not add to the top-level ones. They replace them. If the top level says contents: read and pull-requests: read, and a job declares only contents: write, that job no longer has pull-requests: read.
So when you move a write scope to a job, repeat the read scopes that job still needs. The GitHub Action example further down does this: its job repeats contents: read next to the scopes it adds.
Example: a test job and a release job
This is the example from the GITHUB_TOKEN permissions section of the docs. The test job runs with a read-only token. Only the release job can write:
name: Release
on: push
permissions:
contents: read # every job: read-only
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: npm test
release:
needs: test
runs-on: ubuntu-latest
permissions:
contents: write # only this job can push tags and create releases
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: npm run release
If the test job is ever compromised, its token cannot push. The write scope exists only while the release job runs.
Find over-broad permissions with secureci validate
Fixing one workflow by hand is easy. Knowing that every workflow in a repository is fixed is harder. The free SecureCI CLI (secureci) checks this for you. Install it with npm install -g @secureci/cli (Node.js 20 or later), or use the standalone binary. Then run:
secureci validate .github/workflows/release.yml
The four findings
secureci validate reports four cases where the token is broader than it needs to be. Each finding names the path in the file:
| Finding | Reported at | When |
|---|---|---|
| No permissions declared | permissions | No top-level block, and at least one job has none either. The message names those jobs. |
write-all at the top level | permissions | Every job gets write access to every scope. |
| A write scope at the top level | permissions.<scope> | For example contents: write, which then applies to every job. |
write-all on a job | jobs.<id>.permissions | That job’s token can write to every scope. |
Here is a release workflow with contents: write at the top level and permissions: write-all on its release job. This is the real output of CLI 1.4.0, run with --offline (the line about the advisory lookup is left out):
$ secureci validate .github/workflows/release.yml --offline
[INFO] Validating workflow: .github/workflows/release.yml
✓ Validation passed: .github/workflows/release.yml
[WARN] [WARNING] permissions.contents: Workflow-level "contents: write" applies to every job. Declare it on the job(s) that need it instead (job-level permissions replace the top-level ones)
[WARN] [WARNING] jobs.release.permissions: Job "release" uses permissions: write-all, giving its GITHUB_TOKEN write access to every scope. List only the scopes it needs
A workflow with no permissions: at all gets this instead:
[WARN] [WARNING] permissions: No top-level permissions: and job(s) "test" declare none, so their GITHUB_TOKEN gets the repository's default permissions (read/write on every scope in many repositories). Add a top-level block such as "permissions: { contents: read }", or declare permissions on each job
What is not flagged
- Read-only blocks:
permissions: {},permissions: read-alland any mapping of read ornonescopes, at either level. - Write scopes on a job:
contents: writeon the release job is fine. That is where write scopes belong. Onlywrite-allon a job is flagged. - Reusable workflows called by others: a workflow whose only trigger is
on: workflow_callruns with the token of the job that calls it, so it is exempt from the missing-block check. Thewrite-alland write-scope checks still apply to it. If it has another trigger too, such asworkflow_dispatch, it is checked like any other workflow.
Show findings on pull requests
Locally, the findings print as text. In CI, --format sarif writes a SARIF 2.1.0 report, where these findings use the rule secureci/permissions. --format json gives the same findings as JSON, with a path, severity and rule for each one. See machine-readable output.
The SecureCI GitHub Action runs the checks on every pull request and uploads the SARIF report to GitHub code scanning, so findings show up inline. Note that the workflow follows its own advice. The top level is read-only, and only the job adds the two scopes the upload needs:
# .github/workflows/secureci.yml
name: SecureCI
on: [pull_request]
permissions:
contents: read
jobs:
secureci:
runs-on: ubuntu-latest
permissions:
contents: read
actions: read # upload-sarif reads the workflow run
security-events: write # upload SARIF to code scanning
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- uses: secure-ci/cli@a8bc54904c21f09b96a80850c557fdaa5f92abb6 # v1.4.0
with:
contract: contracts/standard.yml
By default the action validates every file in .github/workflows. The upload needs code scanning enabled for the repository. If you cannot enable it, set upload-sarif: false. secureci init workflow writes this file for you, with actions pinned to commit SHAs. The details are in use in CI.
Make it a rule: a permissions policy in a pipeline contract
Warnings are easy to ignore. A pipeline contract turns the permission checks into a policy, and a broken policy fails validation. Add a permissions key to the contract:
# contracts/standard.yml
permissions:
required: true # every workflow (or every job) must declare permissions
max: # ceiling for the top-level block; write scopes only per job
contents: read
required: truemakes a missing block an error. A workflow passes if it has a top-level block or if every job declares its own.maxis a ceiling for the top-level block. Each scope there must be at or below its level inmax. Scopes not listed inmaxare capped atnone.read-allandwrite-allat the top level are errors unlessmaxallows that level for every scope. A workflow with no top-level block, where any job relies on the default token, is also an error.- Job-level permissions are not capped. The policy pushes write scopes onto the jobs that need them. It does not forbid them.
Run the same release workflow against this contract, and the top-level write scope is now an error (real CLI 1.4.0 output, advisory line left out):
$ secureci validate .github/workflows/release.yml --contract contracts/standard.yml --offline
[INFO] Validating workflow: .github/workflows/release.yml
[INFO] Validating against pipeline contract: contracts/standard.yml
[ERROR] Validation failed: .github/workflows/release.yml
[WARN] [WARNING] jobs.release.permissions: Job "release" uses permissions: write-all, giving its GITHUB_TOKEN write access to every scope. List only the scopes it needs
[ERROR] [ERROR] permissions.contents: Workflow-level "contents: write" exceeds the contract's cap on workflow-level permissions (contents: read). Grant it on the job(s) that need it instead
The command exits non-zero, so the pull request check fails. The write-all on the job stays a warning, because the contract does not cap job-level permissions. The fixed workflow from the example above passes the same contract with no findings.
For many repositories, keep one contract in a central repository and point each check at it with --contract owner/repo/path@ref. Make the SecureCI job a required check, and a workflow that drops its permissions: block cannot merge. To see where you stand today, secureci org scan <org> runs validate on every repository in an organisation and saves the JSON results. It clones only .github/. The full rules are in permissions policy.
GitHub’s own controls set the default token for a repository or organisation. A contract checks what each workflow file declares, before it merges. For how the two fit together, see SecureCI vs GitHub native security. A committed contract and a SARIF report per run are also evidence that the check is in place. They support controls in frameworks such as PCI DSS and SOC 2; the compliance mapping shows which, and what you still need beyond SecureCI.
Limits
- Warnings by default. Without a contract, permission findings are reported but validation still passes. Use a contract if you want the check to fail.
- Only the validated file is checked. The reusable workflows it calls are not checked as part of it. Validate those files too. The GitHub Action does this by default, since it validates every file in
.github/workflows. - It reads the file, not your settings. The CLI cannot see the repository or organisation default. A workflow without a block is flagged whatever that default is.
- Privileged triggers are a separate check.
pull_request_targetandworkflow_runrun with a read/write token even for forks.secureci validatecovers them under dangerous triggers.
For how these checks compare with actionlint, zizmor and OpenSSF Scorecard, see SecureCI vs actionlint and zizmor. To run the workflow itself before you push, see how to run GitHub Actions locally.
Check your workflows now
The SecureCI CLI is free and open source (MIT), for public and private repositories. It needs Node.js 20+, or use the standalone binary.
npm install -g @secureci/cli
secureci validate .github/workflows/ci.yml
secureci validate .github/workflows/ci.yml --contract contracts/standard.yml
Want to know which workflows in your organisation still rely on the default token? Request an assessment →
FAQ
What permissions does GITHUB_TOKEN have by default?
Without a permissions: block, the token gets the repository’s or organisation’s default permissions. On many repositories that is read/write on every scope. Declare a permissions: block in each workflow so the token’s access is set in the file, and see GitHub’s documentation for the default setting.
What does permissions: {} do, and how is it different from read-all?
permissions: {} gives the token no access at all. permissions: read-all gives it read access to every scope. A mapping such as contents: read is the tightest choice when jobs need only some scopes. secureci validate accepts all three, at the top level or on a job.
Do job-level permissions add to workflow-level permissions?
No. Job-level permissions replace the top-level ones. When you give a job contents: write, any other scope that job needs, such as a read scope from the top-level block, must be listed on the job too.
Why should I avoid permissions: write-all?
write-all gives the token write access to every scope. At the top level it applies to every job in the workflow. Any step in a job, including a third-party action, can use that token. List only the scopes the job needs instead.
How do I enforce least-privilege permissions across many repositories?
Write a pipeline contract with permissions: required: true and a max ceiling such as contents: read, keep it in a central repository, and check every repository’s workflows against it with the SecureCI GitHub Action as a required check. secureci org scan runs the same checks over every repository in an organisation.