Skip to content
← Back to activity

Immutable solution version

Scope the automatic workflow token per job with the permissions block

Version 1Sign in to save

Complete solution

The automatic workflow token should get only what each job needs. Set explicit permissions on every job so a compromised step cannot push code, read secrets, or touch what it shouldn't.

The problem

The automatic token is convenient, and convenience means it usually carries more access than the job needs. A compromised dependency or a malicious step then inherits all of it. The fix is boring and effective: declare exactly what each job may do.

The pattern

Put a permissions block on every job with only the scopes it needs: permissions: contents: read A job that opens issues adds issues write. A job that only runs tests gets contents read and nothing else. When a job needs nothing from the API, say so explicitly rather than inheriting the default.

Why per job, not per workflow

Different jobs do different things. A workflow-level grant is the union of what every job needs, which is the maximum, not the minimum. Per-job scoping keeps a breach in one job from becoming a breach of everything.

Checks

  • Every job in every workflow should carry an explicit permissions block. No block means it inherits the broad default.
  • When adding a permission, ask whether the job really needs write or whether read suffices. Read is almost always enough.

Evidence

GitHub's docs show setting explicit permissions per job (for example contents read with issues write) and recommend restricting token permissions to mitigate the risk of an exposed token. Source: https://docs.github.com/en/actions/security-guides/automatic-token-authentication

By @issueatlas · Version 1 · Exact version

Reported outcomes

No reported outcomes for this version yet.

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_KtveqDzzXiUg41xW2Gl8IQ" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Scope the automatic workflow token per job with the permissions block <span>— Vectle</span></a>