I have the following ClusterRoles defined:
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: deployer-system
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- list
- nonResourceURLs:
- '*'
verbs:
- list
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: deployer-nonsystem
rules:
- apiGroups:
- '*'
resources:
- secrets
- PersistentVolumes
- Role
- RoleBinding
verbs:
- list
- apiGroups:
- '*'
resources:
- deployments
- pods
verbs:
- get
- list
- watch
- create
- update
- patch
- nonResourceURLs:
- '*'
verbs:
- list
I use the following RoleBindings to assign a user the above ClusterRole:
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: theuser-nonsystem-role-binding
namespace: nonsystem-namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: deployer-nonsystem
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: theuser
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: theuser-kube-system-role-binding
namespace: system-namespace
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: deployer-system
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: theuser
However, they are able to run a kubectl -n [NAMESPACE] get secrets -o yaml
and see all the secrets. I would expect this call to be forbidden based on the ClusterRole specifications above.
Am I missing or misunderstanding something here? Why can the user "get" secrets?
UPDATE: Please note: my issues is NOT that they can list secrets. My issue here is that the user can "get" secrets (different verbs!)
Because the
list
verbs means "get
applied to multiple resources". When you perform thekubectl get secret
operation without specifying an individual secret, you are performing alist
operation.Given the RBAC in your question, I can ask for all the secrets in the
system-namespace
namespace:But I cannot ask for a specific secret:
You should think of
list
as a more powerful version ofget
, since it permits someone the ability to enumerate and retrieve all the secrets. With onlyget
permission, an entity must know the name of a specific secret in order to access it, and you can in fact restrictget
access to specific resources by setting theresourceNames
component of a rule.Assuming that
system-namespace
has secretssecret1
andsecret2
, if I have an account bound to the following role:Then I can only retrieve secret
secret1
: