Sub topic 11
Permissions in reusable workflows
This chapter assumes you can write a permissions block at workflow and job level, and that you have seen workflow_call and uses: at least once. It covers how the GITHUB_TOKEN passes from a calling workflow into a reusable (called) workflow, who controls its permissions, and which mistakes cause startup failures or over-broad tokens.
The caller sets the ceiling
A reusable workflow is a workflow file with an on: workflow_call trigger. A caller runs it from a job that has a uses: key instead of steps:. Three facts determine the token the called workflow receives:
- The token belongs to the caller's repository and run. Even when the reusable workflow lives in another repository,
github.repositoryand the token's scope refer to the caller. - The caller decides the maximum permissions. These come from the caller job's
permissionskey. If that is missing, they come from the caller's workflow-levelpermissions. If that is missing too, they come from the repository, organization, or enterprise default. - The called workflow can keep or reduce those permissions. It can never raise them.
This design stops a shared workflow from silently gaining write access. Whoever owns the calling repository stays in control, even when someone else maintains the shared workflow.
What the effective token looks like
The table shows the effective token for a few combinations. "Declares" means the permissions the called workflow requests with its own permissions key.
| Caller grants | Called workflow declares | Result |
|---|---|---|
| `contents: read` | Nothing | Token has `contents: read` and no other scopes. |
| `contents: write` | `contents: read` | Token is reduced to `contents: read`. |
| `contents: read` | `packages: write` | The run fails at startup, because the caller never granted `packages`. |
| Nothing set, default is read-only | `contents: read` | Token has `contents: read`. |
| `{}` | `contents: read` | The run fails at startup, because the caller granted nothing. |
The last row is a common surprise. A workflow-level permissions: {} in the caller is a good deny-by-default, but every uses: job must then grant the scopes the called workflow needs.
A worked example
This reusable workflow builds a container image and optionally pushes it to GitHub Container Registry. It declares what it needs at job level, so it also documents its own requirements.
name: build-image
on:
workflow_call:
inputs:
push:
type: boolean
default: false
permissions: {}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- uses: docker/login-action@v3
if: ${{ inputs.push }}
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
- uses: docker/build-push-action@v6
with:
context: .
push: ${{ inputs.push }}
tags: ghcr.io/${{ github.repository }}:${{ github.ref_name }}The caller denies everything by default and grants the two scopes to the one job that needs them:
name: release
on:
push:
tags: ['v*']
permissions: {}
jobs:
image:
permissions:
contents: read
packages: write
uses: ./.github/workflows/build-image.yml
with:
push: trueA second caller can run the same workflow with push: false on pull requests. That caller can grant only contents: read, but the run then fails at startup because the called job declares packages: write. To support both modes, split the build and push into two reusable jobs with different permissions, or declare the minimum at the called workflow's workflow level and let each caller pass what its mode needs. The first option usually reads better.
Startup failures
When the called workflow requests more than the caller allows, GitHub rejects the run before any job starts. The error names the nested job and the two permission sets, in the form "The nested job 'build' is requesting 'packages: write', but is only allowed 'packages: none'." This differs from the runtime error "Resource not accessible by integration", which appears when a step calls an API the token cannot use. A startup failure is a static mismatch between the two files. You fix it by changing one of them:
- If the called workflow really needs the scope, add it to the caller job's
permissions. - If the called workflow asks for more than it uses, remove the extra scope from its
permissionsblock.
Do not "fix" the error by raising the caller's workflow-level permissions. That grants the scope to every job in the caller. Put the grant on the uses: job only.
Reducing inside the called workflow
The called workflow should declare its own permissions instead of relying on whatever the caller passes. If it declares nothing, it receives the caller's full set, and an unrelated caller with broad permissions then gives the shared workflow more access than it needs. A shared workflow that declares permissions: {} at workflow level and grants per job behaves the same no matter who calls it, which makes it easier to review.
Declaring permissions in the called workflow also tells callers what to grant. Treat the permissions block as part of the workflow's interface, next to inputs and secrets.
When the caller sets nothing
A uses: job with no permissions key inherits from the caller's workflow-level block. If that block is also missing, the called workflow receives the repository default. A repository set to read-only (see the chapter on defaults) gives a read-only ceiling. A repository still on the permissive default gives broad write scopes to a shared workflow you may not control. Because of this, set an explicit permissions key on every job that calls a reusable workflow, especially one from another repository.
Nested and cross-repository calls
A reusable workflow can call another reusable workflow, up to the nesting limit in the GitHub docs. The ceiling shrinks at each hop:
- The first caller's job sets the maximum.
- Each intermediate workflow can narrow it.
- A workflow deeper in the chain that asks for a scope an earlier level dropped fails at startup.
For a reusable workflow in another repository, the caller needs access to that repository. Private and internal repositories must allow access under Actions settings. Pin external calls to a full commit SHA, for example uses: my-org/shared/.github/workflows/build-image.yml@<full-sha>. A moving tag lets the workflow's owner change what runs with your token.
Secrets and OIDC
The GITHUB_TOKEN needs no secrets: entry, because it is generated for the called run. Other secrets are not passed automatically. You must list them under secrets: or write secrets: inherit. Inheriting passes every secret the caller can see, which defeats least privilege, so name the ones the workflow needs.
OIDC works the same way as the token. A called workflow that requests id-token: write runs only if the caller job grants it. Grant it on the specific uses: job that deploys. Do not grant it at workflow level.
jobs:
deploy:
permissions:
contents: read
id-token: write
uses: my-org/shared/.github/workflows/deploy.yml@<full-sha>
secrets:
deploy-role: ${{ secrets.DEPLOY_ROLE }}Checklist for reusable workflows
- Set
permissions: {}at workflow level in the caller, and grant scopes on eachuses:job. - Declare the minimum permissions inside the called workflow, per job.
- Document the required scopes in the called workflow's README or comments.
- Pass named secrets instead of
secrets: inherit. - Pin cross-repository calls to a commit SHA.
Exercise
A caller has permissions: {} at workflow level. Its lint job uses uses: ./.github/workflows/lint.yml with no permissions key. The called workflow declares contents: read and pull-requests: write on its job. What happens, and how do you fix it with the least access?
Show answer
The run fails at startup. The lint job inherits the empty workflow-level permissions, so the called job requests scopes the caller never granted. Add a permissions key to the lint job in the caller with contents: read and pull-requests: write. Do not change the workflow-level block. If the called workflow does not actually need pull-requests: write, remove it from the called workflow instead.
Exercise
A caller job grants contents: write and packages: write to a reusable workflow. The called workflow declares only contents: read at workflow level and has no job-level permissions. What permissions does its token have, and can the called workflow push to GHCR?
Show answer
The token has contents: read and nothing else. The called workflow's declaration narrows the caller's grant, so contents: write and packages: write are both dropped. It cannot push to GHCR unless the called workflow declares packages: write and the caller grants it.