Join our Newsletter — 33% off our NHI Course
Home› Guides› Docker Hub Tokens Security Guide: Access Tokens, Scopes…
Guide Non-Human Identity (NHI)

Docker Hub Tokens Security Guide: Access Tokens, Scopes and Image Secret Hygiene

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 26 October 2026 13 min read
On this page

Docker Hub access tokens decide who can push the images your production clusters pull, and the images themselves are one of the most common places secrets leak. A personal access token with write permission can overwrite a trusted tag in every repository its owner can reach, and a token or API key copied into an image layer is published to anyone who runs docker pull. This guide covers both sides of the problem: how identity, roles and tokens work in Docker Hub, how to choose and scope personal and organisation access tokens, what to log and how to keep credentials out of the images you publish. It is written for platform engineers, DevSecOps teams and the administrators who own a Docker Hub organisation.

Key takeaways

  • Use organisation access tokens for automation. OATs belong to the organisation, can be limited to specific repositories and scopes, and survive the departure of the person who created them; personal access tokens do not.
  • PAT permissions are account-wide. A PAT has one repository permission that applies to every repository the account can access, so a "Read & Write" PAT for one pipeline can push to all of them.
  • Expiry is not on by default. Both PATs and OATs default to "None" (never expire), and the expiry date cannot be changed later, so set 30 or 90 days at creation.
  • Deleting a leaked secret from an image does not revoke it. Layers persist in every copy already pulled; revoke and reissue the credential, then rebuild.
  • Build secrets belong in secret mounts. Docker's documentation says build arguments and environment variables persist in the final image; use RUN --mount=type=secret instead.

How identity and access work in Docker Hub

Docker Hub has user accounts, organisations that own repositories and teams, and, on Docker Business, companies that group several organisations. People sign in with a password, through SSO, or with a token. Automation should never use a password: once two-factor authentication is turned on or SSO is enforced, the CLI does not accept the account password at all and a token is required.

PATs and OATs compared

AttributePersonal access token (PAT)Organisation access token (OAT)
OwnerA user account; acts as that userThe organisation; any organisation owner can view, edit, deactivate or delete it
SubscriptionAvailable to individual accountsDocker Team or Docker Business
Repository scopeOne permission level across every repository the account can accessUp to 50 named repositories, or all organisation repositories, each with its own scopes
Other scopesOptional Cloud Sandboxes access (sandbox:use)Organisation scopes (members, audit log, repository creation and more) and product scopes
Expiry optionsNone (default), 30 days, 90 days, custom up to one yearNone (default), 30 days, 90 days, custom up to one year
Sign-in usernameThe Docker usernameThe organisation name
LimitsAuto-generated tokens capped at five per account; fair use applies10 per organisation on Team, 100 on Business; expired and deactivated tokens count until deleted
Works with Docker Desktop and Image Access ManagementYesNo
Best forA person using the CLI or DesktopCI/CD, deployment and registry automation

PAT permission levels

  • Repo Public Read-only (default): view, search and pull public repositories.
  • Repo Read-only: adds private repositories the account can access.
  • Repo Read & Write: adds push to repositories the account manages.
  • Repo Read, Write, Delete: adds deleting images and managing repositories.
  • No repository access: for tokens used only for Cloud Sandboxes.

Permissions can be changed while a PAT is active or inactive, but not after it expires. Docker does not let you limit a PAT to a single repository; if a job needs that, it needs an OAT.

Admin roles and privileged access

RoleKey permissionsToken relevance
Organisation ownerAll organisation settings: members, roles, teams, SSO and SCIM, Image and Registry Access Management, billing; repository activity and publisher programmesCan create, view, edit, deactivate and delete every OAT
Company ownerSame organisation management as an owner across the company; push and pull permissions do not applyCan manage OATs for organisations in the company
EditorCreate, edit and delete repositories, manage tags, assign team permissions to repositoriesA PAT from an editor with Read, Write, Delete can remove images across the organisation
MemberView members and pull from repositories the member can accessA member PAT is effectively read-only
Custom role (Business)Granular organisation permissions, including "Manage organization access tokens"Lets a platform team manage OATs without full ownership
  • Keep owners few: owners control SSO, SCIM and every OAT. Use two or three named owners and grant other administrators a custom role.
  • Use teams for repository access: custom roles do not grant pull access to private repositories; team permissions do. Avoid making people editors just so a pipeline under their PAT can push.
  • Enforce SSO and 2FA: with SSO enforced, the CLI requires a token, which removes reusable passwords from scripts. Before enforcing, Docker advises ensuring CI/CD pipelines use PATs or OATs instead of passwords.
  • Remember the leaver problem: a PAT is tied to its creator. If a pipeline runs on an engineer's PAT, either it breaks when they leave or, worse, the account is kept alive to avoid the break. Move such pipelines to OATs. See the OWASP NHI Top 10 NHI10 Human Use of NHI Guide.

