Action is forbidden by RBAC policy
Production Risk
Correctly configured RBAC is critical for security. However, overly restrictive rules can prevent applications from functioning correctly if they cannot access required resources.
A user or service account is attempting to perform an action (like reading secrets or listing pods) that it is not authorized to do. This is a direct rejection from the Kubernetes API server based on Role-Based Access Control (RBAC) rules.
- 1The user or service account does not have a Role or ClusterRole attached that grants the necessary permission
- 2The RoleBinding or ClusterRoleBinding that links the user to the role is missing or incorrect
- 3The action is being attempted in the wrong namespace where the permissions do not apply
A `kubectl` command or an in-cluster application making an API call fails with a 'Forbidden' error message.
kubectl get secrets
expected output
Error from server (Forbidden): secrets is forbidden: User "system:serviceaccount:default:default" cannot list resource "secrets" in API group "" in the namespace "default"
Fix 1
Check permissions with 'can-i'
WHEN To quickly test if a user or service account has a specific permission
kubectl auth can-i list secrets --as=system:serviceaccount:default:default
Why this works
This `auth` subcommand impersonates the specified user/service account and tells you if the action is allowed by the current RBAC policies, returning 'yes' or 'no'.
Fix 2
Create a Role and RoleBinding
WHEN Permissions need to be granted within a specific namespace
kubectl apply -f my-role.yaml && kubectl apply -f my-rolebinding.yaml
Why this works
Applying a Role manifest defines a set of permissions, and a RoleBinding manifest grants those permissions to a specific user, group, or service account within that namespace.
✕ Grant the 'cluster-admin' role to the service account
This gives the service account unrestricted superuser access to the entire cluster, which is a major security risk. You should always grant the least privilege necessary.
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev