Skip to content
Cloud · Secret guide

Leaked OpenShift User Token: what to do in the first hour

Critical severityDetected onlyLast verified · 4 min read

An OpenShift user token is an OAuth access token issued to a person or service account after login. Whoever holds it acts on the cluster API with the same permissions as that user, on every project the user can reach. For a cluster administrator that means everything: reading secrets, running workloads, changing role bindings. Even a developer token can read the secrets of its projects, which often hold database passwords and cloud keys. Delete the token first, then work out what it did.

Check your GitHub account for leaked secrets — free

Provider
Openshift
Severity
Critical
Impact
Cloud infrastructure access
Checked live by LeakWatch
No

What an OpenShift user token looks like

sha256~XXXXXXXX…   OpenShift OAuth access token

The value starts with sha256~, followed by 43 characters made of letters, digits, _ and -. It is what oc whoami -t prints and what appears in the Authorization: Bearer header of calls to the cluster API. It also appears as token: in a kubeconfig file, in the output of “Copy login command” from the web console, and in variables such as OPENSHIFT_TOKEN or OC_TOKEN.

Be careful with look-alikes: the name of the token object stored in the cluster is derived from the token and, according to the Red Hat documentation, cannot be used to log in. Service account tokens are a different thing: they are JSON Web Tokens, or long-lived secrets, and are not matched by this pattern. If a kubeconfig leaked, check for both.

How OpenShift user tokens get leaked

  • Pasted login commands. The copied oc login --token=... --server=... line ends up in a README, a ticket or a chat.
  • Shell history and CI logs. A pipeline that logs in with oc login and echoes the command.
  • Committed kubeconfig files. A ~/.kube/config copied into a repository or a container image, with the token inside.
  • Pipeline variables. A token stored in a public pipeline definition rather than a masked secret.
  • Screenshots and terminal recordings of a session where oc whoami -t was run.
  • Debug output. Applications that dump the request headers they send to the cluster API.

What to do in the first hour

  1. Delete the token. Log in with another session and remove the leaked token object from the cluster (see the link below). Deleting a token logs out every session that uses it. Merely running oc logout only ends the current session’s token, so it does not help if the leaked token is a different one.
  2. Find the owner. Determine which user the token belongs to. If it is a person with cluster-admin rights, treat the incident as a full cluster compromise.
  3. Rotate what the user could read. Secrets in the projects the user can access, such as database passwords, registry credentials and cloud keys, must be assumed exposed and rotated.
  4. Audit the activity. Review the cluster audit logs and the events of the affected projects since the exposure. Look for new role bindings, service accounts, secrets read in bulk, pods with shell access and unusual image pulls.
  5. Check what the attacker could have created. Look for new deployments, cron jobs, routes, service accounts and their tokens, and webhooks in build configurations.
  6. Review access. Reset the password at the identity provider if it may also be exposed, and prefer short token lifetimes.
  7. Clean up the code. See I accidentally pushed an API key to GitHub.

Not sure what else leaked from the same repository? Run a free scan.

Not sure what else leaked? Run a free scan.

Revoke it at OpenShift

Revocation happens on your own cluster, not in a vendor account: there is no single public URL, because every cluster has its own console, reachable from your cluster console. The Red Hat documentation on managing user-owned OAuth access tokens, at https://docs.redhat.com/en/documentation/openshift_container_platform/4.22/html/authentication_and_authorization/managing-oauth-access-tokens, lists the commands: oc get useroauthaccesstokens shows the tokens of the current user and oc delete useroauthaccesstokens <token_name> removes one. A cluster administrator can remove another user’s tokens through the cluster-level OAuth access token objects. A person has not confirmed the exact commands against your version, so check the documentation for your release.

How LeakWatch detects it

The rule is called Openshift User Token. It accepts the literal prefix sha256~ followed by exactly 43 letters, digits, _ or -, starting at a word boundary and followed by a character that is not part of the token (or the end of the text). A value that is shorter, longer, or without the exact prefix is not reported. The rule does not need a variable name nearby, because the prefix is distinctive. The severity is critical. This type is not checked live: LeakWatch does not send any request to your cluster with the token it found.

LeakWatch detects this format but does not check it live: it can tell you the key is exposed, not whether it still works. Assume it does until you have revoked it.

FAQ

Does the token expire by itself?

OpenShift access tokens have a configured lifetime, set by the cluster administrator, so some expire sooner than others. Do not wait for that: delete the token as soon as you know about the leak.

Is oc logout enough?

No. It invalidates the token of the session you are using. A leaked token held by someone else keeps working until you delete that token object.

What if the leaked token belongs to a cluster administrator?

Treat the cluster as compromised: rotate every secret it could read, review all role bindings, and look for workloads you did not deploy.

Get alerted next time a secret leaks — create a free account

LeakWatch is not affiliated with Openshift.