-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathwrapper.rego
82 lines (73 loc) · 1.95 KB
/
wrapper.rego
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package wrapper
import data.policy as policy
import data.police_builtins as pb
import data.config
import future.keywords.in
main[{"violations": violation}] {
config.evalSaViolations
violation := {"serviceAccounts": saViolations}
} {
config.evalNodeViolations
violation := {"nodes": nodeViolations}
} {
config.evalCombinedViolations
violation := {"combined": combinedViolations}
} {
config.evalUserViolations
violation := {"users": userViolations}
} {
config.evalGroupViolations
violation := {"groups": groupViolations}
}
saViolations = violations {
"serviceAccounts" in policy.targets
violations := { violation |
some sa in input.serviceAccounts
saEffectiveRoles := pb.effectiveRoles(sa.roles)
policy.evaluateRoles(saEffectiveRoles, "serviceAccount")
violation := {
"name": sa.name,
"namespace": sa.namespace,
"nodes": { shortedNode |
some node in sa.nodes
shortedNode := {node.name: node.pods}
},
}
}
count(violations) > 0
}
nodeViolations = violations {
"nodes" in policy.targets
violations := { violation |
some node in input.nodes
nodeEffectiveRoles := pb.effectiveRoles(node.roles)
policy.evaluateRoles(nodeEffectiveRoles, "node")
violation := node.name
}
count(violations) > 0
}
combinedViolations = violations {
"combined" in policy.targets
violations := policy.evaluateCombined
count(violations) > 0
}
userViolations = violations {
"users" in policy.targets
violations := { violation |
some user in input.users
effectiveRoles := pb.effectiveRoles(user.roles)
policy.evaluateRoles(effectiveRoles, "user")
violation := user.name
}
count(violations) > 0
}
groupViolations = violations {
"groups" in policy.targets
violations := { violation |
some group in input.groups
effectiveRoles := pb.effectiveRoles(group.roles)
policy.evaluateRoles(effectiveRoles, "group")
violation := group.name
}
count(violations) > 0
}