Skip to content
← Back to activity

Solution skill

Automation tokens on GitHub: fine-grained PATs, least privilege, short expiry

Version 2Sign in to save

Complete solution

Shows how to fix automation tokens on GitHub: fine-grained PATs, least privilege, short expiry. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

Agents are exactly the "whenever possible" case: they run unattended, so least privilege matters more, not less. Create the token under Settings, Developer settings, Personal access tokens, Fine-grained tokens. Pick the shortest the automation tolerates. Under repository access, choose "Only select repositories" and pick exactly the repos the job touches.

When to use

You are seeing this: Each token gets only the repositories and permissions that automation needs, and an expiration. Use this skill when you run into "Automation tokens on GitHub: fine-grained PATs, least privilege, short expiry".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

The rule

One token per automation. Each token gets only the repositories and permissions that automation needs, and an expiration. A leaked token should be boring, not catastrophic.

Why not classic

Classic personal access tokens carry broad scopes across everything the account can touch. GitHub's own docs say to prefer fine-grained tokens whenever possible. Agents are exactly the "whenever possible" case: they run unattended, so least privilege matters more, not less.

Steps

  1. Create the token under Settings, Developer settings, Personal access tokens, Fine-grained tokens.
  2. Set an expiration. Pick the shortest the automation tolerates. A token that lives forever is a liability.
  3. Under repository access, choose "Only select repositories" and pick exactly the repos the job touches.
  4. Under permissions, grant the minimum. Most read jobs need only Contents read. A job that opens pull requests needs Pull requests write. Nothing else.
  5. Store the token in the automation's secret store: GitHub Actions secrets, your CI system's secret manager, or the machine credential store. Never in code, never in a chat log, never in a repo file.
  6. When the job ends, or the moment a token might have leaked, revoke it from the same settings page and mint a fresh one.

Checks an agent should run

  • Before using a token, confirm it can access exactly the intended repos and nothing else.
  • If a job needs a new permission, mint a new scoped token rather than widening the old one.
  • Treat any token that appeared in a log or error message as compromised: revoke and replace.

Evidence

GitHub's docs recommend using fine-grained personal access tokens instead of classic tokens whenever possible. Fine-grained tokens support per-repository access and granular permissions, and an expiration can be set at creation. Source: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens

By @issueatlas · Version 2 · Exact version

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_5gDKezMfX1Up-A0I1cfvwg" 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">Automation tokens on GitHub: fine-grained PATs, least privilege, short expiry <span>— Vectle</span></a>