Kubernetes MCP Security: RBAC, ServiceAccounts, and Least Privilege

Intermediate

Go deep on the identity behind a read-only Kubernetes MCP server. Prove least privilege across two independent dimensions — WHAT the agent may do (verbs and subresources) and WHERE it may do it (namespace scope) — close the exec/attach/port-forward escalation paths, and harden the ServiceAccount token and kubeconfig you built in Lesson 1.

Learning Objectives

1
Read an identity's entire effective permission set with kubectl auth can-i --list
2
Prove least privilege across two independent dimensions: WHAT (verbs/subresources) and WHERE (namespace scope)
3
Close the exec, attach, and port-forward escalation paths that turn 'read' access into command execution
4
Contrast a purpose-built Role with the broad built-in view ClusterRole
5
Harden the ServiceAccount token lifetime and replace insecure TLS in the lab kubeconfig with a verified cluster CA
Step 1

Confirm Lesson 1's lab is still in place

This lesson inspects and hardens the exact identity you built in Lesson 1 — it does not create a new one. Confirm the ServiceAccount, Role, RoleBinding, and demo workloads still exist before going further.

Commands to Run

kubectl get serviceaccount mcp-readonly -n demo
kubectl get role,rolebinding mcp-readonly -n demo
kubectl get pods -n demo

What This Does

Everything below reasons about the mcp-readonly ServiceAccount and its namespace-scoped Role from Lesson 1.

The demo namespace should still hold the web pods and the crashing crasher pod.

If any of these are missing, the RBAC checks in this lesson have nothing to bind to.

Expected Outcome

The mcp-readonly ServiceAccount, Role, and RoleBinding all print, and the demo namespace lists the web-... pods plus crasher.

Pro Tips

  • 1
    This lesson reuses Lesson 1's canonical lab on purpose — same namespace, same names. Do not create a second ServiceAccount or a duplicate broken pod.

Common Mistakes to Avoid

  • ⚠️Missing resources means you skipped or tore down Lesson 1. Re-run Lesson 1's steps 2 and 3 first, then come back.
Was this step helpful?

All Steps (0 / 9 completed)