Sub topic 11
Permissions in reusable workflows
This chapter assumes you can write a workflow with on, jobs, and steps. It also assumes you know the permissions key at workflow level and job level, and you have seen uses: for actions. Here you will see how token permissions pass from a calling workflow to a reusable one.
How the token is shared
A reusable workflow is a workflow with the workflow_call trigger. Another workflow runs it with uses: at the job level. The called workflow does not get a new token. It runs with the token of the caller, and the caller decides the ceiling.
The rule is that permissions can be kept or reduced as they pass down the chain. They can never be raised. If the caller grants contents: read, the called workflow cannot ask for contents: write.
A caller and a called workflow
The called workflow below labels pull requests. It declares what it needs at the job level.
name: label-called
on:
workflow_call:
permissions: {}
jobs:
label:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- uses: actions/labeler@v5The caller grants those two scopes on the job that calls it. It sets nothing for other jobs.
name: label
on: pull_request
permissions: {}
jobs:
call-label:
permissions:
contents: read
pull-requests: write
uses: ./.github/workflows/label-called.ymlThe permissions key on the calling job sets the maximum for the called workflow. If you leave it out, the caller's workflow-level block applies. If that is missing too, the repository default applies.
Why the called workflow still declares permissions
Declare permissions in the called workflow even when the caller already grants them. The reusable workflow may be called from other repositories or by other teams. Its own permissions block documents what it needs. It also protects you if a caller is more generous than necessary, because the called workflow reduces the token to its own list.
Common errors
A caller that grants too little makes the run fail before any job starts. The message looks like this:
The nested job 'label' is requesting 'pull-requests: write', but is only allowed 'pull-requests: none'.To fix it, add the missing scope to the calling job or to the caller's workflow-level block. Do not widen the called workflow, because that cannot override the caller.
Other points to check:
- A workflow-level
permissions: {}in the caller gives the called workflow nothing, unless the calling job sets its own block. - Permissions on the calling job apply to the whole called workflow, not to individual jobs inside it. The called workflow can narrow them per job.
- Secrets do not pass automatically. Use
secrets: inheritor list them undersecrets:. This is separate from the token. - For a workflow from a fork, the read-only limit for forks still applies, whatever the caller requests.
Decision guide
| Situation | What to do |
|---|---|
| You write a shared workflow | Set `permissions: {}` at the top and declare per-job scopes |
| You call a shared workflow | Grant the called workflow's needed scopes on the calling job only |
| You call a workflow you do not control | Read its `permissions` blocks before granting write access |
Exercise
A caller sets permissions: { contents: read } at workflow level and calls a reusable workflow with uses: on a job that has no permissions block. The reusable workflow has a job requesting packages: write. What happens, and how do you fix it?
Show answer
The run fails at startup, because the called workflow cannot raise permissions above the caller's contents: read. The fix is to add permissions: { contents: read, packages: write } to the calling job. Changing the called workflow alone does not help.