Founding prices until 15 December: 30% off Pro, locked for life. See pricing

$ … Error from server (Forbidden): pods is forbidden: User cannot list resource

Kubernetes 'Forbidden: cannot list resource': fixing RBAC

The user or ServiceAccount is authenticated but RBAC doesn't allow the action.

Kubernetes

What it means

Kubernetes knows who you are, but no Role or ClusterRole bound to you grants that verb on that resource in that namespace. The error names the user, verb, resource and namespace: everything you need to write the rule.

Causes and fixes

Most likely first. Run the check, and if it matches, apply the fix.

1. No RoleBinding for that user or ServiceAccount in the namespace

Check:

kubectl auth can-i list pods -n <ns> --as=<user>
kubectl get rolebindings -n <ns> -o wide

Fix: Create a Role with the verbs it needs and a RoleBinding to the subject.

2. The binding exists but in another namespace, or names the wrong subject (ServiceAccount namespace, user name)

Check:

kubectl describe rolebinding <name> -n <ns>

Fix: Bind in the namespace where the access is needed, with the exact subject.

3. The Role misses the resource, verb or API group (deployments are in apps)

Check:

kubectl describe role <role> -n <ns>

Fix: Add the missing verb or apiGroup; check with kubectl auth can-i.

Fix it yourself

A live machine in your browser with this problem already on it. The grader checks the result.

Open the lab

No account needed for your first tries.

Related errors