Skip to content
LF Cert Trainer

Lesson 76 · Section 7: Security

Lesson 76: Certificates API: getting certificates signed through the cluster

How the CertificateSigningRequest object replaces copying the CA key around: who creates a request, who approves it, which controller signs it, and the exam routine for giving a new user a client certificate. · 18 min read · 4 min video

1/10Certificates API
0:00 / 4:07

Narrated by the local narrator voice. Keys: Space plays and pauses, J and L step, C captions, F full screen.

Why it exists

In the Certificate Creation lesson you made certificates by hand: generate a key, write a signing request, and sign it with openssl x509 -req -CA ca.crt -CAkey ca.key. That last step needs the cluster's CA private key, and whoever can read that key can mint any identity in the cluster, including a member of system:masters.

That is fine while you are the only administrator. It stops working as soon as the cluster has more people and more machines:

  • Every new user needs a certificate, and every certificate expires and must be renewed.
  • Every new node needs certificates for its kubelet.
  • The CA key should stay on the control plane, readable by as few people as possible.

If signing means "log in to the control plane node and run openssl as root", then either one person becomes a bottleneck or the CA key starts travelling. The Certificates API solves this by turning signing into an ordinary API request: anyone may ask for a certificate, someone with the right permission approves, and a controller that already sits next to the CA key signs.

What it is

The API group is certificates.k8s.io, and its main resource is the CertificateSigningRequest, short name csr. It is cluster-scoped: there is no namespace, because a certificate identifies someone to the whole cluster.

From a private key to a signed certificatecreatereviewApprovedissuesdecodeJanejane.key + jane.csrCSR objectPendingApproverapprove or denyController managersigns with ca.keyCertificatestatus.certificatekubeconfigjane.crt + jane.key
From a private key to a signed certificate. The private key never leaves the user and the CA key never leaves the control plane. Only the request and the finished certificate travel, and both travel through the API.

Parts:

  • Jane (jane.key + jane.csr)
  • CSR object (Pending)
  • Approver (approve or deny)
  • Controller manager (signs with ca.key)
  • Certificate (status.certificate)
  • kubeconfig (jane.crt + jane.key)

Connections:

  • Jane to CSR object: create
  • CSR object to Approver: review
  • Approver to Controller manager: Approved
  • Controller manager to Certificate: issues
  • Certificate to kubeconfig: decode

Do not confuse the two things that are both called "CSR":

NameWhat it isWhere it lives
The CSR file (jane.csr)A PEM file made by openssl req -new: a public key plus the requested subject, signed with the private keyOn the requester's machine
The CSR objectA Kubernetes resource that carries that file in spec.request and tracks approval and the resultIn etcd, behind the API server

A request for a user certificate looks like this:

apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: jane
spec:
  request: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0t...   # base64 of jane.csr, one line
  signerName: kubernetes.io/kube-apiserver-client
  expirationSeconds: 86400                                  # one day; optional
  usages:
    - client auth
FieldMeaning
metadata.nameA name for the request. It is only a label for the object; it does not become the user name
spec.requestThe CSR file, base64-encoded on a single line. The user name and groups come from here: CN is the user, each O is a group
spec.signerNameWhich signer should issue the certificate. Required, and it decides the rules for everything else
spec.usagesWhat the certificate may be used for. A user certificate needs client auth
spec.expirationSecondsThe lifetime you ask for, at least 600 (ten minutes). The signer may give less, never more than its own maximum
spec.username, spec.groups, spec.uidFilled in by the API server with the identity of whoever created the object. You cannot set them, which is what makes the REQUESTOR column trustworthy
status.conditionsApproved, Denied or Failed. Empty means Pending
status.certificateThe signed certificate, base64-encoded. Present only after approval and signing

How it works

Three roles

  1. The requester creates the key pair and the CSR file locally, then creates the CSR object. The private key never leaves their machine. Kubernetes never sees it and cannot give it back to you if you lose it.
  2. The approver decides whether the request is legitimate. Approval only adds a condition to the object; it signs nothing. An approver can be a person running kubectl certificate approve or a controller.
  3. The signer watches for approved requests with its signerName, creates the certificate and writes it to status.certificate.

Splitting approval from signing is deliberate. The approver needs judgement but no access to key material; the signer needs the CA key but makes no decisions.

Signers

The signerName is how a request says what kind of certificate it wants. Each signer has its own rules about subjects, usages and lifetime, and its own answer to "who approves?".

