-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrole-binding-role-ref.yaml
39 lines (37 loc) · 1013 Bytes
/
role-binding-role-ref.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
apiVersion: kubevious.io/v1alpha1
kind: ClusterRule
metadata:
name: role-binding-role-ref
spec:
summary: |
Validate RoleBinding and ClusterRoleBinding to Role and ClusterRole reference.
categories:
- k8s
- rbac
- binding
- role
- reference
target: |
Union(
Api('rbac.authorization.k8s.io')
.Kind("ClusterRoleBinding")
.isClusterScope(true),
Api('rbac.authorization.k8s.io')
.Kind("RoleBinding"),
)
rule: |
if (!config.roleRef) {
error(`RoleRef not set`);
return;
}
const roleKind = config.roleRef.kind;
const role = Api(config.roleRef.apiGroup)
.Kind(roleKind)
.name(config.roleRef.name)
.isClusterScope(roleKind.startsWith('Cluster'))
.namespace(config.roleRef.namespace ?? item.namespace)
.single();
if (!role)
{
error(`Could not find ${config.roleRef.kind} ${config.roleRef.name}`);
}