Maschinenraum #02

A stolen laptop must not cost you the cluster

Three patterns that keep a compromised device from becoming a compromised platform.

All pieces

Falk Hähner · · 2 minute read

Count the laptops in your company that can delete your production cluster right now. The honest number usually sits in ~/.kube/config.

The risk is well documented: the Kubernetes docs advise against sharing the admin config, and Microsoft and OWASP list the kubeconfig as an attack path. The problem is less the file than what is in it. A client certificate stays valid until it expires, because Kubernetes has no revocation. If the laptop goes missing, the certificate travels with it.

Three patterns help. We use all three.

1. Short-lived logins instead of static kubeconfigs

With OIDC the API server checks a short-lived token, and your identity provider decides how long it lives. Our operations team signs in this way: personal accounts instead of a shared admin account, lifetimes in our own configuration. The access token only lives for minutes.

The difference from a certificate: a token expires on its own, and you can end the session at the identity provider.

2. Permissions per project, not per cluster

Our customers work through the portal, Git and the CLI, and their permissions apply per organisation, project and namespace. No customer gets cluster-admin or a kubeconfig. A stolen laptop gets as far as that one account. That can still hurt, but then one project is on fire and not the platform.

3. Git as the normal path

A change to an app is a commit: reviewable, traceable, reversible with git revert. The platform reconciles the cluster against the repo. With branch protection, someone holding your laptop runs into a review first.

The platform itself commits changes made to projects and namespaces in the portal, and secrets are never in Git. That is less exciting than a hotfix on a Friday evening. Which is the point.

It all comes down to one sentence: only permanent permissions can be stolen.

What you can build without us

First, take inventory. It takes a minute, and it is often the most unpleasant minute of the day:

kubectl get clusterrolebindings -o json | jq -r '
  .items[]
  | select(.roleRef.name == "cluster-admin")
  | .metadata.name as $binding
  | .subjects[]?
  | "\($binding)\t\(.kind)\t\(.name)"'

Second, OIDC instead of certificates. With kubelogin the kubeconfig looks like this. The file itself then holds no secret. The tokens sit in a cache and expire:

users:
  - name: oidc
    user:
      exec:
        apiVersion: client.authentication.k8s.io/v1
        interactiveMode: Never
        command: kubectl
        args:
          - oidc-login
          - get-token
          - --oidc-issuer-url=https://login.example.com/realms/demo
          - --oidc-client-id=kubernetes

Third, permissions per project. Bind people to namespaces through groups. Cluster-admin is kept for emergencies, and you write down in advance what counts as one.

Where does your most powerful kubeconfig live, and who has a copy?

Sources