How to fix User cannot get resource in Kubernetes
This RBAC error occurs when a user lacks permission to access a resource. Fix it by creating a Role or ClusterRole with required permissions and binding it to the user with RoleBinding or ClusterRoleBinding.
Quick fix
Fixes User cannot get resource
# Check current user
kubectl auth whoami
# Test specific permission
kubectl auth can-i get pods
kubectl auth can-i get pods -n production
# Test as another user
kubectl auth can-i get pods --as=john.developer
# List all permissions for a user
kubectl auth can-i --list --as=john.developer- Check current user and test permissions
- Inspect existing roles and bindings
- Create a Role with required permissions
- Create RoleBinding to grant permissions
# Check current userkubectl auth whoami# Test specific permissionkubectl auth can-i get podskubectl auth can-i get pods -n production# Test as another userkubectl auth can-i get pods --as=john.developer# List all permissions for a userkubectl auth can-i --list --as=john.developerUser cannot get resource
What this error means
The "User cannot get resource" error (typically shown as "Error from server (Forbidden): {resource} is forbidden: User cannot {verb} resource") indicates that Kubernetes RBAC (Role-Based Access Control) is blocking the request. The authenticated user doesn't have permission to perform the requested action on the specified resource. Kubernetes RBAC uses four main objects: Roles (namespace-scoped permissions), ClusterRoles (cluster-wide permissions), RoleBindings (grant Role to users in a namespace), and ClusterRoleBindings (grant ClusterRole cluster-wide). A user must have an appropriate binding to a role that includes the required verb and resource. This error commonly occurs when users are added to a cluster without proper role assignments, when accessing resources in namespaces where they lack bindings, or when the role doesn't include all necessary verbs (get, list, watch, create, update, delete).
Typical symptoms
- kubectl commands return "Error from server (Forbidden)"
- User can access some resources but not others
- Works in one namespace but not another
- Works with --as=system:admin but not with actual user
- Helm deployments fail with permission errors
Common causes
- User has no RoleBinding or ClusterRoleBinding
- Role doesn't include required verb (get, list, watch, etc.)
- Incorrect apiGroup in Role definition
- RoleBinding in wrong namespace (namespace-scoped access only)
- Using Role when ClusterRole is needed for cluster-wide access
How to fix "User cannot get resource"
Verify who you are and what permissions you have:
# Check current user
kubectl auth whoami
# Test specific permission
kubectl auth can-i get pods
kubectl auth can-i get pods -n production
# Test as another user
kubectl auth can-i get pods --as=john.developer
# List all permissions for a user
kubectl auth can-i --list --as=john.developerResponse is "yes" or "no".
Find what roles and bindings exist:
# List roles in namespace
kubectl get roles -n default
# Describe a role
kubectl describe role pod-reader -n default
# List role bindings
kubectl get rolebindings -n default
# Find bindings for a specific user
kubectl get rolebindings,clusterrolebindings --all-namespaces -o json | \
jq '.items[] | select(.subjects[]?.name=="john.developer")'Create a namespace-scoped Role:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: pod-reader
namespace: default
rules:
- apiGroups: [""] # Core API (pods, services, secrets)
resources: ["pods"]
verbs: ["get", "list", "watch"]
- apiGroups: ["apps"] # Apps API (deployments, statefulsets)
resources: ["deployments"]
verbs: ["get", "list"]Common apiGroups:
- "" (empty): pods, services, configmaps, secrets
- "apps": deployments, statefulsets, daemonsets
- "batch": jobs, cronjobs
- "networking.k8s.io": networkpolicies
Bind the role to the user:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: pod-reader-binding
namespace: default
subjects:
- kind: User
name: john.developer
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: Role
name: pod-reader
apiGroup: rbac.authorization.k8s.ioApply and verify:
kubectl apply -f rolebinding.yaml
kubectl auth can-i get pods --as=john.developer -n defaultFor access across all namespaces:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pod-reader-global
rules:
- apiGroups: [""]
resources: ["pods", "namespaces"]
verbs: ["get", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: pod-reader-global-binding
subjects:
- kind: User
name: john.developer
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: pod-reader-global
apiGroup: rbac.authorization.k8s.ioConfirm permissions are working:
# Test permission
kubectl auth can-i get pods --as=john.developer -n default
# Try the actual command
kubectl get pods -n default
# Test multiple verbs
kubectl auth can-i list pods --as=john.developer
kubectl auth can-i create pods --as=john.developer
kubectl auth can-i delete pods --as=john.developerAll required verbs should return "yes".
Advanced notes
Role Aggregation (Kubernetes 1.9+):
Compose permissions from multiple roles using labels:
aggregationRule:
clusterRoleSelectors:
- matchLabels:
rbac.authorization.k8s.io/aggregate-to-viewer: "true"Impersonation for testing:
kubectl auth can-i get pods --as=jane.developer
kubectl get pods --as=system:serviceaccount:default:webappPrivilege Escalation Prevention: You can only create roles/bindings with permissions you already possess.
Common Role Templates:
- Pod reader: verbs: ["get", "list"] on resources: ["pods"]
- Deployment manager: verbs: ["get", "list", "create", "update", "patch"] on resources: ["deployments"]
- Read-only all: verbs: ["get", "list", "watch"] on resources: ["*"]
Frequently asked questions
- What does "User cannot get resource" mean?
- The "User cannot get resource" error (typically shown as "Error from server (Forbidden): {resource} is forbidden: User cannot {verb} resource") indicates that Kubernetes RBAC (Role-Based Access Control) is blocking the request. The authenticated user doesn't have permission to perform the requested action on the specified resource. Kubernetes RBAC uses four main objects: Roles (namespace-scoped permissions), ClusterRoles (cluster-wide permissions), RoleBindings (grant Role to users in a namespace), and ClusterRoleBindings (grant ClusterRole cluster-wide).
- How do I fix "User cannot get resource"?
- This RBAC error occurs when a user lacks permission to access a resource. Fix it by creating a Role or ClusterRole with required permissions and binding it to the user with RoleBinding or ClusterRoleBinding.
- What causes "User cannot get resource"?
- User has no RoleBinding or ClusterRoleBinding Role doesn't include required verb (get, list, watch, etc.) Incorrect apiGroup in Role definition
- Is the "User cannot get resource" error serious?
- It is a medium-severity error โ more of a blocker than a risk. The steps above resolve it.
Official resources & further reading
- ๐Kubernetes Official Documentation
- ๐Kubernetes Docs: Using RBAC Authorization(Official Docs)
- ๐Azure: Troubleshooting Forbidden error in AKS(Official Docs)
- ๐ฌStack Overflow: Kubernetes RBAC access issues(Stack Overflow)