On this page
Every automation that talks to GitHub holds a credential, and most organizations have far more of them than they think: classic personal access tokens (PATs) pasted into CI systems years ago, OAuth apps authorized by individual developers, deploy keys, and a few GitHub Apps installed with broad permissions. Each one is a way into your repositories that does not go through SSO prompts or 2FA.
This guide covers the organization policies that govern those credentials and how to choose the right credential type for each job.
The credential types
| Credential | Acts as | Scope | Lifetime | Org control |
|---|---|---|---|---|
| PAT (classic) | The user | Coarse scopes across everything the user can reach | Optional expiration | Allow or block |
| Fine-grained PAT | The user | One resource owner, selected repositories, granular permissions | Expiration required by default | Approval, lifetime limit, revoke |
| OAuth app token | The user | Coarse scopes | Until revoked | App access restrictions |
| GitHub App installation token | The app | Repositories it is installed on, declared permissions | One hour | Install approval, permissions review |
| Deploy key | The repository | One repository, read or read-write | Until removed | Policy to disable |
The direction of travel is clear: classic PATs and OAuth app tokens inherit everything the user can do; fine-grained PATs and GitHub Apps are scoped to what the job needs.
Restrict classic personal access tokens
A classic token with the repo scope reads and writes every repository the user can access in every organization. If it leaks from a laptop or a CI log, the blast radius is the user's entire access.
Under Settings > Personal access tokens > Settings, choose Restrict access via personal access tokens (classic). Classic tokens then cannot access organization resources at all (they still work on public resources and on the user's own repositories). Enterprises can set the same policy for all organizations.
Before flipping it, find out who is using classic tokens. Search the audit log for programmatic_access_type:"Personal access token (classic)" over the last few weeks, or stream events and group by actor (see the audit log guide). Contact those owners with a migration date.
Govern fine-grained personal access tokens
Fine-grained PATs are the right choice when a human needs a scripted credential: a one-off migration, a local tool, a personal automation. Configure three things:
- Allow or restrict: under Fine-grained tokens, decide whether they may access the organization at all.
- Require approval: with Require administrator approval, any token targeting the organization enters a pending state until an owner or a delegated approver approves it. The requester states a reason; the approver sees the repositories and permissions requested.
- Set a maximum lifetime: organization owners can set a maximum lifetime for fine-grained tokens (and separately for classic tokens where allowed). Tokens that exceed the limit are rejected when used against the organization. Setting the policy does not revoke existing tokens; they start failing when they are used.
Review pending and active tokens through the API, which is handy for a weekly report:
# Pending requests
gh api --paginate "/orgs/ACME/personal-access-token-requests" \
--jq '.[] | [.owner.login, .reason, .token_expires_at] | @tsv'
# Approved tokens with access to the organization
gh api --paginate "/orgs/ACME/personal-access-tokens" \
--jq '.[] | [.id, .owner.login, .repository_selection, .token_expires_at, .token_last_used_at] | @tsv'
# Revoke access for one token
gh api -X POST "/orgs/ACME/personal-access-tokens" \
-F 'pat_ids[]=12345' -f action=revoke
When approving, push back on All repositories selection and on write permissions to administration, workflows or secrets. A token that can edit workflow files can run arbitrary code with the repository's Actions secrets.
Prefer GitHub Apps for automation
For anything that runs unattended (CI integrations, bots, internal tools), use a GitHub App instead of a token tied to a person:
- No human dependency. The app does not leave when an employee does, and it does not inherit their access.
- Least privilege by declaration. The app declares each permission (
contents: read,pull_requests: write) and is installed on selected repositories. - Short-lived tokens. Installation access tokens expire after one hour. The long-lived secret is the app's private key, which should live in a secrets manager or an HSM-backed store.
- Clear attribution. Actions show up in the audit log as the app's bot account.
In GitHub Actions, use the official action to mint a token scoped to what the step needs, instead of storing a PAT:
jobs:
sync:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/create-github-app-token@f418cff399f7aef4c2f0ad47e25ca7a6abbdd6fc # v3.4.0
id: app-token
with:
client-id: ${{ vars.SYNC_APP_CLIENT_ID }}
private-key: ${{ secrets.SYNC_APP_PRIVATE_KEY }}
owner: ACME
repositories: docs-site
permission-contents: write
- run: gh api repos/ACME/docs-site/dispatches -f event_type=sync
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
The repositories input narrows the token to one repository even if the app is installed on more, and the permission-* inputs narrow it to a subset of the app's permissions (here, creating a repository dispatch event needs contents: write). The token is revoked when the job ends. Pin the action to a full commit SHA as shown; the Actions security guide explains why.
Govern app installations
Under Settings > Member privileges > App access requests (and the GitHub Apps section of third-party access), only owners can install apps by default, and members can request installations. Review installed apps regularly:
gh api --paginate "/orgs/ACME/installations" \
--jq '.installations[] | [.app_slug, .repository_selection, (.permissions | tostring)] | @tsv'
Flag any app with repository_selection: all combined with write permissions on contents, administration or workflows. Third-party apps with those permissions are a supply-chain dependency; treat their vendor as one.
Restrict OAuth apps
OAuth apps act with the token of whoever authorized them, so an OAuth app a developer approves for a side project can read your private repositories if the scopes allow it. Under Settings > Third-party Access > OAuth application policy, enable access restrictions. Existing app authorizations lose access to organization resources until an owner approves the app; members can request approval from their authorized apps list.
Approve only apps you have reviewed, and prefer the vendor's GitHub App when one exists.
Deploy keys and SSH certificates
Deploy keys are SSH keys bound to one repository. They are not tied to a person, so they survive offboarding and are rarely rotated. Organization owners can disable deploy keys for the organization; enterprise owners can set this as a policy. If you keep them, make them read-only and list them in your quarterly review:
gh api "/repos/ACME/payments-api/keys" --jq '.[] | [.id, .title, .read_only, .created_at] | @tsv'
On Enterprise Cloud, SSH certificate authorities let you issue short-lived SSH certificates from your own CA instead of long-lived keys, and you can require certificates for Git access.
A target state
A realistic end state for most organizations:
- Classic PATs restricted.
- Fine-grained PATs allowed with approval and a maximum lifetime of 90 days or less.
- Automation runs as GitHub Apps with per-repository installations and short-lived tokens; cloud access from CI uses OIDC instead of stored keys.
- OAuth app access restrictions enabled, with an approved list reviewed quarterly.
- Deploy keys disabled or read-only and inventoried.
- Secret scanning enabled so that tokens committed by mistake are caught before they reach the default branch.
References
- Setting a personal access token policy for your organization (GitHub Docs)
- Managing requests for personal access tokens in your organization (GitHub Docs)
- New PAT rotation policies preview (GitHub Changelog)
- Differences between GitHub Apps and OAuth apps (GitHub Docs)
- About OAuth app access restrictions (GitHub Docs)
- actions/create-github-app-token (GitHub repository)
- OWASP Top 10 CI/CD Security Risks: CICD-SEC-2 Inadequate Identity and Access Management
- MITRE ATT&CK T1528: Steal Application Access Token
Tags:organizationidentitysecrets
Written by
Florian Amette, Security Engineer & EditorSecurity engineer writing practical hardening guides for GitHub organizations, repositories and CI/CD pipelines, with a focus on software supply-chain security.