Sub topic 16
When the GITHUB_TOKEN is not enough
This chapter assumes you can read workflow YAML, know the permissions key, and have set the repository default to read-only. The GITHUB_TOKEN covers most jobs. A few tasks need something else, and choosing the right replacement keeps the least-privilege approach intact.
Where the GITHUB_TOKEN stops
The token is scoped to the repository that runs the workflow. Its limits show up in these cases:
- It cannot read or write a different private repository.
- It cannot use organization-level or user-level APIs, such as managing teams or organization secrets.
- Events caused by the token do not start new workflow runs. A push made with it will not trigger a
pushworkflow, which prevents recursive runs. - It expires when the job ends, so it cannot serve any process that runs after the job.
- It cannot call external systems such as cloud providers.
When a job fails because of one of these limits, adding more scopes to permissions will not help. You need a different credential.
The alternatives
| Credential | Use it when | Main risk |
|---|---|---|
| GitHub App installation token | You need cross-repository or organization access, or you need to trigger further workflow runs | The app's private key is a long-lived secret |
| Fine-grained personal access token (PAT) | A single, narrow cross-repository task and an app is not practical | It is tied to one person and expires on a schedule |
| OIDC (`id-token: write`) | The job talks to a cloud provider | The cloud trust policy must be written carefully |
Prefer them in that order for GitHub access, and use OIDC for cloud access whenever the provider supports it.
Using a GitHub App token
An app installed on only the repositories it needs gives you narrow, short-lived access. The actions/create-github-app-token action exchanges the app's credentials for an installation token that lasts at most one hour.
name: sync-docs
on:
workflow_dispatch:
permissions: {}
jobs:
sync:
runs-on: ubuntu-latest
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ vars.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
repositories: docs-site
- uses: actions/checkout@v4
with:
repository: ${{ github.repository_owner }}/docs-site
token: ${{ steps.app-token.outputs.token }}
persist-credentials: falseThe workflow's own GITHUB_TOKEN has no permissions here (permissions: {}). All access to docs-site comes from the app token, and the repositories input limits that token to one repository.
Choosing a credential
Common errors
- Adding
writescopes to fix a cross-repository failure. The scope applies only to the current repository, so the error stays. - Storing a PAT in a secret and using it everywhere. Limit it to the one job that needs it.
- Expecting a push made with the
GITHUB_TOKENto start another workflow. Use an app token if you need that. - Letting an app's permissions grow past what its workflows use. Review them like any other credential.
Exercise
A release workflow uses the GITHUB_TOKEN to push a commit to the main branch of the same repository. A second workflow listening for push events on main never runs. Why, and what would you change?
Show answer
Events created by the GITHUB_TOKEN do not trigger new workflow runs, to prevent recursive runs. Create a GitHub App installation token with actions/create-github-app-token, limited to this repository, and use it to push. Pushes made with that token start the second workflow.
Exercise
A job must deploy to AWS. Which credential should it use, and which permissions entry does the job need?
Show answer
Use OIDC so the job gets short-lived cloud credentials and no long-lived secret is stored. The job needs id-token: write, plus contents: read if it checks out code.