Kubernetes Security & Hardening›Identity & Access · Cheat sheet & self-check

Identity & Access · wrap-up

Cheat sheet & self-check

Every command from this section on one page.

01 · Cluster PKI & certificates

Inspect certificates

sudo kubeadm certs check-expirationExpiry of every kubeadm-managed certificate
openssl x509 -in cert.crt -noout -subject -issuer -enddateWho, signed by whom, valid until
openssl x509 -in apiserver.crt -noout -ext subjectAltNameNames and IPs the API server cert is valid for
echo | openssl s_client -connect <host>:6443 2>/dev/null | openssl x509 -noout -datesCheck a live endpoint's certificate

Kubelet certificates

ls -l /var/lib/kubelet/pki/kubelet client/serving certs on a node
kubectl get csrCertificate signing requests (e.g. kubelet serving certs)
kubectl certificate approve <csr>Approve a pending CSR (after checking it!)

02 · cert-manager in production

Install & inspect

helm repo add jetstack https://charts.jetstack.ioAdd the cert-manager chart repository
helm install cert-manager jetstack/cert-manager -n cert-manager --create-namespace --set crds.enabled=trueInstall with CRDs (older charts: installCRDs=true)
kubectl get clusterissuers,issuers -AConfigured issuers and their readiness
kubectl get certificate -ACertificates, Ready status and secret names
kubectl describe certificate <name>Events: why it isn't issued yet
kubectl get certificaterequests,orders,challenges -AThe issuance pipeline (ACME)

03 · Authentication methods

Who am I?

kubectl auth whoamiUsername and groups the API server sees
kubectl config view --minifyThe user entry kubectl is using

Client certificate via the CSR API

openssl genrsa -out asha.key 2048A private key
openssl req -new -key asha.key -subj "/CN=asha/O=devops" -out asha.csrCN = username, O = group
kubectl certificate approve ashaApprove the CertificateSigningRequest
kubectl get csr asha -o jsonpath='{.status.certificate}' | base64 -d > asha.crtFetch the signed certificate

ServiceAccount tokens

kubectl create token app -n shop --duration=1hA short-lived token for a ServiceAccount
cat /var/run/secrets/kubernetes.io/serviceaccount/tokenThe projected token inside a pod

04 · OIDC login for kubectl

API server (kube-apiserver flags)

--oidc-issuer-url=https://sso.example.com/realms/platformWho issues the tokens (must be HTTPS)
--oidc-client-id=kubernetesThe audience (client) tokens must be issued for
--oidc-username-claim=email --oidc-username-prefix=oidc:Which claim becomes the username (with a prefix)
--oidc-groups-claim=groups --oidc-groups-prefix=oidc:Which claim holds group membership

kubectl side (kubelogin)

kubectl krew install oidc-loginInstall kubelogin as a kubectl plugin
kubectl oidc-login setup --oidc-issuer-url=… --oidc-client-id=kubernetesTest the login and print the claims
kubectl auth whoamiConfirm username and groups

05 · SSO, federation & MFA

Design checklist

One source of identityEnterprise IdP (Entra ID, Okta, Google…) for every cluster
Broker when neededKeycloak/Dex/Pinniped federate the IdP to many clusters
MFA at the IdPKubernetes never sees passwords or second factors
Short tokensMinutes, refreshed by the IdP; faster offboarding
Break-glassOffline, sealed, monitored credentials: rotated after every use

Useful commands

kubectl auth whoamiConfirm who you're logged in as
sudo kubeadm kubeconfig user --client-name=breakglass-2026q3 --org=kubeadm:cluster-adminsGenerate a separate emergency admin kubeconfig (kubeadm)

06 · RBAC design at scale

Review access

kubectl auth can-i --list --as=oidc:asha@example.com --as-group=oidc:developers -n shopEverything a user+group may do in a namespace
kubectl get clusterrolebindings -o wideCluster-wide grants and their subjects
kubectl who-can get secrets -n shopWho can read secrets (kubectl-who-can plugin)
kubectl get clusterroles -l rbac.authorization.k8s.io/aggregate-to-edit=trueRoles aggregated into 'edit'

Dangerous verbs & resources

secrets: get/list/watchRead every credential in scope
pods: create (any)Run as any ServiceAccount in that namespace, mount its Secrets
bind / escalate on rolesGrant yourself more than you have
impersonateAct as another user or group
nodes/proxy, pods/execReach into nodes or containers