A leaked kubeconfig file can hand a stranger the same access to a Kubernetes cluster that its owner had, and the right response depends entirely on which kind of credential sits inside it. A kubeconfig is just a YAML file that tells kubectl which API server to talk to and how to authenticate, so it may hold an embedded client certificate and key, a static bearer token, a service account token, or only an exec plugin command that fetches short-lived credentials from a cloud identity. Each of those is revoked in a different way, and one of them cannot be revoked at all short of rotating the cluster certificate authority. This guide is for platform, SRE and incident response teams who have just found a kubeconfig in a public repository, a paste site, a CI log, a support ticket or a laptop image. It covers how to identify the credential type within minutes, contain it in the right order, check the audit trail for use, and recover without breaking every legitimate client. For a cluster you already believe is compromised, move to the full Kubernetes Cluster Compromise Playbook.
Key takeaways
- Read the users block first. Whether the file holds
client-certificate-data,token, or anexecsection decides every later step, so open the file and classify it before touching the cluster. - Client certificates cannot be revoked. The Kubernetes documentation states that it does not support certificate revocation and that an issued certificate stays valid until it expires, so a leaked admin certificate usually means rotating the cluster CA.
- Exec plugin files move the problem to the cloud identity. An EKS, AKS or GKE kubeconfig that only calls a plugin holds no secret of its own; check whether the cloud credentials that the plugin uses leaked alongside it.
- Remove the authorisation while you prepare the revocation. Deleting RoleBindings and ClusterRoleBindings for the leaked identity buys time, but it does nothing for certificates in the
system:mastersgroup, which bypasses RBAC. - Prove use or non-use from the audit log. Search API server audit events for the leaked username, groups, source IPs and user agents from the moment of exposure, and keep that evidence before logs roll over.
How the incident shows up
Kubeconfig leaks are almost always found as a file or a pasted block of YAML rather than by a cluster alert. The structure is easy to recognise: top-level clusters, users and contexts lists, a current-context, and a server: URL pointing at an API endpoint, often on port 443 or 6443. The Kubernetes documentation notes that kubectl looks for a file named config in $HOME/.kube by default and that the KUBECONFIG environment variable or --kubeconfig flag can point elsewhere, which is why the file turns up under many names.
| Where it is found | Typical cause | First signal |
|---|---|---|
| Public or internal Git repository | .kube/config, admin.conf or kubeconfig.yaml committed with project files or dotfiles | Secret scanning alert, external researcher report |
| CI/CD logs and artefacts | Pipeline prints KUBECONFIG contents, or uploads the workspace as an artefact | Log review, secret scanning of build output |
| Container images | Kubeconfig copied into an image layer during build | Image scanning, registry review |
| Tickets, chat and paste sites | File shared to get help debugging access | Data loss prevention match, colleague report |
| Lost or reimaged laptop, departed staff | Long-lived admin kubeconfig kept locally | Asset or offboarding review |
| Cluster itself | Unfamiliar user agent or source IP using a known admin identity | Audit log detection rule |
The Kubernetes project also warns that a specially crafted kubeconfig can lead to code execution or file exposure, so only open untrusted files as text, never by pointing kubectl at a file you received from outside.
Triage questions
Answer these in the first 30 minutes. Work from a copy of the file viewed as plain text.
- Which credential type is in each user entry? Use the table below. A single file can hold several users and clusters.
- Which cluster and environment? Match the
serverURL and the CA data to a known cluster. Production, shared platform and management clusters come first. - Is the API endpoint reachable from the internet? A private endpoint lowers the immediate risk but does not remove it; insiders and compromised hosts on the network can still reach it.
- What identity does it map to? For certificates, decode the subject: the common name (CN) is the username and organisation (O) values are groups. Check for
system:mastersorkubeadm:cluster-admins. - When was it first exposed, and is it still exposed? The commit date, paste time or artefact upload date sets the start of your audit log search window.
- What else leaked with it? A kubeconfig in a dotfiles repository often sits next to cloud CLI credentials, SSH keys and
.envfiles.
| Field in the users entry | Credential type | Can it be revoked directly? | Primary containment action |
|---|---|---|---|
client-certificate-data and client-key-data | X.509 client certificate signed by the cluster CA | No, valid until notAfter | Remove RBAC bindings; rotate the cluster CA if the subject is privileged or long-lived |
token holding a JWT whose issuer is the cluster | Service account token (legacy Secret-based or TokenRequest) | Secret-based: yes, delete the Secret. TokenRequest: no specific mechanism, wait for expiry or rotate signing keys | Delete the token Secret or the service account; remove bindings |
token that is not a cluster JWT | Static token file entry, bootstrap token, or OIDC id_token | Static: edit the token file and restart the API server. Bootstrap: delete the token Secret in kube-system. OIDC: no, short-lived by design | Remove the entry; revoke the user's session at the identity provider |
exec with aws, kubelogin or gke-gcloud-auth-plugin | Exec credential plugin fetching short-lived tokens from a cloud identity | The file holds no secret; the cloud credentials do | Check for leaked cloud keys; review cloud and cluster access mappings |
username and password | Basic authentication (a legacy option that the current Kubernetes authentication documentation no longer lists) | Depends on the distribution | Treat as a legacy cluster finding; disable and upgrade |
Containment priorities
Contain in this order. Each step is safe to take before the next is ready.
- Stop further exposure. Make the repository private or remove the file, take down the paste, purge the CI artefact. This does not undo the leak: assume anything public for even a few minutes has been copied.
- Remove authorisation for the leaked identity. List RoleBindings and ClusterRoleBindings whose subjects match the username, groups or service account and delete or edit them. For managed clusters, remove the cloud mapping too: delete the EKS access entry for the IAM principal, or remove the Entra group or Azure role assignment on AKS. This step is fast and reversible.
- Revoke what can be revoked. Delete a Secret-based service account token, delete the service account if it is single-purpose, remove a static token from the token file, delete a bootstrap token, or disable the identity provider account and revoke its sessions. The Kubernetes documentation notes that with
--service-account-lookupenabled, tokens deleted from the API are revoked. - Decide on CA rotation for certificates. If the leaked certificate carries
system:masters(kubeadm'ssuper-admin.conf) or any long-lived admin identity, RBAC changes do not help: the Kubernetes RBAC documentation describessystem:mastersas bound tocluster-admin, and kubeadm describes it as a break-glass group that bypasses authorisation. Plan a CA rotation now, even if it runs later in the day. - Restrict network reach while you rotate. Narrow the API server's authorised IP ranges or switch to a private endpoint where the platform supports it, so the leaked credential cannot be used from outside while rotation is prepared.
- Rotate any cloud credentials found alongside. For exec plugin files, the cloud access key, refresh token or service account key is the real secret. See the Leaked Credential Response Playbook.
Managed cluster specifics
- Amazon EKS:
aws eks update-kubeconfigwrites an entry that authenticates withaws eks get-token, so access depends on the IAM principal. Review access entries (AWS describes them as the way to grant IAM principals Kubernetes permissions and to restore access through the EKS API) and any remainingaws-authConfigMap mappings. See the Amazon EKS Security Hardening Guide. - Azure Kubernetes Service: Microsoft describes local accounts as enabled by default and the
--admincredential as a non-auditable path. If an admin kubeconfig leaked, runaz aks rotate-certsto rotate the cluster CA and refresh child certificates, then reissue user credentials withaz aks get-credentials. Microsoft also advises rotating certificates after disabling local accounts on a cluster where people may have held local credentials. See the Azure Kubernetes Service Security Hardening Guide. - Google Kubernetes Engine: Google's credential rotation replaces the control plane IP, cluster root CA, service account signing keys and aggregation layer CA. Old credentials are revoked at the complete step, and GKE completes a rotation automatically seven days after it starts. See the GKE Security Hardening Guide.
Eradication
Eradication means the leaked credential no longer works and nothing the attacker could have created survives.
- Self-managed CA rotation: The Kubernetes manual CA rotation task asks you to back up the certificate directory first, assumes a highly available control plane, and warns that a single API server will be unavailable while it restarts. The process distributes the new CA alongside the old, updates the
certificate-authority-datain kubeconfig files, updates service account tokens and thecluster-infoConfigMap where bootstrap tokens are used, restarts components as a rolling update, and only then removes the old CA. Pods using an in-cluster kubeconfig need a restart to pick up the new data. - Service account signing keys: Because TokenRequest tokens have no specific invalidation mechanism, a leaked token bound to a long-running workload is removed by deleting the Pod it is bound to (which expires its bound tokens), or by rotating the signing key set by
--service-account-key-filewhen the scope is wide. See How to rotate a Kubernetes service account token and detect old token use. - Persistence sweep: Look for objects created by the leaked identity during the exposure window: new ClusterRoleBindings, service accounts with token Secrets, CertificateSigningRequests approved for client authentication, mutating or validating webhooks, DaemonSets, privileged Pods, and changes to
kube-system. Each one can outlive the credential that created it. - Source removal: Remove the file from Git history, not just the latest commit, and rotate first: rewriting history does not reach clones and forks already made. See the Git Secret Scanning Guide.
Recovery
- Reissue legitimate access with less privilege. kubeadm's documentation warns against sharing
super-admin.conforadmin.confand recommends least privileged credentials even for administrators, keeping the super-admin file for break-glass use only. Use this event to move people to identity provider sign-in with group-based RBAC. - Prefer short-lived credentials. Issue client certificates through the CertificateSigningRequest API with
spec.expirationSeconds(honoured from Kubernetes v1.22) rather than year-long certificates, or use OIDC or cloud exec plugins. - Update every client. CI runners, GitOps controllers, monitoring agents and operators that hold kubeconfigs need the new CA data and new credentials. Inventory them before the old CA is removed, not after.
- Restore network exposure only as needed. Keep authorised IP ranges or a private endpoint if the incident showed the public endpoint was not required.
- Confirm the old credential fails. From an isolated test host, use a copy of the leaked kubeconfig against the API server and confirm an authentication failure. Record the result as evidence of closure.
Evidence to preserve
Collect these before rotation and before audit logs roll over. The Kubernetes audit documentation describes events generated at request stages, filtered by a policy and written to a log file or webhook backend, so confirm where your cluster's events go and how long they are kept.
| Evidence | Where it lives | What it answers |
|---|---|---|
| The leaked file, with hash and discovery context | Repository, paste, artefact store | Exactly which credentials and clusters were exposed |
| Exposure timeline | Commit history, platform audit logs, paste metadata | Start of the search window |
| API server audit events for the identity | Audit log backend, cloud control plane logs | Was it used, from where, and for what (user, sourceIPs, userAgent, verb, objectRef) |
| Cloud audit trail | AWS CloudTrail, Azure Activity Log, Google Cloud Audit Logs | Credential retrieval (for example az aks get-credentials --admin) and access mapping changes |
| RBAC and object snapshots | kubectl get exports of bindings, service accounts, webhooks, CSRs | What existed before you changed it |
| Certificate details | Decoded subject, issuer, serial, notAfter | Identity, groups and natural expiry |
Useful audit annotations include authorization.k8s.io/decision and, for legacy service account tokens, authentication.k8s.io/legacy-token-invalidated, which Kubernetes adds when an invalidated auto-generated token is used. See the Kubernetes Audit Log Detection Guide for query patterns.
Notification triggers
- Personal data: If the audit trail shows reads of Secrets, ConfigMaps or volumes holding personal data, or you cannot rule it out, GDPR Article 33 requires notification to the supervisory authority without undue delay and, where feasible, within 72 hours of becoming aware of a personal data breach that is likely to result in a risk to individuals. Record the decision either way.
- Sector and national rules: Operators within NIS2 scope, DORA scope or US federal contracts have their own reporting clocks for significant incidents. Use the Cyber Incident Reporting Requirements Map to check which apply.
- Customers and partners: Multi-tenant platforms and managed service providers usually have contractual notice duties when a shared cluster credential leaks, even without evidence of use.
- Researcher reports: If an external researcher reported the leak, acknowledge receipt and confirm remediation in line with your disclosure policy.
Detection and measurement
- Alert on admin identities from new places: Requests from
system:mastersmembers,kubernetes-adminor break-glass users from source IPs outside your management ranges. - Alert on credential minting: Creation of token Secrets, approved client-authentication CSRs, and new ClusterRoleBindings to
cluster-admin. - Scan for kubeconfig patterns: Secret scanners should flag files containing
client-key-data,apiVersion: v1withkind: Config, and bearer tokens in YAML.
| Metric (NHI Mgmt Group suggestion) | Target |
|---|---|
| Time from discovery to RBAC removal for a leaked identity | Under 1 hour |
| Clusters with local or static admin credentials enabled | Zero outside documented break-glass |
| Human client certificates with lifetime over 24 hours | Trending to zero |
| Clients inventoried before a CA rotation starts | 100% |
| Audit log retention on production clusters | At least the period your exposure windows need, often 90 days or more |
Framework mapping
| Framework | Reference | How it applies |
|---|---|---|
| MITRE ATT&CK | T1552.001 Credentials In Files; T1078.004 Cloud Accounts; T1609 Container Administration Command; T1613 Container and Resource Discovery | Leaked kubeconfig use, follow-on cluster actions |
| NIST SP 800-53 Rev 5 | IR-4 Incident Handling; IA-5 Authenticator Management; AC-2 Account Management; AU-6 Audit Record Review; SC-12 Cryptographic Key Establishment and Management | Response, revocation, CA and key rotation, log review |
| NIST CSF 2.0 | RS.MI-01; RS.AN-03; RC.RP-01; PR.AA-05 | Containment, analysis, recovery, least privilege re-issue |
Practitioner checklist
- Classify every user entry in the leaked file as certificate, token or exec plugin before acting.
- Remove the exposed copy and assume it has already been copied.
- Delete RBAC bindings and cloud access mappings for the leaked identity within the first hour.
- Revoke Secret-based tokens, static tokens, bootstrap tokens and identity provider sessions where they apply.
- Plan a cluster CA rotation for any leaked privileged or long-lived client certificate, with all clients inventoried first.
- Restrict API server network exposure while rotation is prepared.
- Export audit events, cloud trail entries and RBAC snapshots before changing anything else.
- Sweep for persistence created during the exposure window: bindings, service accounts, CSRs, webhooks, DaemonSets.
- Reissue access through identity provider sign-in or short-lived certificates, and keep super-admin credentials offline.
- Record the notification decision and confirm the leaked credential now fails.
Standards and references
- Kubernetes: Authenticating
- Kubernetes: Organizing Cluster Access Using kubeconfig Files
- Kubernetes: Manual Rotation of CA Certificates
- Kubernetes: Managing Service Accounts
- Kubernetes: Certificate Management with kubeadm
- Kubernetes: Auditing
- Microsoft Learn: Certificate management and rotation in AKS
- Google Cloud: Rotate your cluster credentials (GKE)
Related NHI Mgmt Group resources: Kubernetes Cluster Compromise Playbook · Kubernetes RBAC Guide · Kubernetes NHI Security Guide · Leaked Credential Response Playbook