Restricting classic personal access tokens in a GitHub organisation is a one-click setting, but doing it safely means finding every script and integration that still depends on them, moving each one to a fine-grained token or a GitHub App, and only then switching the policy. This guide is the step-by-step migration: how to build the inventory, how to decide between a fine-grained token and a GitHub App for each consumer, how to cut over without breaking automation, how to enforce the restriction and how to roll back if something critical fails.
For the wider picture of how GitHub tokens work, admin roles and the full hardening baseline, read the GitHub Personal Access Tokens Security Guide. This page does not repeat that material; it focuses on the migration project itself.
This is an independent guide from NHI Mgmt Group, based on GitHub's public documentation as of November 2026. It is not sponsored or reviewed by GitHub. Product features change, so confirm settings against GitHub's current documentation.
Key takeaways
- Classic tokens are broad by design. GitHub documents that a classic token grants access to all repositories within the organisations the user can reach, plus their personal repositories, and calls classic tokens "less secure". Fine-grained tokens are limited to a single resource owner and can be limited to selected repositories.
- Owners cannot see classic tokens in the organisation UI. The Active tokens view lists fine-grained tokens only. Unless classic tokens are restricted, any classic token can access organisation resources until it expires. Your inventory therefore has to come from the audit log and from asking teams, not from a settings page.
- Automation belongs on GitHub Apps. GitHub documents that App installation tokens expire after one hour, that Apps act independently of a user and stay installed when the installer leaves, and that a token tied to a user can break when that user loses access.
- Fine-grained tokens have documented gaps. Some use cases, including Packages, the Checks API, access to several organisations at once and outside collaborator work, still need classic tokens. Plan an exception route for these rather than discovering them on enforcement day.
- Enforce last, roll back narrowly. Restricting classic tokens blocks them from organisation resources; SSH keys created with those tokens keep working. If a critical job breaks, re-allow access for a short, dated window instead of abandoning the policy.
When you need this
Run this migration when any of the following applies:
- Your organisation still has the GitHub default, where both classic and fine-grained tokens are allowed to access organisation resources, and you want to remove the broad-scope option.
- A security review, audit finding or customer questionnaire asks you to show that tokens reaching your source code are scoped to specific repositories and have an owner-approved lifecycle.
- You have had a token exposure, from a public repository, a CI log or a developer laptop, and want to reduce the blast radius of the next one. A leaked classic token with the
reposcope reaches every repository its owner can reach; a fine-grained token reaches only its selected resource owner and repositories. - Integrations keep breaking when people leave because they run on a personal token tied to a departed employee.
- You are moving to a model where every non-human identity touching source code is inventoried, owned and reviewed, and classic tokens are the main thing you cannot see.
If your goal is only to put a lifetime cap on tokens rather than to remove classic tokens, see How to set expiry policies on personal access tokens.
Before you start
Confirm the following before you change anything.
- Roles. You need organisation owner rights to change the personal access token policy and to view and revoke fine-grained tokens. If your organisation sits under an enterprise, check whether an enterprise policy already constrains the organisation setting before you plan your timeline.
- A test or low-risk organisation. Pilot the restriction somewhere that breaking a job is acceptable.
- A way to read the audit log. You will search it in the UI and, for larger organisations, through the REST API on
/orgs/{org}/audit-log. GitHub documents that Git events need an audit log export to be identified, so plan for an export as well as a search. - A token inventory sheet. At minimum: owner, purpose, consumer system, repositories touched, operations performed, token type, proposed replacement, migration date and status.
- A communication plan. Restricting classic tokens affects developers' personal scripts as much as shared automation. A dated notice with a link to instructions for creating a fine-grained token removes most of the friction.
- A named owner for GitHub Apps. Someone has to own each App's registration, private key and permissions. See the GitHub App Private Key Security Guide for how to store and rotate the App private key, because moving secrets from a PAT to an App key only helps if the key is managed properly.
Step 1: build the inventory of classic token use
Because owners can only view and revoke fine-grained tokens in the organisation UI, classic token use has to be reconstructed from evidence. Work through three sources.
Search the audit log for token-authenticated activity
GitHub's audit log records an event for each action a user or integration performs, and when the action happened outside the web UI the event shows how the user or integration authenticated. GitHub documents these fields for searching token activity:
| Field | GitHub's description | How to use it in the migration |
|---|---|---|
programmatic_access_type | Type of authentication used | Group events by authentication type to separate personal token use from App and OAuth use |
token_scopes | If applicable, the scopes for the token | Scopes such as repo indicate a classic token; record them as the starting point for the replacement's permissions |
hashed_token | SHA-256 hash of the token used for authentication | Count distinct hashes to estimate how many tokens are in use, and tie each hash to an actor and a consumer |
GitHub's documentation does not list the possible values of programmatic_access_type, so look at what your own log returns rather than assuming values. In the UI, search with hashed_token:"VALUE" with the hash in quotation marks. In the REST API, URI-escape the hash and pass it in the phrase parameter. Remember the documented limit: searches in the UI and through the REST API do not return Git events, so clone and push activity by token needs an audit log export. GitHub also marks token data for Git events, SSH keys and deploy keys as public preview and subject to change.
Match a known token to its activity
When a team hands you a token they think is in use, you can confirm it without sharing the secret further. GitHub documents computing the hash on macOS or Linux with:
echo -n TOKEN | openssl dgst -sha256 -binary | base64
Search the audit log for that value to see what the token actually does. This is often the fastest way to set the replacement's permissions, because you build them from observed operations rather than from the classic scopes the token was created with. Run the command on a trusted machine and clear shell history afterwards, since the token appears on the command line.
Ask the owners
Evidence tells you an actor used a token; it does not tell you which system holds it. For each actor with token activity, ask where the token lives (a CI variable, a secrets manager, a server cron job, a developer laptop), what breaks if it stops working and who is responsible. Search your secrets manager and CI configuration for GitHub token patterns as well; the Git Secret Scanning Guide covers how to do this at scale.
Close the step by classifying each entry as one of: shared automation, personal developer use, or a documented gap where a fine-grained token cannot do the job.
Step 2: choose the replacement for each consumer
GitHub recommends fine-grained tokens over classic tokens whenever possible, and recommends personal tokens mainly for API testing and short-lived scripts. For anything that runs unattended, the GitHub App is the documented fit.
| Consumer | Replacement | Why, from GitHub's documentation |
|---|---|---|
| Shared automation, bots, integrations, CI jobs calling the API | GitHub App installed on the organisation | Apps act independently of a user, are not tied to a user account, do not use a seat and remain installed when the installer leaves. Installation tokens expire after one hour. |
| A developer's own scripts and API testing | Fine-grained token | Limited to one resource owner, can be limited to selected repositories, uses per-permission access levels |
| A workload outside GitHub that needs a short-lived credential | GitHub App, generating installation tokens on demand | Installation tokens can be narrowed to specific repositories and permissions per request |
| Packages, Checks API, several organisations at once, outside collaborator contributions, user-owned Projects | Classic token under a documented exception | GitHub lists these as cases fine-grained tokens do not yet support |
For workflows that run inside GitHub Actions and today use a stored classic token to reach a cloud provider, the right replacement is usually federation rather than any GitHub token at all; see the GitHub Actions OIDC Federation Hardening Guide. For a fuller decision on the three credential types, see GitHub Apps vs Personal Access Tokens vs OAuth Apps.
Mapping classic scopes to fine-grained permissions
There is no one-to-one translation. Classic scopes are broad, and GitHub's documentation for each REST endpoint lists the fine-grained permissions it requires. The reliable approach is:
- List the API endpoints and Git operations the token performed, from the audit log and the consumer's code.
- Look up the required permission for each endpoint in GitHub's REST documentation.
- Grant only those permissions, at the lowest access level (read, write or admin) that works. GitHub notes that not every permission supports all three levels.
- Select only the repositories the consumer touches.
Two details catch teams out. First, GitHub documents that fine-grained tokens always include read-only access to all public repositories on GitHub, so do not treat "no repositories selected" as "no access". Second, organisation permissions only apply when the resource owner is an organisation, and account permissions only when the current user is the resource owner.
Step 3: migrate consumers one at a time
Moving automation to a GitHub App
- Register the App with only the permissions the inventory showed are needed. GitHub documents that Apps use fine-grained permissions, so a job that only reads contents can be given read-only contents access.
- Install it on the organisation and choose the specific repositories it can access. The installing owner decides which repositories the App reaches.
- Change the consumer to generate installation tokens. GitHub's documented flow is: create a JSON web token for the App, find the installation ID, then send a
POSTto/app/installations/INSTALLATION_ID/access_tokenswith the JWT in theAuthorizationheader as a bearer token. GitHub notes that Octokit SDKs can generate and refresh installation tokens automatically. - Narrow each token at request time. The
repositoriesorrepository_idsbody parameters limit a token to up to 500 repositories, and thepermissionsparameter restricts what it can do. A token can never exceed what the installation or App was granted. - Handle expiry. Installation tokens expire after one hour, so long jobs must refresh rather than cache a token for the run.
- Run old and new side by side for a short period if the consumer allows it, compare results, then remove the classic token from the consumer and revoke it at its owner's account.
A side benefit: GitHub documents that installation-token rate limits scale with the number of repositories and organisation users, which often removes the rate limit problems that pushed teams to share one personal token in the first place.
Moving personal scripts to fine-grained tokens
Give developers short instructions. In GitHub's documented flow, the path is profile picture, Settings, Developer settings, Personal access tokens, Fine-grained tokens, Generate new token. They then:
- Set a name and an expiry. Infinite lifetimes are allowed unless a maximum lifetime policy blocks them.
- Choose your organisation as the Resource owner. Organisations that block fine-grained tokens do not appear.
- Pick Only select repositories and the repositories they need.
- Choose the minimum repository and organisation permissions.
- Fill in the justification if the organisation requires approval.
Under the default approval policy, a member's fine-grained token is marked pending and can only read public resources until an organisation owner approves it. Owners' own tokens are approved automatically. Plan approval capacity before the announcement, because a migration wave produces a burst of requests.
Handling the documented gaps
GitHub states that fine-grained tokens do not support every feature of classic tokens and lists these gaps: contributing to public repositories where the user is not a member, contributing as an outside or repository collaborator, accessing several organisations at once, accessing Packages, calling the Checks API and accessing Projects owned by a user account. GitHub also notes some REST endpoints support only classic tokens and that the gaps will be closed over time.
For each gap, record the exception in the inventory with an owner, the reason, a short expiry on the classic token and a review date. Check GitHub's current documentation at each review, because a gap that closes is an exception you can retire.
Step 4: enforce the policy
When the inventory shows no remaining unexplained classic token activity, change the organisation settings. GitHub's documented path is the organisation Settings, then under Personal access tokens, Settings, then the relevant tab.
| Setting | Documented options and default | Migration choice |
|---|---|---|
| Classic token restriction (Tokens (classic) tab) | Allow access (default) or Restrict access | Restrict access, after the pilot |
| Fine-grained token restriction (Fine-grained tokens tab) | Allow access (default) or Restrict access | Keep allowed, or members have no personal token route at all |
| Fine-grained approval | Require administrator approval (default) or Do not require | Keep approval required |
| Maximum lifetime (Fine-grained tokens and Tokens (classic) tabs) | Fine-grained organisation maximum defaults to 366 days; classic tokens have no expiration requirement by default | Set a shorter fine-grained maximum and a classic maximum for any tokens kept under exception |
Sequence the change: give a dated notice, set lifetime limits, then restrict classic access. Know what the policy does and does not do:
- With classic access restricted, classic tokens cannot access resources owned by the organisation. Public organisation resources stay readable.
- SSH keys created by restricted tokens keep working. Review SSH keys separately as part of the same project.
- A lifetime policy does not revoke or disable non-compliant tokens; tokens belonging to members that exceed the limit are blocked, and users find out when API calls to the organisation are rejected.
Verify it worked
- Audit log. After enforcement, search again by
token_scopesandprogrammatic_access_type. Any remaining classic token activity should be from exception holders only; anything else is either a misconfiguration or evidence that a consumer was missed. - Active tokens. In organisation Settings, Personal access tokens, Active tokens, filter by Owner, Repository and Permissions. Look for fine-grained tokens that reproduce the old breadth, such as all repositories with administration permissions, and send them back for narrowing.
- Apps. Confirm each new App is installed only on its intended repositories and has only the permissions in its design. The How to audit GitHub Apps and OAuth apps in an organisation covers this review.
- Consumers. Each migrated job should have run successfully at least once on its new credential, including any job that runs weekly or monthly.
If you want to automate the review of fine-grained tokens, note GitHub's documented constraint: the REST endpoints to review and revoke them can be called only by GitHub Apps, not by personal tokens or OAuth apps. That gives you a natural first App to build.
Rollback and common errors
If a critical integration fails after enforcement, re-allow classic access for the organisation, set a dated end to the exception window and fix the consumer, rather than removing the restriction permanently. Better still, keep the gap small by piloting first and migrating the highest-impact consumers before enforcement.
| Symptom | Likely cause | Fix |
|---|---|---|
| A member's new token works on public repositories but fails on private ones | Token is pending owner approval | Approve the request, or check the justification and permissions first |
| A developer cannot select the organisation as resource owner | Fine-grained tokens are restricted for the organisation | Keep fine-grained access allowed while classic is restricted |
| API calls fail with a working token after a policy change | Token exceeds the new maximum lifetime and is blocked | Create a new token within the limit |
| A job fails partway through a long run | App installation token expired after one hour | Refresh the token in the job, or use an SDK that does so |
| Packages or Checks API calls fail on a fine-grained token | Documented fine-grained gap | Classic token under a dated exception |
| Revoked token, but Git over SSH still works | SSH keys created by the token continue to work | Remove those SSH keys separately |
Common failure patterns
- Enforcing before inventorying. Because classic tokens do not appear in the owner view, the first sign of a missed consumer is a broken production job.
- One fine-grained token per team that recreates classic breadth. Migration that swaps a classic
repotoken for a fine-grained token with all repositories and broad write permissions changes the label, not the risk. - Personal tokens for shared automation. Moving a bot from a departed engineer's classic token to another engineer's fine-grained token repeats the problem; use an App.
- App private keys copied into many places. The App key becomes the new long-lived secret. Keep it in one secrets store with an owner.
- Exceptions without expiry. A classic token kept for Packages with no review date becomes permanent.
- Forgetting SSH keys and offboarding. Revocation and restriction leave token-created SSH keys working, and leavers' tokens need explicit handling; see the Employee Offboarding Security Guide.
- Approval as a rubber stamp. Approving every pending request without reading permissions and repository selection removes most of the benefit of fine-grained tokens.
Practitioner checklist
- Confirm owner rights and any enterprise-level policy that constrains the organisation.
- Search and export the audit log for token-authenticated activity using
programmatic_access_type,token_scopesandhashed_token, including Git events from an export. - Build an inventory with owner, consumer, repositories, operations, replacement and status for every classic token in use.
- Move shared automation to GitHub Apps with minimal permissions and repository selection; handle one-hour token expiry.
- Move personal scripts to fine-grained tokens scoped to one resource owner and selected repositories.
- Record documented gaps as dated exceptions with short-lived classic tokens.
- Keep fine-grained approval required and staff the approval queue for the migration wave.
- Pilot the restriction in a low-risk organisation, then give a dated notice, set lifetime limits and restrict classic access.
- Review and remove SSH keys created with classic tokens.
- Re-run the audit log search after enforcement and investigate any classic activity outside the exception list.
- Schedule a quarterly review of active fine-grained tokens, App permissions and open exceptions.
Standards and references
- GitHub Docs: Setting a personal access token policy for your organization
- GitHub Docs: Managing your personal access tokens
- GitHub Docs: Reviewing and revoking personal access tokens in your organization
- GitHub Docs: Identifying audit log events performed by an access token
- GitHub Docs: Deciding when to build a GitHub App
- GitHub Docs: Generating an installation access token for a GitHub App
- OWASP: Non-Human Identities Top 10 2025
- MITRE ATT&CK: Steal Application Access Token (T1528) and Application Access Token (T1550.001); NIST SP 800-53 Rev. 5 IA-5 Authenticator Management and AC-6 Least Privilege
Related NHI Mgmt Group resources: GitHub Personal Access Tokens Security Guide · GitHub Apps vs Personal Access Tokens vs OAuth Apps · GitHub App Private Key Security Guide · GitHub Audit Log Detection Guide