/root. The steps below show how to embed the CSR into a Kubernetes CertificateSigningRequest resource, approve it so the cluster issues a certificate, and how to inspect and handle unexpected CSRs.
Prerequisites
- Access to a control-plane node or a machine with
kubectlconfigured to talk to the cluster control plane. - The CSR file (PEM) and private key available locally (in this example
/root/akshay.csrand/root/akshay.key).
Inspect the working directory
Confirm the CSR and private key are present:When embedding a PEM CSR into the
spec.request field of a CertificateSigningRequest manifest, the CSR must be base64-encoded and written as a single continuous line. On Linux, use base64 -w 0 to produce single-line output.Step-by-step: create and approve a CSR
- Base64-encode the CSR as a single line and save it to a file:
- Create a YAML manifest for the Kubernetes
CertificateSigningRequest. Replace therequest:value with the single-line base64 string you generated.
akshay.yaml:
- Apply the
CertificateSigningRequestmanifest:
- Check the CSR list. Newly created CSRs appear in the Pending state until approved:
- Approve the CSR so the cluster controller will issue a certificate:
- Verify the CSR status is now Approved and Issued:
- Extract the issued certificate (base64-decoded) from the CSR object and write it to a PEM file:
akshay.crt is the PEM certificate issued by the cluster. Pair it with the private key (akshay.key) to use as a client certificate.
Inspecting and handling suspicious CSRs
Occasionally you’ll see unexpected CSRs (for example, a CSR requesting cluster-admin groups). Inspect such CSRs closely before approving. Example: a CSR namedagent-smith requests privileged groups.
- View the CSR YAML to inspect
spec.groups,spec.usages, andusername:
- If you did not expect this request and it requests privileged groups (like
system:masters), deny it:
- Optionally delete the denied CSR from the cluster:
Final verification
Check all remaining CSRs and their conditions:Common CSR commands
Notes and best practices
- Always inspect
spec.groups,spec.usages, andusernamebefore approving a CSR. Approving a CSR grants the requester the privileges encoded in the certificate. - Use the appropriate
signerNamefor the certificate purpose:kubernetes.io/kube-apiserver-clientfor kube-apiserver clients (client auth).- Other built-in signers exist for kubelet serving certificates (e.g.,
kubernetes.io/kubelet-serving) or custom signers for external issuers.
- Base64-encode the CSR as a single-line string before embedding it into
spec.request. - Keep private keys secure at all times. Never commit private keys into source control or store them in cluster manifests.
Do not approve CSRs that request privileged groups (for example
system:masters) unless you can verify the identity and intent of the requester. Approving such CSRs can grant cluster-admin access.