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
Official competencies this lesson covers
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.
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":
| Name | What it is | Where 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 key | On the requester's machine |
| The CSR object | A Kubernetes resource that carries that file in spec.request and tracks approval and the result | In 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
| Field | Meaning |
|---|---|
metadata.name | A name for the request. It is only a label for the object; it does not become the user name |
spec.request | The 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.signerName | Which signer should issue the certificate. Required, and it decides the rules for everything else |
spec.usages | What the certificate may be used for. A user certificate needs client auth |
spec.expirationSeconds | The 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.uid | Filled 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.conditions | Approved, Denied or Failed. Empty means Pending |
status.certificate | The signed certificate, base64-encoded. Present only after approval and signing |
How it works
Three roles
- 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.
- 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 approveor a controller. - The signer watches for approved requests with its
signerName, creates the certificate and writes it tostatus.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?".
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
signerName | Issues | Approved automatically? | Required shape |
|---|---|---|---|
kubernetes.io/kube-apiserver-client | Client certificates the API server accepts: users and other clients | Never | usages must include client auth, and nothing beyond digital signature, key encipherment, client auth |
kubernetes.io/kube-apiserver-client-kubelet | The client certificate a kubelet uses to talk to the API server | Yes, by the csrapproving controller, when the request has the right shape | Subject CN=system:node:<node>, O=system:nodes |
kubernetes.io/kubelet-serving | The serving certificate for the kubelet's own HTTPS endpoint (port 10250) | Never by kube-controller-manager | Usages include server auth; the names must be the node's own DNS names and IPs |
example.com/anything | Whatever a custom signer you install decides | Up to that signer | Up 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:
| Controller | Job |
|---|---|
csrapproving | Approves kubelet client certificate requests that pass its checks |
csrsigning | Signs approved requests for the built-in signers |
csrcleaner | Deletes 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
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:
| CONDITION | Meaning |
|---|---|
Pending | Nobody has decided yet |
Approved | Approved, but not signed yet. For more than a few seconds, this is a signing problem |
Approved,Issued | Signed. status.certificate holds the certificate |
Denied | Refused. No certificate will be issued |
Approved,Failed | Approved, 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.
ApprovedandDeniedexclude 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
csrcleanercontroller 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:
| To | You need |
|---|---|
| Create a request | create on certificatesigningrequests |
| Approve or deny | get, list, watch on certificatesigningrequests; update on certificatesigningrequests/approval; and approve on the resource signers with the signer's name as resource name |
| Sign | update 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 openssl | Certificates API | |
|---|---|---|
Who touches ca.key | The person signing, on the control plane node | Only kube-controller-manager |
| Access needed | Root on a control plane node | An API permission (approve for a signer) |
| Record of who asked and who approved | None | The CSR object, events and the audit log |
| Automation | Scripts you write | Built in for kubelets; controllers can approve |
| Lifetime | Whatever -days says | Capped by --cluster-signing-duration |
| Works without a running control plane | Yes | No |
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.requesttakes the.csrfile. The private key must never be pasted into a manifest, and a.crtis rejected. - Base64 with line breaks, or encoding twice. The value must be one line that starts with
LS0tLS1CRUdJTiBDRVJU. - Leaving out
signerNameorusages. Both are required incertificates.k8s.io/v1. A user certificate needskubernetes.io/kube-apiserver-clientandclient auth. - Asking for
server authfrom the client signer. The usages do not fit the signer, so no certificate is issued. - Using the old API version.
certificates.k8s.io/v1beta1is gone. Old blog posts and notes still show it. - Expecting the object name to be the user name. The user comes from
CNin the CSR file. A request namedjanewhose subject saysCN=adminproduces a certificate foradmin. - Forgetting RBAC. The user authenticates and then gets
Forbiddeneverywhere. - 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;
-nhas 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. signerNameandusagessay what kind of certificate is wanted. For a user:kubernetes.io/kube-apiserver-clientwithclient auth.kubectl certificate approve <name>ordeny <name>decides. The decision is final.- kube-controller-manager signs approved requests with the CA from
--cluster-signing-cert-fileand--cluster-signing-key-file; the certificate lands instatus.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.