Integrations, API tokens and service accounts

OAT scopes worth knowing

OAT scopes are hierarchical: a more capable scope includes the lesser ones in its set.

Scope (value)IncludesUse it for
Image Pull (scope-image-pull)NoneDeployment targets and clusters that only pull
Image Push (scope-image-push)Image PullThe release job for a named repository
Image Delete (scope-image-delete)Image PushRetention clean-up jobs only
Tag Admin (scope-tag-admin)Tag ReadRarely needed by pipelines
Webhook Admin (scope-webhook-admin)Webhook Edit, Webhook ReadIntegration set-up; a changed webhook can redirect events
Repository Admin (scope-repository-admin)Repository Edit, Repository ReadAdministrative automation, not builds
Repository Create (scope-repository-create, organisation scope)NoneProvisioning automation; no repository scope grants it
Audit Log Read (scope-activity-read)NoneSIEM collectors pulling activity logs
Member Edit (scope-member-edit)Member ReadIdentity automation; treat as privileged

Choosing a token for each job

JobTokenScope and expiry
CI build and push for one serviceOATImage Push on that repository only, 90 days or less
Kubernetes image pull secretOATImage Pull on the repositories the namespace runs; avoid "all organisation repositories"
Developer using the CLI with SSO enforcedPATRepo Read-only unless they publish by hand; 30 to 90 days
Docker Desktop or Image Access ManagementPATOATs are not supported here
Log collection to a SIEMOATAudit Log Read only
Individual account with no organisationPAT per pipelineLowest permission level, one token per system so revocation is targeted

Handling tokens on clients and runners

  • Use --password-stdin: it keeps the token out of shell history and logs. Never pass it with -p on the command line.
  • Configure a credential store: without one, Docker writes base64-encoded credentials into ~/.docker/config.json, which Docker itself describes as less secure. Set credsStore (osxkeychain, wincred, pass or secretservice) or per-registry credHelpers.
  • Clean up ephemeral runners: on self-hosted runners, run docker logout at the end of the job or use a fresh home directory, so the next job cannot read the previous job's config.json.
  • Store tokens in a vault: the token is shown once and Docker does not store it. Record owner, purpose, scopes and expiry in your inventory at creation. See the Secrets Management Guide.

Image secret hygiene

Token scoping protects the registry. The other half of the problem is secrets carried inside the images it serves. The Docker Hub Secrets Leak 2025 found 10,456 images uploaded in a single month that exposed keys, most often AI model API keys, through packed .env files, hardcoded source, secrets written directly into Dockerfiles and whole project directories copied into the build. Earlier academic work, summarised in Secrets in Docker Hub Images, found secrets in about 8.5% of 337,171 images, including private keys still used by live TLS and SSH hosts.

How secrets get inFix
ARG or ENV holding a tokenRUN --mount=type=secret,id=npm with docker build --secret id=npm,src=...; the secret is available only for that instruction
Private Git clone with an embedded tokenSSH mount: docker buildx build --ssh default .
COPY . . pulling in .env, .npmrc, .git or caches.dockerignore listing secrets files, VCS folders and caches such as __pycache__
Secret written then deleted in a later layerMulti-stage build; copy only artefacts into the final stage
Runtime config baked into the imageInject at runtime from an orchestrator or secrets manager
Work images pushed to personal or contractor namespacesRequire corporate namespaces; monitor public registries for your organisation's names and key patterns

Scan the built image, not only the source. In the PyPI Admin GitHub Token Leak 2024, a token that was never committed reached public images through a compiled .pyc file because the .dockerignore did not exclude caches. See the Container Image Security Guide.

Logging and detection

Docker Hub activity logs are available on Team and Business. Docker Home keeps them for 90 days, the UI queries up to 30 days at a time, and the audit logs API returns up to three months of events in requests of up to 31 days. Export them to your SIEM with an OAT that holds only Audit Log Read, because 90 days is shorter than many exposure windows.

EventWhy it mattersResponse
Access token created or updatedNew credential or widened scopesMatch against an approved change; check scopes
Access token revoked or deletedExpected during rotation; unexpected deletion may hide tracks or break pipelinesConfirm owner action
Tag Pushed outside release windowsPossible push with a stolen tokenCompare with CI run IDs and image digests
Privacy ChangedA private repository made public can publish embedded secretsAlert immediately; verify intent
Repository Deleted or Tag DeletedDestructive use of a delete-capable tokenRestore from your build system; revoke the token
Tag immutability updatedTurning immutability off enables tag overwriteTreat as a privileged change

