GitHub Actions Permissions for Least-Privilege Jobs

Set GitHub Actions permissions per job, keep validation read-only, and verify the separate scope for pull request comments with a tested review matrix.

GitHub Actions permission matrix with contents read for validation, pull requests write for the separate comment job, and nine checks in a local fixture.

Set GitHub Actions permissions at the job boundary. For a workflow that validates a change and posts a pull request comment, give validation contents: read and give only the comment job pull-requests: write. A top-level permissions block supplies the default for jobs without a block of their own. A job that sets its own map must name every permission it needs.

Start from the operations the workflow performs. Reading repository files, attaching a workflow artifact, and commenting on a pull request are three different operations. A job that lists the files it checked and writes a test summary has no reason to change repository content. Put the decision to write to GitHub in the pull request, where the next reviewer can trace it to a specific step.

Scope a validation job and a comment job

Imagine a coding agent adds a workflow for a new package. The first job checks out the repository and validates a manifest. The second job posts the resulting validation status on a pull request. Reviewing those jobs separately reveals a simple policy. The first reads source. The second writes a comment. Neither updates a branch or creates a release.

This is a permission excerpt for that design. The production workflow still needs explicit events, runner definitions, and reviewed steps.

permissions:
  contents: read

jobs:
  validate:
    # Inherits contents: read.
  comment:
    permissions:
      pull-requests: write

In the final workflow, place the reporting job behind the appropriate trust boundary for your repository. Keep the report data small, such as a check identifier and pass or fail status. Review its source, parse it as data, and make sure a branch contributor cannot use it to choose an operation or destination. Ordinary test output goes into the job summary or an artifact. A comment is optional when the existing check results already tell the reviewer what happened.

For a validation job that restores npm’s cache, use the GitHub Actions cache example to check that the install and tests used the lockfile from the checked-out commit.

If the comment job also checks out the repository, add contents: read in that job's permission map. Prefer removing the checkout when the job only needs a reviewed summary and the pull request number. Unlisted permissions in an explicit map have no access. GitHub's workflow syntax explains this rule and the additional handling for fork events.

What each job can ask for

Make the allowed operation a row in the review. Keep permissions tied to the actual API or action being used. For example, a pull request conversation comment uses an issue-comment endpoint that documents issue-write or pull-request-write access. Another operation on the same page may have a different scope or policy requirement. Read the documentation for the actual action, rather than assuming everything under a pull request shares a permission.

Job Intended operation Start with Review question
Validate Read files from this repository and run the checks contents: read Does the job need a checkout at all?
Report Post a reviewed status comment to the pull request pull-requests: write Can the job publish a job summary instead?
Release Publish from an approved release context Only the documented permissions for the exact release operation Who can invoke the job, and what reference does it trust?

Treat test validation and publication as separate responsibilities. A job that signs a release or publishes an image should be reviewed on its own. Its permission set depends on the registry, environment, and workflow action. The validation example does not transfer those permissions to jobs that only need to run tests.

What our YAML check verified

We fed five synthetic workflow shapes through a local parser and checked nine assertions. In the first YAML, the top-level write-all shorthand was selected for both jobs. The policy asked us to replace it with explicit permission maps. The corrected YAML above selected contents: read for validation and pull-requests: write for the comment job. The comment job's map omitted contents, so the fixture recorded no contents permission for that job.

Synthetic input What the check recorded Reviewer action
Workflow-wide write-all Both jobs selected the broad declaration Replace it with maps attached to the jobs that need them
Workflow read and one job write Both jobs matched their reviewed operations Keep the scopes and inspect the trigger
Empty permission map on validation Validation lost the contents permission required for checkout Keep it empty only if the job can work without source access
Validation has no permission declaration at either level The runtime default needs separate verification Inspect repository and organization settings
Extra packages: read on comment The extra scope has no reviewed operation in this example Remove it or document and review the operation

The check used a local YAML parser and a small policy for the example. It did not run GitHub Actions, request tokens, contact an API, or model all possible scopes. It verified these declarations against our reviewed list of job operations. Actual token rights still depend on the repository, organization, event, and GitHub's rules. That limit matters when a static check says the YAML is narrow and a real job still receives a denial.

For the same style of evidence handoff, see how to keep a human decision in the agent workflow. A compact record of the exact declaration changed, the planned operation, and the environment verified gives a reviewer something concrete to approve.

