LAB05a: Create a Kubernetes User

complete, production-grade LAB for Option 1: Creating a Kubernetes User Using CSR API — without accessing the cluster CA private key.

This method is used in real enterprises because it is safer and managed fully through Kubernetes.

LAB: Create a Kubernetes User via CertificateSigningRequest (CSR API)

No CA key access required. Kube-API signs the certificate.

Lab Goal

You will:

  1. Create a new user: john

  2. Generate CSR + private key locally

  3. Create a Kubernetes CSR manifest

  4. Approve the CSR in the cluster

  5. Extract the client certificate

  6. Build a kubeconfig for john

  7. Configure RBAC

  8. Test the user

Prerequisites

Run commands on your local machine or control-plane, must have:

  • kubectl access (admin)

  • OpenSSL installed

STEP 1 — Generate Key + CSR Locally

Explanation:

  • CN=john → username inside Kubernetes

  • O=dev-team → group name inside Kubernetes (you can set any group, RBAC will use this)

STEP 2 — Base64 Encode the CSR

STEP 3 — Create the Kubernetes CSR Manifest

Create john-csr.yaml:

Replace <BASE64_CSR_HERE>:

STEP 4 — Apply the CSR to Kubernetes

Check CSR status:

STEP 5 — Approve the CSR

As cluster admin:

Verify:

You should now see:

STEP 6 — Extract the Signed Certificate

Now you have:

  • john.key (private key)

  • john.crt (signed certificate)

STEP 7 — Build a Custom Kubeconfig for John

1. Get cluster name:

2. Extract API server endpoint:

3. Extract CA certificate:

Build kubeconfig:

Set cluster:

Set user:

Set context:

Switch context:

STEP 8 — Test User Authentication (No RBAC Yet)

Expected:

This confirms: ✔ Authentication working ✘ No authorization yet

STEP 9 — Add RBAC Permissions

OPTION A — Namespace-limited read access:

OPTION B — Cluster-wide read access:

OPTION C — Full admin:

STEP 10 — Test RBAC

Check who you are:

Output:

Check allowed actions:

Try listing pods:

LAB COMPLETED — You Successfully Created a Kubernetes User via CSR API

You now have:

This is the enterprise-standard & secure way to:

  • Create developer/operator credentials

  • Issue short-lived certificates

  • Avoid exposing Kubernetes CA private key

  • Automate cert management

Last updated