Three built-in signers, two kinds of approvalwaitscheckedwaitsApprovedautoApprovedUser client certkube-apiserver-clientKubelet client cert...-client-kubeletKubelet serving certkubelet-servingYoukubectl certificatecsrapprovingapproves by itselfYou or an add-onnever automaticcsrsigningsigns with cluster CA
Three built-in signers, two kinds of approval. The signerName on a request says what kind of certificate is wanted. Only the kubelet's client certificate is approved automatically; the other two wait for a person or an add-on.

Parts:

  • User client cert (kube-apiserver-client)
  • Kubelet client cert (...-client-kubelet)
  • Kubelet serving cert (kubelet-serving)
  • You (kubectl certificate)
  • csrapproving (approves by itself)
  • You or an add-on (never automatic)
  • csrsigning (signs with cluster CA)

Connections:

  • User client cert to You: waits
  • Kubelet client cert to csrapproving: checked
  • Kubelet serving cert to You or an add-on: waits
  • You to csrsigning: Approved
  • csrapproving to csrsigning: auto
  • You or an add-on to csrsigning: Approved
signerNameIssuesApproved automatically?Required shape
kubernetes.io/kube-apiserver-clientClient certificates the API server accepts: users and other clientsNeverusages must include client auth, and nothing beyond digital signature, key encipherment, client auth
kubernetes.io/kube-apiserver-client-kubeletThe client certificate a kubelet uses to talk to the API serverYes, by the csrapproving controller, when the request has the right shapeSubject CN=system:node:<node>, O=system:nodes
kubernetes.io/kubelet-servingThe serving certificate for the kubelet's own HTTPS endpoint (port 10250)Never by kube-controller-managerUsages include server auth; the names must be the node's own DNS names and IPs
example.com/anythingWhatever a custom signer you install decidesUp to that signerUp to that signer

There is also kubernetes.io/legacy-unknown, a leftover from the old beta API. The stable certificates.k8s.io/v1 API does not accept it, so you will not use it.

Who actually signs: kube-controller-manager

The built-in signers are not a separate service. They are controllers inside kube-controller-manager:

ControllerJob
csrapprovingApproves kubelet client certificate requests that pass its checks
csrsigningSigns approved requests for the built-in signers
csrcleanerDeletes old CSR objects

csrsigning needs a CA to sign with, and it gets one from two flags:

grep cluster-signing /etc/kubernetes/manifests/kube-controller-manager.yaml
    - --cluster-signing-cert-file=/etc/kubernetes/pki/ca.crt
    - --cluster-signing-key-file=/etc/kubernetes/pki/ca.key
Where the CA key is used, and where it is trustedmountedsignsused byTLStrustsca.crt + ca.key/etc/kubernetes/pkiController manager--cluster-signing-*jane.crtCN=janeca.crtpublic half onlyAPI server--client-ca-filekubectl as janepresents jane.crt
Where the CA key is used, and where it is trusted. kube-controller-manager signs with the CA pair it is given in its flags. The API server accepts the result because it trusts the same CA certificate for client logins.

Parts:

  • ca.crt + ca.key (/etc/kubernetes/pki)
  • Controller manager (--cluster-signing-*)
  • jane.crt (CN=jane)
  • ca.crt (public half only)
  • API server (--client-ca-file)
  • kubectl as jane (presents jane.crt)

Connections:

  • ca.crt + ca.key to Controller manager: mounted
  • Controller manager to jane.crt: signs
  • jane.crt to kubectl as jane: used by
  • kubectl as jane to API server: TLS
  • ca.crt to API server: trusts

A certificate signed this way works as a login because the API server trusts the same CA for client certificates (--client-ca-file=/etc/kubernetes/pki/ca.crt). This is the link to remember when something breaks: if a request is Approved but never becomes Approved,Issued, the approval worked and the signing did not. Check that kube-controller-manager is running and that both flags point at files that exist inside its Pod.

Lifetime

The certificate lives for the shorter of two values: spec.expirationSeconds on the request and --cluster-signing-duration on kube-controller-manager, which defaults to one year (8760h). Asking for ten years gets you one year. Asking for less than 600 seconds is rejected when you create the object.

The life of a CSR object

kubectl get csr shows the state in the CONDITION column:

CONDITIONMeaning
PendingNobody has decided yet
ApprovedApproved, but not signed yet. For more than a few seconds, this is a signing problem
Approved,IssuedSigned. status.certificate holds the certificate
DeniedRefused. No certificate will be issued
Approved,FailedApproved, but the signer could not issue it, for example because the usages do not fit the signer

Two rules about these conditions surprise people:

  • A decision is final. Approved and Denied exclude each other and cannot be removed. You cannot deny a request you approved, or approve one you denied. To try again, delete the object and create a new one.
  • CSR objects are temporary. The csrcleaner controller deletes approved, denied and failed requests after about an hour, and pending ones after 24 hours. The issued certificate keeps working after the object is gone, but you can no longer fetch it from the API. Extract it straight after approval.

