Personal access token

Also known as: PAT

On this page 7

A personal access token (PAT) is a long, randomly generated secret string that a user creates in a platform to authenticate API calls, command-line tools and scripts in place of a password. The token acts with the identity of the user who issued it, usually restricted to selected scopes and an expiration date.

In automation security, PATs matter because they are the most common credential found inside workflows, pipelines and integration scripts. They are convenient and quick to create, yet they tie automated jobs to a human identity, which creates risks when the person changes role, leaves the organization or accidentally exposes the token.

How a personal access token authenticates requests

A personal access token authenticates by being sent with every API request, typically in an HTTP Authorization header as a bearer value or as the password field of basic authentication. The server looks up the token, confirms that it is valid and unexpired, and then applies the issuing user’s permissions narrowed by the token’s scopes.

Most platforms show the full token only once at creation and store only a hash of it afterward. Many modern implementations add a recognizable prefix to the token so that secret scanners can detect leaked tokens in code repositories and logs with very few false positives.

The following table lists the attributes that define a PAT and why each one matters for security.

AttributeTypical settingSecurity effect
OwnerThe issuing user accountDefines the maximum possible access
ScopesRead, write or admin per resourceLimits what the token can do
Resource restrictionSelected projects or repositoriesLimits where the token works
Expiration7 to 90 days, sometimes noneBounds the exposure window
PrefixPlatform-specific identifierEnables automated leak detection
Last-used metadataTimestamp and source addressSupports audits and cleanup
Key attributes of a personal access token

Classic and fine-grained token types

Personal access tokens come in two broad generations: classic tokens with coarse scopes and fine-grained tokens that restrict access to specific resources and individual permissions. Fine-grained tokens follow the principle of least privilege far more closely and often require administrator approval within an organization.

PropertyClassic tokenFine-grained token
Permission modelBroad scopes across all resourcesPer-resource, per-action permissions
ExpirationOptional on many platformsUsually mandatory
Organization controlLimited visibilityApproval and revocation by admins
Blast radius if leakedEverything the user can reachOnly the selected resources
CompatibilityWorks with nearly all APIsSome endpoints may be unsupported
Classic versus fine-grained PATs

Where both types exist, the safer default is to choose fine-grained tokens and fall back to classic ones only when a required API does not yet support them, documenting the exception.

PATs compared with other automation credentials

A personal access token is a user-bound credential, which sets it apart from credentials designed for non-human identities. Choosing the right credential type is one of the most consequential decisions in automation security.

CredentialBound toLifetimeBest fit
Personal access tokenA human userDays to monthsPersonal scripts and quick tests
Service account keyA non-human identityMonths, ideally rotatedShared production automation
OAuth app tokenAn application plus consentMinutes to hours, refreshableThird-party integrations
Workload identity federationA runtime environmentMinutesCI/CD pipelines and cloud jobs
API keyA project or applicationOften unlimitedSimple, low-risk service calls
Credential options for automated workflows

The central problem with PATs in shared automation is ownership mismatch. When a production workflow runs on an employee’s token, the workflow breaks if that employee leaves, and every action appears in logs as performed by that person, which weakens audit trails and accountability.

Managing PATs safely in automation

Safe use of personal access tokens rests on minimal scope, short lifetime and secure storage. A token should grant only what the task requires, expire as soon as practical and never appear in source code, chat messages or plain-text configuration files.

  • Store tokens in a credential vault or the platform’s secret store, never in repositories.
  • Set an expiration date and track renewals in the automation inventory.
  • Use one token per purpose so revocation affects a single workflow.
  • Enable secret scanning with push protection on code repositories.
  • Redact tokens in logs and error messages produced by workflows.
  • Review active tokens regularly and revoke unused ones.
  • Migrate production jobs to service accounts or federated identities.

Organization administrators can enforce many of these rules through policy, for example by requiring approval for fine-grained tokens, setting a maximum lifetime or blocking classic tokens entirely for sensitive resources.

Common PAT risks and failure modes

Leaked personal access tokens are among the most frequent causes of supply chain incidents, because a single exposed token can grant write access to source code, packages or deployment pipelines. Attackers actively scan public repositories and container images for credential patterns within minutes of publication.

Failure modeTypical causeCountermeasure
Token committed to a repositoryHardcoded credentials in scriptsPush protection and vault references
Overprivileged tokenAdmin scope chosen for convenienceFine-grained, least-privilege scopes
Orphaned automationOwner left the organizationService accounts and ownership reviews
Non-expiring tokenExpiration disabledEnforced maximum lifetime
Token in logsVerbose debug outputLog redaction and masking
PAT failure modes and countermeasures

When a leak is suspected, the correct response is to revoke the token immediately, review its last-used records for unauthorized activity, and only then issue a replacement with narrower permissions.

Put simply

A personal access token is like a spare key cut for a specific job. Instead of handing a program your actual password, you create a separate key that opens only certain doors and stops working after a set date.

If the key is lost, you can cancel that one key without changing your password. The catch is that the key still belongs to you, so anything a program does with it looks as if you did it yourself. That is why shared, long-running automations should use their own dedicated keys instead.

In practice

A platform team at a mid-sized software company discovers that its nightly release pipeline authenticates to the code hosting platform with a classic token owned by a senior developer. The token has full repository and package write scope and no expiration date.

When the developer announces a move to another department, the team audits the dependency. It finds the same token reused in four other workflows. The team replaces the release pipeline credential with workload identity federation that issues tokens valid for about 15 minutes, moves two internal scripts to fine-grained PATs limited to single repositories with 30-day expiry, and revokes the classic token.

The result is no production automation tied to a person, a single owner per credential in the automation inventory, and logs that clearly separate human actions from pipeline actions.