PREP WITH PROOF
Menu
DEVOPS & SECURITY / PRACTICAL GUIDE

GitHub Actions Permissions: Limit GITHUB_TOKEN by Job

Set job-level GitHub Actions permissions, diagnose GITHUB_TOKEN 403 errors, and separate trusted writes from untrusted inputs. Includes a reviewed YAML example.

THE QUICK ANSWER

Give each GitHub Actions job only the GITHUB_TOKEN permissions its API operations need. Use explicit maps, inspect the credential and triggering event, and separate trusted writes from untrusted code. Repository token permissions, filesystem access and cloud OIDC authorization are different controls.

Begin with the operation, not the permission error

A workflow fails with “Resource not accessible by integration,” and the tempting repair is permissions: write-all. That may change the outcome, but it also gives unrelated jobs authority they do not need. Start by identifying the exact API operation and the credential used by the failing step. Reading a source file, posting an issue comment and obtaining a cloud identity are different operations.

The practical goal is a small permission budget per job, combined with a clear boundary around the code that runs there. A token with narrow repository access still matters if arbitrary code can use it. Conversely, a correctly isolated job can still fail because its requested token permissions or repository policy do not permit the endpoint.

This guide uses a manually dispatched demonstration with a read job and an optional comment job. It does not deploy software, change your repository settings or configure a cloud account. The YAML is intended for a disposable repository with an existing test issue and at least one committed file.

Know which credential the job actually holds

GitHub creates a GITHUB_TOKEN for each workflow job. It is a GitHub App installation access token scoped to the repository containing the workflow, and it is available through the github.token context. Do not treat it as a general personal credential for unrelated repositories.

A step may use this token through GH_TOKEN, an action input or the github.token context. Omitting an explicit token input does not prove that an action lacks access to it. Review the entire job: every action and process in that job belongs inside the same trust analysis.

First confirm whether the failing request uses GITHUB_TOKEN, a personal access token, a GitHub App token or cloud credentials. The workflow permissions key controls GITHUB_TOKEN. It does not reduce the privileges of a separate credential you inject from secrets. Replacing a blocked token with a more powerful personal token can hide the actual configuration problem.

Source: GitHub GITHUB_TOKEN concept and repository scope ↗

Use an explicit map for each job

The permissions key can set workflow defaults or a job-specific map. When you specify individual permissions, unspecified available permissions are set to none; write includes read where that permission supports both levels. A job map should therefore be reviewed as a complete declaration, rather than as a small additive patch to whatever you imagine the workflow inherited.

Start from permissions: {} when the workflow can explicitly declare each job’s needs. A source-reading job can request contents: read, while a separate issue-comment job can request issues: write. Neither operation requires contents: write merely because the workflow belongs to a repository.

These declarations are requests within GitHub’s policy model. Organization and repository settings, event restrictions and reusable-workflow boundaries still matter. Inspect the effective permissions reported for the job and the endpoint’s documentation before concluding that YAML alone guarantees a grant.

Job purposeRelevant declarationSeparate question
Read repository filescontents: readWhich repository and ref are being read?
Add an issue commentissues: writeIs the selected issue and comment intended?
Request an OIDC identity tokenid-token: writeWill the cloud trust policy accept these claims?
Compute without repository API accesspermissions: {}Does another supplied credential add authority?

Source: GitHub workflow syntax: permissions and job settings ↗

A read job and an optional write job

Place this file at .github/workflows/permission-demo.yml on the default branch of your test repository. Run it with post_comment left false first. The inspect job calls the repository Contents API and lists the root paths; it does not check out or execute repository code. The example assumes the GitHub CLI available on the selected GitHub-hosted Ubuntu runner.

If you deliberately enable post_comment and provide a positive existing issue number, the second job adds the fixed comment shown below. That is a real write when run on GitHub, and rerunning it can add another comment. Use a disposable test issue. The dependency establishes job order; it does not pass the first job’s token to the second.

The comment job receives issues: write without contents: read in its map. This is sufficient for the intended comment operation under an allowing repository policy; it is not an application-level restriction to a single issue. The shell validation restricts the demonstration input. Repository tokens do not become issue-specific credentials because a script checks an issue number.

name: Permission boundary demonstration

on:
  workflow_dispatch:
    inputs:
      issue_number:
        description: Existing test issue in this repository
        required: true
        default: 1
        type: number
      post_comment:
        description: Add one fixed comment to the test issue
        required: true
        default: false
        type: boolean

permissions: {}

jobs:
  inspect:
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      contents: read
    steps:
      - name: List root paths through the repository API
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
        shell: bash
        run: |
          set -euo pipefail
          gh api --method GET "repos/$GH_REPO/contents" --jq '.[].path'

  comment:
    needs: inspect
    if: ${{ inputs.post_comment }}
    runs-on: ubuntu-latest
    timeout-minutes: 5
    permissions:
      issues: write
    steps:
      - name: Comment only on the selected test issue
        env:
          GH_TOKEN: ${{ github.token }}
          GH_REPO: ${{ github.repository }}
          GH_ISSUE: ${{ inputs.issue_number }}
        shell: bash
        run: |
          set -euo pipefail
          if [[ ! "$GH_ISSUE" =~ ^[1-9][0-9]*$ ]]; then
            echo "Use a positive integer issue number" >&2
            exit 1
          fi
          printf '%s\n' 'Permission-boundary demonstration completed.' > comment.txt
          gh issue comment "$GH_ISSUE" --repo "$GH_REPO" --body-file comment.txt

Source: GitHub repository Contents API ↗

Keep values out of generated shell source

The example passes repository and issue values through environment variables, then quotes shell expansions. It does not insert the issue input directly into the run script as source text. The explicit numeric guard rejects negative, fractional and nonnumeric values before the CLI command runs.