Also review the "Last used" column on PAT and OAT lists: tokens unused for 30 days are candidates for deletion, and use of a token outside its pipeline's schedule is worth investigating. Relevant ATT&CK techniques are T1528 Steal Application Access Token, T1552.001 Credentials In Files and T1195.002 Compromise Software Supply Chain.

Metrics that show it is working

  • Automation on OATs: percentage of CI/CD and cluster pull credentials that are OATs rather than PATs.
  • Expiry coverage: percentage of active tokens with an expiry of 90 days or less (target 100%).
  • Least scope: number of OATs with "all organisation repositories" or Image Delete, trending down.
  • Stale tokens: count of tokens not used in 30 days.
  • Image secret findings: secrets detected in built images per month, and the share revoked (not just removed) within 24 hours.
  • Log export continuity: days of activity log history held outside Docker Hub.

Hardening baseline

  1. Inventory: list every PAT and OAT, its creator, scopes, expiry and last used date, and map each to the pipeline or person that uses it.
  2. Enforce identity controls: turn on 2FA for all members and, on Business, configure and enforce SSO after confirming pipelines use tokens.
  3. Pilot OATs: move one service's build and pull credentials to OATs scoped to its repository, run for a release cycle, then revoke the old PAT. Keep the PAT deactivated (not deleted) for a week as a rollback path.
  4. Migrate by risk: production image pushes first, then cluster pull secrets, then everything else.
  5. Set expiry and rotation: 90 days or less for every token, with a rotation runbook; because expiry cannot be edited, rotation means creating a new token.
  6. Fix the build: adopt secret mounts, multi-stage builds and .dockerignore, and add image secret scanning as a blocking gate before push.
  7. Protect tags: enable tag immutability on release repositories and deploy by digest.
  8. Stream logs: export activity logs to the SIEM and alert on the events above.

Framework mapping

Control areaNIST SP 800-53 Rev 5NIST CSF 2.0CIS Controls v8.1ISO/IEC 27001:2022 Annex A
Token issuance, expiry and storageIA-5 Authenticator ManagementPR.AA-01Control 5 Account ManagementA.5.17 Authentication information
Scoped OATs, roles and teamsAC-6 Least PrivilegePR.AA-05Control 6 Access Control ManagementA.8.2 Privileged access rights
Secret-free images and minimal build contextsCM-7 Least FunctionalityPR.PS-01Control 16 Application Software SecurityA.8.9 Configuration management
Image integrity and trusted tagsSR-11 Component AuthenticityGV.SC-05Control 16 Application Software SecurityA.5.21 Managing information security in the ICT supply chain
Activity log reviewAU-6 Audit Record Review, Analysis, and ReportingDE.AE-02Control 8 Audit Log ManagementA.8.15 Logging

Common misconfigurations

  • Pipelines on a person's PAT: the token carries that person's access to every repository and dies, or lingers, with their account.
  • Never-expiring tokens: "None" is the default for both token types. Tokens created years ago with Read, Write, Delete remain valid until someone deletes them.
  • "All organisation repositories" on a pull secret: one leaked cluster secret then exposes every private image, and any secrets inside them.
  • Removing the image, keeping the key: in the Flare study about a quarter of developers removed a leaked secret within a day or two, but most did not revoke it, so anyone who had pulled the image could still use it.
  • Plain-text config.json on shared runners: without a credential store, a token sits base64-encoded on disk for the next job or any malware on the host.
  • Short log retention: relying on 90 days of in-product history means a token leaked longer ago cannot be investigated, as PyPI found when GitHub's 90-day security log limit left the start of a 15-month image exposure unexplained.

Practitioner checklist

  • Inventory every PAT and OAT with owner, scopes, expiry and last used date.
  • Move CI/CD and cluster pull credentials from PATs to OATs scoped to named repositories.
  • Set an expiry of 90 days or less on every new token and delete tokens unused for 30 days.
  • Limit owners, use custom roles for token administration and teams for repository access.
  • Enforce 2FA and, on Business, SSO once pipelines no longer use passwords.
  • Configure credential stores and use --password-stdin on every client and runner.
  • Use secret mounts, multi-stage builds and .dockerignore, and scan built images before push.
  • Revoke and reissue any credential found in an image, then rebuild and republish.
  • Export activity logs to the SIEM and alert on token changes, privacy changes and deletions.

Standards and references

Related NHI Mgmt Group resources: Container Registry Security Guide · Container Image Security Guide · npm Tokens Security Guide · Kubernetes NHI Security Guide · API Key Management Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 26 October 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.