RBAC for Secrets
What you'll learn: How to use Kubernetes Role-Based Access Control (RBAC) to restrict who can view, create, or modify Secrets.
Why RBAC Matters for Secrets
Secrets contain your most sensitive data—database passwords, API keys, TLS certificates. By default, anyone with access to the Kubernetes API could potentially read all Secrets in a namespace. RBAC lets you create fine-grained permissions so only authorized users and service accounts can access specific Secrets.
How RBAC Controls Secret Access
Think of RBAC like building security: you don't give everyone keys to every room. Instead, you assign specific access cards (Roles) to specific people (ServiceAccounts or Users) for specific rooms (Secrets in namespaces).
RBAC rules define:
- Who can access (Subject: users, groups, service accounts)
- What they can do (Verbs:
get,list,create,update,delete) - Which resources (Resources:
secrets)
For example, you might allow a CI/CD service account to only get specific Secrets, while denying list access (so it can't see what other Secrets exist). Or you might give developers read-only access to Secrets in the dev namespace but no access in prod.
Common RBAC Patterns
You can restrict Secret access by:
- Namespace: Different permissions for
dev,staging, andproduction - Verb: Allow reading (
get) but not modifying (update,delete) - ResourceName: Grant access to only specific Secret names
This prevents accidental exposure and limits blast radius if credentials are compromised.
Key Takeaway: RBAC for Secrets enforces the principle of least privilege—granting only the minimum necessary access to sensitive data, protecting your secrets from unauthorized viewing or modification.