LAB02c: Create a New Kubernetes User Using Certificate Authentication

Goal

You will create:

  • A new Linux-user/identity name: john

  • A client certificate for john

  • A kubeconfig file for john

  • RBAC permissions (Role/ClusterRole/RoleBinding/ClusterRoleBinding)

  • Test access as john

This lab works on kubeadm clusters.

PREREQUISITES

Run the following commands on the control-plane node:

Important files needed:

/etc/kubernetes/pki/ca.crt
/etc/kubernetes/pki/ca.key

These are used to sign the new user's certificate.

STEP 1 — Create a private key for the new user


STEP 2 — Create a CSR (Certificate Signing Request)

Meaning:

  • CN=john → Kubernetes username

  • O=dev-team → Group name (RBAC will use this)

You can also put: O=system:masters → full admin But we avoid that for safety.

STEP 3 — Sign the CSR with Kubernetes CA

Now you have:

STEP 4 — Create a new kubeconfig for the new user

We extract the cluster details from the admin kubeconfig.

1. Get the cluster name

Example: kubernetes

2. Get the server endpoint

3. Get the CA certificate

STEP 5 — Build a kubeconfig file manually

You now have a working john.kubeconfig.

STEP 6 — Test the kubeconfig without RBAC

Expected output:

This means authentication succeeded, but no authorization yet.

Perfect — now we'll add RBAC.

STEP 7 — Grant RBAC Permissions

Choose the level you want:

OPTION A — Namespace limited access (e.g., default namespace)

Create Role:

Bind it:

OPTION B — Cluster-wide read-only

STEP 8 — Test Access as john

Now run:

Depending on RBAC, you will either:

  • get pods

  • get pods only in namespace

  • get full cluster admin access

STEP 9 — Validate Identity (VERY IMPORTANT)

Expected:

Or if admin:

STEP 10 — Inspect the certificate details

Look for:

FINAL OUTPUTS OF THIS LAB

You now have:

Plus RBAC bindings in cluster.

Summary

You learned how to:

✔ Generate user certificate ✔ Sign it with Kubernetes CA ✔ Build a full kubeconfig manually ✔ Apply RBAC roles ✔ Validate authentication ✔ Verify certificate identity

This is the industry-standard way to add developers, DevOps engineers, and automation clients to Kubernetes.

Last updated