Review defaults, forks, and reusable workflows separately

Start by looking for permissions at the job level, then at the workflow level. When neither is present, record the configured default as a separate finding. GitHub calculates defaults from administrative settings before applying workflow and job declarations. A copy of a YAML file alone cannot tell you how all those settings resolve for an actual run. GitHub's repository Actions settings shows where repository-level defaults are maintained and which settings can be constrained by an organization.

Then trace the event. Fork pull requests normally receive read-only access when the relevant setting leaves write tokens disabled. A comment job that works in a trusted repository branch may fail on a fork. Verify the intended behavior for each event you support and keep untrusted source and a privileged reporter in separate contexts. Changing the event simply to clear a permission error changes the trust boundary. GitHub's secure use guidance is the reference for which contexts can carry secrets and privileged tokens.

Review reusable workflow calls as another boundary. Confirm the scope at the caller and the intended operations in the callee. A nested call cannot use permissions that the caller does not grant. An action or command that authenticates with a different credential needs its own review. Narrowing GITHUB_TOKEN leaves the scopes of an independently supplied credential to its own issuer. Record each credential source even when you expect the job to use just one.

Respond to a permission failure without widening the whole workflow

Find the first step that failed and name the operation. A read-only checkout, creating a comment, and publishing an artifact each need a different answer. Check the permission declaration on that job, the event that started the run, and the endpoint or action documentation. Once you know those details, you can tell whether the right fix is a narrower grant, moving the step to another job, or leaving the operation unavailable in that context.

Keep build output useful while you investigate. A workflow can still show test results in its existing run or job summary when a separate comment is unavailable. For reviewers, record why the write was attempted and whether it is essential for approval. If routine runs all need the owner to override a setting, the workflow boundary and the intended operating model disagree.

Treat permission changes like interface changes. The code may pass every test while the job now has two more ways to modify the repository. A CODEOWNERS review can give workflow files a predictable reviewer. A review of AI guardrails can help you decide which operations should wait for a human. Keep the repository setting, permission declaration, and requested automation action in one reviewable change whenever you can.

Record the minimum a reviewer needs to approve

For each job, write down the event, what code it runs, which credential it uses, the intended operation, and why that operation belongs with the job. In the example, the validation job reads the repository and runs checks. The separate reporter receives a narrow result and posts it when the event and repository policy allow. A third job that publishes packages would get its own line and its own approval.

When an agent changes a workflow, ask for one more detail in its handoff. Have it name every repository operation added or removed, not just the YAML keys touched. If it adds a write scope, the handoff should identify the step using the permission, what input the step accepts, and how the team will see an unexpected result. Then the reviewer can confirm the change against both the workflow and the intended behavior. Keep that record alongside the same permission decisions you already review for coding agents. The runtime must still enforce its own authorizations.

When you add a job or change what one can do, record the new permission and the reviewer's decision in the pull request.

Frequently asked questions

Where do you set GitHub Actions permissions?

Set permissions once at the workflow level for a common baseline, then give a job its own explicit map when it performs a different operation. Check repository or organization settings if neither declaration exists. Review GitHub’s event restrictions separately, especially when the workflow can be triggered from a fork.

Does a job inherit permissions that are omitted from its own map?

A job with its own explicit permissions map must include each scope it needs. If a comment job sets only pull requests write, it does not inherit contents read from the surrounding workflow map. Add contents read to the job only if the job also needs to read repository files.

What permission does a workflow need to comment on a pull request?

For a pull request conversation comment, check the documented create issue comment endpoint and the credential your step uses. The endpoint lists issue write or pull request write for fine-grained access. Use the scope that fits your operation, and verify that the event and repository policy allow the write.

Why can a pull request write still fail after the YAML sets it?

The YAML is one input to GitHub’s effective permissions. A fork event can downgrade write scopes, and administrative settings can place other limits on automation. Check the event, repository settings, action inputs, and the endpoint’s exact permission requirement. A scoped write is useful only in the context where it is intended.

What does an empty permissions map do?

An explicit empty map removes the permissions that would otherwise be available through the workflow declaration for that job. It works for jobs that need no repository operations. If an existing checkout or API read later fails, confirm the step’s required scope before changing the map or workflow default.