I create a service account, a role, and a role binding that attaches the role to the SA.
I am trying to get the service account to list nodes but I can't, although the auth call tells me I can (for deployments it's even worst, the role do allow it, but I can't do anything):
#pods
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test auth can-i get pods
yes
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test get pods
NAME READY STATUS RESTARTS AGE
no-st-1 0/1 CreateContainerConfigError 0 74m <<--ignore the ConfigError, this is expected.
# nodes
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test auth can-i get nodes
Warning: resource 'nodes' is not namespace scoped
yes <<<<------ ?? i can get nodes, but then i can't??
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test get nodes
Error from server (Forbidden): nodes is forbidden: User "system:serviceaccount:psp-ns:sa-test" cannot list resource "nodes" in API group "" at the cluster scope
#deployments (at least this one is consistent, although the role should allow this)
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test auth can-i get deployments
no
Simons-MBP:psp simon$ kubectl --as=system:serviceaccount:psp-ns:sa-test get deployments
Error from server (Forbidden): deployments.apps is forbidden: User "system:serviceaccount:psp-ns:sa-test" cannot list resource "deployments" in API group "apps" in the namespace "psp-ns"
The role I am using should allow all 3 operations above:
Simons-MBP:psp simon$ kubectl describe role test-sa-role
Name: test-sa-role
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"Role","metadata":{"annotations":{},"name":"test-sa-role","namespace":"psp-ns"},"rules...
PolicyRule:
Resources Non-Resource URLs Resource Names Verbs
--------- ----------------- -------------- -----
deployments [] [] [list get]
nodes [] [] [list get]
pods [] [] [list get]
And finally the role binding showing that the role is attached to this service account:
Simons-MBP:psp simon$ kubectl describe rolebinding rb-test
Name: rb-test
Labels: <none>
Annotations: kubectl.kubernetes.io/last-applied-configuration:
{"apiVersion":"rbac.authorization.k8s.io/v1","kind":"RoleBinding","metadata":{"annotations":{},"name":"rb-test","namespace":"psp-ns"},"rol...
Role:
Kind: Role
Name: test-sa-role
Subjects:
Kind Name Namespace
---- ---- ---------
ServiceAccount sa-test psp-ns
Why is this happening? I was expecting to be able to get all nodes/pods/deployments, and that auth can-i returns yes for all calls I tried.