What approval does not give

There is one more limit. Kubernetes cannot revoke a certificate. There is no revocation list. A certificate that has been issued stays valid until it expires, even if you delete the CSR object. To lock a user out early, remove their RBAC bindings, and to make leaks less harmful, issue short-lived certificates with expirationSeconds.

Under the hood · Who may create, approve and sign

The three roles map to three sets of permissions in the certificates.k8s.io group:

ToYou need
Create a requestcreate on certificatesigningrequests
Approve or denyget, list, watch on certificatesigningrequests; update on certificatesigningrequests/approval; and approve on the resource signers with the signer's name as resource name
Signupdate on certificatesigningrequests/status; and sign on signers for that signer name

The approve and sign verbs on signers are checked by two admission plugins, CertificateApproval and CertificateSigning. They let you say "this team may approve requests for example.com/* but not for kubernetes.io/kube-apiserver-client".

A third plugin, CertificateSubjectRestriction, protects you from the most dangerous request: it rejects any CSR for the kube-apiserver-client signer whose subject asks for the group system:masters. Other powerful groups are not blocked, so reading the subject before you approve is still your job.

Under the hood · Why the kubelet's serving certificate is not auto-approved

A client certificate request from a kubelet is easy to check: the subject must be system:node:<name> in the group system:nodes, and nothing else. A serving certificate contains DNS names and IP addresses, and kube-controller-manager has no reliable way to know which addresses really belong to a node. Approving a wrong one would let a node impersonate another machine. So when serverTLSBootstrap: true is set in the kubelet configuration, each kubelet creates a kubernetes.io/kubelet-serving request that waits for you, or for an add-on that knows your infrastructure, to approve it. Until then the kubelet serves a self-signed certificate.

By hand or through the API?

Signing with opensslCertificates API
Who touches ca.keyThe person signing, on the control plane nodeOnly kube-controller-manager
Access neededRoot on a control plane nodeAn API permission (approve for a signer)
Record of who asked and who approvedNoneThe CSR object, events and the audit log
AutomationScripts you writeBuilt in for kubelets; controllers can approve
LifetimeWhatever -days saysCapped by --cluster-signing-duration
Works without a running control planeYesNo

The last row matters. The control plane's own certificates (API server, etcd, front proxy) are not issued through this API. kubeadm creates them from the CA files directly and renews them with kubeadm certs renew, because they must exist before any API server can answer a request.

Using it

Example · Give a new user a client certificate

The task: create a certificate for the user jane, a member of the group developers.

1. Create a key and a CSR file. CN becomes the user name and O the group:

openssl genrsa -out jane.key 2048
openssl req -new -key jane.key -subj "/CN=jane/O=developers" -out jane.csr

2. Encode the CSR file on one line and create the object:

cat jane.csr | base64 -w 0
# jane-csr.yaml
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: jane
spec:
  request: <paste the base64 output here>
  signerName: kubernetes.io/kube-apiserver-client
  expirationSeconds: 86400
  usages:
    - client auth
kubectl apply -f jane-csr.yaml
kubectl get csr
NAME   AGE   SIGNERNAME                            REQUESTOR          REQUESTEDDURATION   CONDITION
jane   6s    kubernetes.io/kube-apiserver-client   kubernetes-admin   24h                 Pending

3. Approve it and collect the certificate:

kubectl certificate approve jane
kubectl get csr jane                         # CONDITION: Approved,Issued
kubectl get csr jane -o jsonpath='{.status.certificate}' | base64 -d > jane.crt
openssl x509 -in jane.crt -noout -subject -enddate
subject=O=developers, CN=jane
notAfter=Dec  1 11:52:07 2026 GMT

jane.crt and jane.key together are Jane's login. The KubeConfig lesson shows how to put them in a kubeconfig; the short version is kubectl config set-credentials jane --client-certificate=jane.crt --client-key=jane.key.

Example · Do it without a file: one command

When the CSR file already exists, a heredoc saves the editor round trip. The shell fills in the base64 text:

cat <<EOF | kubectl apply -f -
apiVersion: certificates.k8s.io/v1
kind: CertificateSigningRequest
metadata:
  name: jane
spec:
  request: $(base64 -w 0 < jane.csr)
  signerName: kubernetes.io/kube-apiserver-client
  usages:
    - client auth
EOF

Without expirationSeconds the certificate gets the signer's maximum, one year by default.

Example · Review before you approve, and deny what looks wrong

A request called new-dev is pending. Its name tells you nothing, so look inside it:

