Description
In a Role or ClusterRole, * in apiGroups, resources or verbs matches every value in that field. List only the API groups, resources and operations needed within the scope of the other fields and the binding.
Potential impact
A resource or verb wildcard can grant unnecessary permissions. It can also cover resources or operations added later without any change to the role.
Remediation
Check which accounts receive the role through a RoleBinding or ClusterRoleBinding and where the grant applies. After replacing a wildcard, verify that the service account can perform required actions and is denied unrelated ones.
Examples
The first Role uses * in all three fields in the rbac2 namespace. The second example defines a different kind of resource, a ClusterRole, so it does not replace that Role.
Role with wildcards
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: rbac2
name: configmap-modifier
rules:
- apiGroups: ["*"]
resources: ["*"]
verbs: ["*"]
ClusterRole with explicit operations
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
namespace: opa
name: configmap-modifier
rules:
- apiGroups: [""]
resources: ["configmaps"]
verbs: ["update", "patch"]
The second rule grants only update and patch on core configmaps. Omit metadata.namespace in a deployed ClusterRole. Use a RoleBinding to grant these operations in one namespace. A ClusterRoleBinding grants them across namespaces.