This repository has been archived by the owner on Dec 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbasic-example-policy.rego
93 lines (72 loc) · 2.47 KB
/
basic-example-policy.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
82
83
84
85
86
87
88
89
90
91
92
93
package kafka.authz.example.basic
default allow = false
allow {
not deny
}
deny {
not allow_consumer_group
not allow_producer_group
not allow_admin_group
}
allow_consumer_group {
is_consumer_operation
is_consumer_group
}
allow_producer_group {
is_producer_operation
is_producer_group
}
allow_admin_group {
is_admin_operation
is_admin_group
}
###############################################################################
# Groups and their helper rules
###############################################################################
consumer_group = ["tom", "tyrone", "matt", "pepe", "douglas"]
producer_group = ["jack", "conor", "keinan", "john"]
admin_group = ["dean", "christian"]
is_consumer_group {
consumer_group[_] == principal.name
}
is_producer_group {
producer_group[_] == principal.name
}
is_admin_group {
admin_group[_] == principal.name
}
###############################################################################
# Operations and their helper rules
###############################################################################
consumer_operations = {
"Topic": ["Read", "Describe"],
"Group": ["Read", "Describe"]
}
producer_operations = {
"Topic": ["Write", "Describe"]
}
admin_operations = {
"Topic": ["Read", "Write", "Create", "Delete", "Alter", "Describe", "ClusterAction", "DescribeConfigs", "AlterConfigs"],
"Group": ["Read", "Delete", "Describe"],
"Cluster": ["Create", "Alter", "Describe", "ClusterAction", "DescribeConfigs", "AlterConfigs"]
}
is_consumer_operation {
consumer_operations[input.resource.resourceType.name][_] == input.operation.name
}
is_producer_operation {
producer_operations[input.resource.resourceType.name][_] == input.operation.name
}
is_admin_operation {
admin_operations[input.resource.resourceType.name][_] == input.operation.name
}
###############################################################################
# Helper rules for input processing
###############################################################################
principal = {"fqn": parsed.CN, "name": cn_parts[0]} {
parsed := parse_user(urlquery.decode(input.session.sanitizedUser))
cn_parts := split(parsed.CN, ".")
}
parse_user(user) = {key: value |
parts := split(user, ",")
[key, value] := split(parts[_], "=")
}