Skip to content

Commit 6fdee20

Browse files
committed
added group support for both component policies
1 parent 8b4f159 commit 6fdee20

3 files changed

Lines changed: 95 additions & 22 deletions

File tree

rego/nifi_component_logic.rego

Lines changed: 89 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,59 @@ has_key(obj, key) := true if _ = obj[key]
1111

1212
# Root Component Rules Logic
1313
root_policy_types := [key | key := object.keys(root_policies)[_]]
14-
get_root_type := x if {
14+
get_root_type := rt if {
1515
comp_type = root_policy_types[_]
1616
startswith(nifi_inp.inherit_resource_id, comp_type)
17-
x = comp_type
17+
rt = comp_type
1818
}
1919
comp_is_root_type := get_root_type in root_policy_types
2020

2121
component_exists_in_root(comp_type, res_name) := true if {
2222
has_key(root_policies, comp_type)
2323
has_key(root_policies[comp_type], res_name)
2424
}
25+
2526
root_policy_user_has_permissions(comp_type, res_name, user_name, action) := true if {
2627
component_exists_in_root(comp_type, res_name)
2728
user_name in root_policies[comp_type][res_name][action]["users"]
29+
}
30+
root_policy_group_has_permissions(comp_type, res_name, user_groups, action) := true if {
31+
component_exists_in_root(comp_type, res_name)
32+
x := { trim(k, " ") | k = root_policies[comp_type][res_name][action]["groups"][_] }
33+
y := { trim(k, " ") | k = user_groups[_] }
34+
count(x & y) > 0
2835
}
2936

3037

31-
3238
# node Component Rules Logic
3339
node_policy_types := [key | key := object.keys(node_policies)[_]]
34-
get_node_type := x if {
40+
get_node_type := nt if {
3541
comp_type = node_policy_types[_]
3642
startswith(nifi_inp.inherit_resource_id, comp_type)
37-
x = comp_type
43+
nt = comp_type
3844
}
3945
comp_is_node_type := get_node_type in node_policy_types
4046
compID := array.reverse(split(nifi_inp.resource_id, "/"))[0]
4147
inheritCompID := array.reverse(split(nifi_inp.inherit_resource_id, "/"))[0]
4248

43-
component_exists_in_node(comp_type, comp_ID) := true if {
49+
component_exists_in_node(comp_type, res_ID) := true if {
4450
has_key(node_policies, comp_type)
45-
has_key(node_policies[comp_type], comp_ID)
51+
has_key(node_policies[comp_type], res_ID)
4652
}
4753

48-
node_policy_user_has_permissions(comp_type, comp_ID, user_name, action) := true if {
49-
component_exists_in_node(comp_type, comp_ID)
50-
user_name in node_policies[comp_type][comp_ID][action]["users"]
54+
node_policy_user_has_permissions(comp_type, res_ID, user_name, action) := true if {
55+
component_exists_in_node(comp_type, res_ID)
56+
user_name in node_policies[comp_type][res_ID][action]["users"]
57+
}
58+
node_policy_group_has_permissions(comp_type, res_ID, user_groups, action) := true if {
59+
component_exists_in_node(comp_type, res_ID)
60+
x := { trim(k, " ") | k = node_policies[comp_type][res_ID][action]["groups"][_] }
61+
y := { trim(k, " ") | k = user_groups[_] }
62+
count(x & y) > 0
5163
}
5264

5365

54-
55-
56-
## Flow Access
66+
### "NiFi Flow" - Access
5767
flow_allowed:= true if {
5868
root_policy_user_has_permissions(
5969
get_root_type,
@@ -69,36 +79,71 @@ flow_denied:= true if { # macht nur Sinn für Unter-Res zu denyn
6979
"deny")
7080
}
7181

82+
### Root component access
83+
7284
root_comp_allowed := true if {
7385
root_policy_user_has_permissions(
7486
get_root_type,
7587
nifi_inp.resource_name,
7688
nifi_inp.user_name,
7789
nifi_inp.action)
7890
}
91+
root_comp_allowed := true if {
92+
root_policy_group_has_permissions(
93+
get_root_type,
94+
nifi_inp.resource_name,
95+
nifi_inp.user_groups,
96+
nifi_inp.action)
97+
}
98+
7999
root_comp_denied := true if {
80100
root_policy_user_has_permissions(
81101
get_root_type,
82102
nifi_inp.resource_name,
83103
nifi_inp.user_name,
84104
"deny")
85105
}
106+
root_comp_denied := true if {
107+
root_policy_group_has_permissions(
108+
get_root_type,
109+
nifi_inp.resource_name,
110+
nifi_inp.user_groups,
111+
"deny")
112+
}
113+
86114
root_inherit_comp_allowed := true if {
87115
root_policy_user_has_permissions(
88116
get_root_type,
89117
nifi_inp.inherit_resource_name,
90118
nifi_inp.user_name,
91119
nifi_inp.action)
92120
}
121+
root_inherit_comp_allowed := true if {
122+
root_policy_group_has_permissions(
123+
get_root_type,
124+
nifi_inp.inherit_resource_name,
125+
nifi_inp.user_groups,
126+
nifi_inp.action)
127+
}
128+
93129
root_inherit_comp_denied := true if {
94130
root_policy_user_has_permissions(
95131
get_root_type,
96132
nifi_inp.inherit_resource_name,
97133
nifi_inp.user_name,
98134
"deny")
99135
}
136+
root_inherit_comp_denied := true if {
137+
root_policy_group_has_permissions(
138+
get_root_type,
139+
nifi_inp.inherit_resource_name,
140+
nifi_inp.user_groups,
141+
"deny")
142+
}
143+
100144

101145

146+
### Node component access
102147

103148
node_comp_allowed := true if {
104149
node_policy_user_has_permissions(
@@ -107,27 +152,58 @@ node_comp_allowed := true if {
107152
nifi_inp.user_name,
108153
nifi_inp.action)
109154
}
155+
node_comp_allowed := true if {
156+
node_policy_group_has_permissions(
157+
get_node_type,
158+
compID,
159+
nifi_inp.user_groups,
160+
nifi_inp.action)
161+
}
162+
110163
node_comp_denied := true if {
111164
node_policy_user_has_permissions(
112165
get_node_type,
113166
compID,
114167
nifi_inp.user_name,
115168
"deny")
116169
}
170+
node_comp_denied := true if {
171+
node_policy_group_has_permissions(
172+
get_node_type,
173+
compID,
174+
nifi_inp.user_groups,
175+
"deny")
176+
}
177+
117178
node_inherit_comp_allowed := true if {
118179
node_policy_user_has_permissions(
119180
get_node_type,
120181
inheritCompID,
121182
nifi_inp.user_name,
122183
nifi_inp.action)
123184
}
185+
node_inherit_comp_allowed := true if {
186+
node_policy_group_has_permissions(
187+
get_node_type,
188+
inheritCompID,
189+
nifi_inp.user_groups,
190+
nifi_inp.action)
191+
}
192+
124193
node_inherit_comp_denied := true if {
125194
node_policy_user_has_permissions(
126195
get_node_type,
127196
inheritCompID,
128197
nifi_inp.user_name,
129198
"deny")
130199
}
200+
node_inherit_comp_denied := true if {
201+
node_policy_group_has_permissions(
202+
get_node_type,
203+
inheritCompID,
204+
nifi_inp.user_groups,
205+
"deny")
206+
}
131207

132208
node_comp_has_action := true if {
133209
component_exists_in_node(get_node_type, inheritCompID)

rego/nifi_global_logic.rego

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@ global_policy_user_has_permissions(res_id, user_name, action) := true if {
2525
# Searches user-group entry in the nifi_global_policies abstraction layer
2626
global_policy_group_has_permissions(res_id, user_groups, action) := true if {
2727
has_key(global_policies, res_id)
28-
x := { k | k = object.keys(global_policies[nifi_inp.inherit_resource_id]["groups"])[_] }
29-
y := { k | k = nifi_inp.user_groups[_] }
28+
x := { trim(k, " ") | k = object.keys(global_policies[res_id]["groups"])[_] }
29+
y := { trim(k, " ") | k = user_groups[_] }
3030
count(x & y) > 0 # check if there is atleast one intersecting group
3131
}
3232

33+
3334
### READ
3435
# true, if user is allowed to read on a given global policy
3536
global_policy_read := true if {
@@ -97,8 +98,4 @@ global_policy_user_denied := true if {
9798
nifi_inp.inherit_resource_id,
9899
nifi_inp.user_groups,
99100
"DENY")
100-
}
101-
102-
103-
# e2 = is_array(y)
104-
# z := intersection(x|y)
101+
}

rego/nifi_root_policies.rego

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,15 @@ root_policies := {
3434
"Peter":{
3535
"read": {
3636
"users": ["User1"],
37-
"groups": []
37+
"groups": ["Group2","Group234"]
3838
},
3939
"write": {
4040
"users": ["User1"],
4141
"groups": []
4242
},
4343
"deny": {
4444
"users": [],
45-
"groups": []
45+
"groups": ["denyGroup"]
4646
}
4747
},
4848

0 commit comments

Comments
 (0)