kubectl describe csr new-dev
Name:               new-dev
Requesting User:    bob
Signer:             kubernetes.io/kube-apiserver-client
Requested Duration: 24h
Status:             Pending
Subject:
  Common Name:    bob
  Organization:   cluster-admins

kubectl describe decodes the subject for you. Bob is asking for membership of a group that, in this cluster, is bound to cluster-admin. Refuse it:

kubectl certificate deny new-dev
kubectl get csr new-dev                      # CONDITION: Denied
kubectl delete csr new-dev                   # tidy up; a denied request cannot be approved later

To read the full request, including usages and extensions, decode it yourself:

kubectl get csr new-dev -o jsonpath='{.spec.request}' | base64 -d | openssl req -noout -text

Example · Finish the job: let jane do something

The certificate alone gives no access. Bind a Role, then test without switching user:

kubectl create role pod-reader --verb=get,list,watch --resource=pods -n dev
kubectl create rolebinding jane-pod-reader --role=pod-reader --user=jane -n dev
kubectl auth can-i list pods -n dev --as jane          # yes
kubectl auth can-i delete pods -n dev --as jane        # no

To prove the certificate itself works, use it directly:

kubectl get pods -n dev --client-certificate=jane.crt --client-key=jane.key \
  --server=https://controlplane:6443 --certificate-authority=/etc/kubernetes/pki/ca.crt

Example · Troubleshoot a request that is approved but never issued

NAME   AGE   SIGNERNAME                            REQUESTOR          REQUESTEDDURATION   CONDITION
jane   4m    kubernetes.io/kube-apiserver-client   kubernetes-admin   24h                 Approved

Approved without Issued for minutes means the signer is not doing its work. The signer is kube-controller-manager:

kubectl -n kube-system get pods -l component=kube-controller-manager
kubectl -n kube-system logs kube-controller-manager-controlplane | grep -i -E "sign|certificate"
grep cluster-signing /etc/kubernetes/manifests/kube-controller-manager.yaml
ls -l /etc/kubernetes/pki/ca.crt /etc/kubernetes/pki/ca.key

Typical causes: the controller manager Pod is not running, a --cluster-signing-* flag points at a path that does not exist, or the pki folder is not mounted where the flag says. Fix the static Pod manifest, wait for the kubelet to restart the Pod, and the pending signature completes by itself. You do not need to approve again.

Tricks

Common mistakes

  • Encoding the wrong file. spec.request takes the .csr file. The private key must never be pasted into a manifest, and a .crt is rejected.
  • Base64 with line breaks, or encoding twice. The value must be one line that starts with LS0tLS1CRUdJTiBDRVJU.
  • Leaving out signerName or usages. Both are required in certificates.k8s.io/v1. A user certificate needs kubernetes.io/kube-apiserver-client and client auth.
  • Asking for server auth from the client signer. The usages do not fit the signer, so no certificate is issued.
  • Using the old API version. certificates.k8s.io/v1beta1 is gone. Old blog posts and notes still show it.
  • Expecting the object name to be the user name. The user comes from CN in the CSR file. A request named jane whose subject says CN=admin produces a certificate for admin.
  • Forgetting RBAC. The user authenticates and then gets Forbidden everywhere.
  • Waiting too long to fetch the certificate. The object is deleted about an hour after approval.
  • Trying to undo a decision. Approve and deny are final. Delete the request and create it again.
  • Looking for a namespace. CSRs are cluster-scoped; -n has no effect.

Recap

  • A CertificateSigningRequest carries a CSR file, base64-encoded in spec.request, to the cluster, so the CA key never has to leave the control plane.
  • signerName and usages say what kind of certificate is wanted. For a user: kubernetes.io/kube-apiserver-client with client auth.
  • kubectl certificate approve <name> or deny <name> decides. The decision is final.
  • kube-controller-manager signs approved requests with the CA from --cluster-signing-cert-file and --cluster-signing-key-file; the certificate lands in status.certificate.
  • The certificate is identity only. Add RBAC, keep lifetimes short, and remember that certificates cannot be revoked.

Official docs

Quiz: check what you learned

5 questions on this lesson · about 3 min · instant feedback. Missed questions come back in your review queue.

Sign in to take the quiz and keep your score.

Practise: try it on a real cluster

2 hands-on labs for this lesson. You get goals, not steps: any solution that reaches them passes.

  • Get a client certificate issued by the cluster without ever touching the CA key, and decide which waiting requests deserve a signature.

    Build · Level 2 · standard · target 20 min

  • Section capstone. Prepare a namespace for an audit: a short-lived login for the auditor, read-only access for her group, an identity of its own for one app, a hardened container, and network policies that close the namespace.

    Build · Level 3 · challenge · target 40 min

Discussion

Learners ask and answer questions here. Sign in to read and join the discussion.