Sub topic 3
Reading permission errors
Assume you know basic workflow YAML and can read a job's steps. A permission error usually means the token can authenticate, but its scope cannot perform the requested operation.
Read the error first
For Resource not accessible by integration, identify:
- Which step made the request.
- Which GitHub resource it touched.
- Which permission scope that resource needs.
- Whether the event changed the token's access.
For example, creating an issue needs issues: write. Pushing a package needs packages: write. Add the smallest missing scope to that job, then rerun it.
Events and reusable workflows
Fork pull requests commonly receive a read-only token, and their secrets are unavailable. Dependabot workflows also receive restricted access because dependency data is untrusted. Do not “fix” these cases by exposing write secrets to untrusted code.
A reusable workflow receives permissions from its caller. The called workflow can reduce access, but it cannot elevate permissions that the caller did not grant.
permissions: {}
jobs:
release:
permissions:
contents: read
packages: write
uses: ./.github/workflows/release.ymlCheckout credentials
actions/checkout normally stores the token in local Git configuration so later steps can push. If the job only reads code, prevent that credential from remaining available:
- uses: actions/checkout@v4
with:
persist-credentials: falseOIDC and untrusted code
OpenID Connect (OIDC) lets a job exchange a short-lived identity token for cloud credentials. It needs id-token: write; it does not require a cloud secret in GitHub. Configure the cloud provider to trust only the expected repository, branch, or environment.
Avoid running pull-request code with pull_request_target when that code can access write permissions or secrets. This event uses the target repository's context, so an attacker may alter the pull request and make a privileged step execute untrusted commands.
Audit and know the limits
Search every workflow for broad permissions such as permissions: write-all, then replace them with read-only workflow defaults and job-level exceptions. Review third-party actions, especially actions that execute scripts or receive untrusted input.
GITHUB_TOKEN is limited to its repository and its configured scopes. Use a GitHub App token for controlled cross-repository automation, a personal access token only when its user-based access is necessary, and OIDC for cloud access.
Exercise
A job gets a 403 while creating a pull-request label. What should you check first?
Show answer
Check the event and job permissions, then grant pull-requests: write only if that job needs it.