Hack fixing the lack of Kubernetes certificate revocation
Recently I was taking another look at one of my perennial favourite Kubernetes security problems, the lack of certificate revocation and, with some agentic assistance, I realised there’s a kind of hacky approach that will work to mitigating some of the risks of using client certificate authentication in Kubernetes.
Background
One of the challenges of using Kubernetes is that none of the in-built authentication methods are suitable for production use, meaning that anyone using Kubernetes has to implement their own authentication, generally by tying it to an external IAM source like cloud IAM or an LDAP directory. This isn’t ideal for smaller orgs, which leaves them looking for the “least bad” alternative, which is client certificates.
In many ways client certificates aren’t a bad form of authentication, but a major headache in Kubernetes is the lack of certificate revocation support. This is a known issue going back to 2015, but at the moment there’s no official solution.
Hacking up a fix
So if we want to use client certificate authentication how do we fix this problem? Well since Kubernetes v1.32, when a request is authenticated with a client certificate, the API server attaches a credential ID to the user’s information, in the authentication.kubernetes.io/credential-id extra field. This isn’t something stored in the certificate itself, it’s calculated by the API server as a SHA-256 hash of the certificate (X509SHA256=<hash>), which means that every client certificate can be uniquely identified, even ones that were issued long before v1.32. This opens up the idea that if we can intercept authorization decisions in the API server, we can have a mechanism to revoke access by marking a specific credential ID as revoked.
As a proof of concept I knocked up a tool called certrevoker which works as an operator in a Kubernetes cluster. This is very much a proof of concept, so don’t deploy it in a production cluster without a lot of improvement :D
The first stage is to keep track of the client certificates that exist in the cluster, as Kubernetes doesn’t keep any record of the certificates it issues (approved CSRs are cleaned up about an hour after issue). This is done by watching CSR objects. When a client certificate has been signed and added to the CSR, certrevoker picks it up and creates a new object in Kubernetes called an IssuedCertificate which contains information about the cert including the credential ID. Not every certificate goes via the CSR API though (for example the ones kubeadm creates for kubeconfig files), so certrevoker also records any credential IDs it sees being used, which helps fill in the gaps.

Then we have an authorization webhook for the cluster, which is placed in the authorization chain before the Node and RBAC authorizers. The API server is configured to call the webhook for any request authenticated with a client certificate, and part of the information passed to the webhook is the credential ID. The webhook checks that against the list of revoked certificates and, if the certificate has been revoked, returns an explicit deny. An explicit deny stops the authorization chain, so RBAC never gets a chance to allow the request. For anything that isn’t revoked the webhook returns “no opinion” and the request carries on to RBAC as normal. The API server caches these decisions briefly, so a revocation does take a few seconds to kick in.

To revoke certificates there’s a web portal that is available to administrators. They log in with a Kubernetes token, and the portal uses that token for all its actions, so access is controlled by standard RBAC and the API server audit log shows who did what. From there they can view a list of certificates and pick one to revoke, along with a reason for the revocation. Revocations can also be undone, and if you’ve got a certificate or kubeconfig file that isn’t in the list, you can paste it into the portal to get its credential ID. As revocations are just Kubernetes objects, you can also manage them with kubectl if you prefer.

Limitations
As with any hack, there are some important caveats:
system:masterscertificates can’t be revoked. The API server allows any request from a member of thesystem:mastersgroup before it calls any of the configured authorizers, so those requests never reach the webhook. Unfortunately that includes things like the kubeadmadmin.confcertificate, which is one of the ones you’d most like to be able to revoke!- It fails open. If certrevoker is unavailable, the API server treats that as “no opinion” and carries on to RBAC, so revoked certificates will work again until it comes back. This is deliberate, as in a kubeadm cluster the kubelets, controller manager and scheduler all authenticate using client certificates, so failing closed would break the cluster during an outage.
The Future
Whilst this is a useful option if you want to use certificate authentication in Kubernetes now, it’s obviously not the best solution long term. Here KEP 6285 will hopefully move forward providing a supported mechanism for rejecting specific client certificates.