Treat pull-request titles, branch names, issue bodies and other contributor-controlled values as untrusted data. A value that is harmless in a user interface can have meaning when pasted into a shell, query or generated configuration. Environment variables reduce one interpolation hazard; they do not replace validation of the command arguments or authorization of the requested operation.

The fixed body is written to a file and supplied with --body-file. For a generated report, create that file as data rather than constructing a shell command from its contents. Never print token values to diagnose an argument problem. Redaction in logs is useful but should not be your only protection against exposure.

Source: GitHub secure-use reference ↗

Choose the event that matches the trust boundary

A workflow triggered by an ordinary pull_request from a fork is subject to restrictions on secrets and write tokens, with behavior affected by repository settings. A successful run from a trusted branch is therefore not a faithful test of the fork path. Check the event and repository policy rather than immediately adding broader permissions.

pull_request_target runs in the base repository context. It can support repository-side triage, such as labeling a pull request, but it is not a shortcut for giving untrusted pull-request code write privileges. Checking out and executing the contributor’s head code in a privileged job can expose tokens or secrets.

Keep untrusted builds separate from trusted mutation or deployment. Artifacts, caches, outputs and scripts that cross that boundary also need validation. A second workflow is not automatically trustworthy merely because it starts after another run. Identify who could control every input consumed by the privileged stage.

Source: GitHub workflow events and pull_request_target ↗

Treat OIDC permission and cloud authorization separately

id-token: write allows a job to request a GitHub OIDC identity token. It does not by itself grant write access to repository files or to cloud resources. The cloud provider must trust the issuer and accept the relevant token claims before issuing its own short-lived credentials.

Limit the cloud trust relationship to the intended repository and deployment context, and constrain the resulting cloud role separately. Review branch or environment conditions and the audience required by the provider’s integration. Avoid a trust policy that accepts every workflow from an overly broad subject.

This demonstration does not need OIDC, so it requests no id-token permission. When adding a cloud deployment job, keep its identity acquisition and deployment authorization isolated from jobs that process untrusted contributions. The corresponding cloud documentation and integration tests are part of that implementation.

Source: GitHub OpenID Connect overview ↗

A useful order for diagnosing 403 responses

Record the failing endpoint and method, the job, the event and the credential type. Then read that endpoint’s required permission. A workflow that can read a file is not evidence that it may create a release or publish a package. Also confirm the target repository; a job’s default token does not gain cross-repository reach from an URL.

Inspect the job’s permission map and effective token permissions, then repository or organization policy and event-specific restrictions. If a reusable workflow is involved, examine both caller and called workflow. Do not debug only the nearest YAML file while ignoring the execution path that supplied its authority.

If permissions appear correct, preserve the response status and a sanitized error message and check other documented causes. Repository rules, resource state, organization controls or using the wrong endpoint can also prevent an operation. A 403 alone is not proof that a write-all grant is the appropriate remedy.

Review actions and reusable workflows as code dependencies

A third-party action runs code inside the job’s security context. Review its source and required permissions, then pin the reviewed action to a full commit SHA when adopting it. A moving version tag does not provide the same immutable reference. Maintain a deliberate update process so a pin does not become a reason to stop reviewing changes.

Reusable workflows also need explicit interface and permission review. Pass only required secrets and permissions. A called workflow cannot increase the caller’s allowed GITHUB_TOKEN privileges, so an apparently correct declaration in the called file may still be constrained upstream.

The demonstration deliberately uses shell steps and the preinstalled CLI, with no third-party action or repository checkout. That makes its permission boundary easy to inspect; it does not make the hosted runner image or CLI an immutable dependency. Production teams should also track the runner environment and their own supply-chain requirements.

Source: GitHub secure-use reference ↗

What to verify before adopting the pattern

Locally, we parsed the exact YAML, checked both shell blocks and exercised their argument handling with a fake CLI that performs no network operations. The positive issue case produced the intended argument list and fixed body; malformed values were rejected before the fake CLI ran. These checks do not demonstrate GitHub’s actual permission enforcement.

In your disposable repository, run the read-only path first, inspect the job’s effective permissions and confirm the output. Then enable the deliberate comment and confirm that only the intended test issue changes. Exercise a denied operation in the read job without broadening its map, and repeat relevant tests for fork or reusable-workflow contexts if your real workflow uses them.

No workflow was dispatched and no issue comment or cloud operation was performed for this article. The API and token behavior described here was reviewed against current official documentation. Actual integration behavior depends on the repository and organization configuration, so preserve that evidence with the workflow review.

A permission change should explain one operation

A clear workflow review names the operation, the credential, the required permission and the code allowed to use it. Separate jobs when they have different authority needs, and keep untrusted values as data throughout the path. Broader access should never be the only explanation for why a failure disappeared.

Use the related Linux guide when the denial comes from runner filesystem permissions, and the webhook guide when validating external event deliveries. Those are different enforcement layers. Identifying the layer first makes the eventual change smaller and its result easier to verify.

KEEP THESE THREE THINGS

Your next steps

  1. Declare each job’s token permissions as a complete, minimal map.
  2. Identify the credential, event and exact API operation before changing a 403 response.
  3. Separate untrusted code and data from privileged jobs; verify the real repository policy.

Sources & official resources

Linked resources checked on 2026-10-26. Technical behavior and provider guidance can change; check the documentation for the version you use.

About this guide and its recommendations

Published by Prep With Proof with AI-assisted drafting. Study routines and examples are editorial suggestions, not official exam instructions or claims of a learner's personal results. Cited provider facts are linked; ownership of recommended Prep With Proof products is disclosed. No competitor endorsement or guaranteed certification outcome is implied.

Suggest a correction →