Skip to content

Commit 8b4f159

Browse files
committed
added group functionality for global_policies
1 parent 8856b43 commit 8b4f159

4 files changed

Lines changed: 69 additions & 13 deletions

File tree

rego/nifi_global_logic.rego

Lines changed: 54 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,90 @@ res_is_global_type := nifi_inp.resource_id in global_policy_types # return
1515

1616
has_key(obj, key) := true if _ = obj[key] # helper function
1717

18-
# Searches an entry in the nifi_global_policies abstraction layer
18+
# Searches user entry in the nifi_global_policies abstraction layer
1919
global_policy_user_has_permissions(res_id, user_name, action) := true if {
2020
has_key(global_policies, res_id)
2121
has_key(global_policies[res_id]["users"], user_name)
2222
global_policies[res_id]["users"][user_name] == action
2323
}
2424

25+
# Searches user-group entry in the nifi_global_policies abstraction layer
26+
global_policy_group_has_permissions(res_id, user_groups, action) := true if {
27+
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[_] }
30+
count(x & y) > 0 # check if there is atleast one intersecting group
31+
}
32+
33+
### READ
2534
# true, if user is allowed to read on a given global policy
26-
global_policy_user_read := true if {
35+
global_policy_read := true if {
2736
global_policy_user_has_permissions(
2837
nifi_inp.inherit_resource_id,
2938
nifi_inp.user_name,
3039
"READ")
3140
}
41+
# true, if user is allowed to read on a given global policy
42+
global_policy_read := true if {
43+
global_policy_group_has_permissions(
44+
nifi_inp.inherit_resource_id,
45+
nifi_inp.user_groups,
46+
"READ")
47+
}
3248

49+
50+
### WRITE
3351
# true, if user is allowed to write on a given global policy
34-
global_policy_user_write := true if {
52+
global_policy_write := true if {
3553
global_policy_user_has_permissions(
3654
nifi_inp.inherit_resource_id,
3755
nifi_inp.user_name,
3856
"WRITE")
3957
}
58+
# true, if user-group is allowed to write on a given global policy
59+
global_policy_write := true if {
60+
global_policy_group_has_permissions(
61+
nifi_inp.inherit_resource_id,
62+
nifi_inp.user_groups,
63+
"WRITE")
64+
}
65+
4066

67+
### FULL
4168
# true, if user is allowed to read AND write on a given global policy
42-
global_policy_user_full := true if {
69+
global_policy_full := true if {
4370
global_policy_user_has_permissions(
4471
nifi_inp.inherit_resource_id,
4572
nifi_inp.user_name,
4673
"FULL")
4774
}
4875

76+
# true, if a user-group is allowed to read AND write on a given global policy
77+
global_policy_full := true if {
78+
global_policy_group_has_permissions(
79+
nifi_inp.inherit_resource_id,
80+
nifi_inp.user_groups,
81+
"FULL")
82+
}
83+
84+
85+
### DENY
4986
# true, if user is explicitly denied on a given global policy
5087
global_policy_user_denied := true if {
5188
global_policy_user_has_permissions(
5289
nifi_inp.inherit_resource_id,
5390
nifi_inp.user_name,
5491
"DENY")
55-
}
92+
}
93+
94+
# true, if user-group is explicitly denied on a given global policy
95+
global_policy_user_denied := true if {
96+
global_policy_group_has_permissions(
97+
nifi_inp.inherit_resource_id,
98+
nifi_inp.user_groups,
99+
"DENY")
100+
}
101+
102+
103+
# e2 = is_array(y)
104+
# z := intersection(x|y)

rego/nifi_global_policies.rego

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ global_policies := {
1111
"User1": "FULL",
1212
"User2": "READ"
1313
},
14-
"groups": {}
14+
"groups": {
15+
"Group 1": "FULL",
16+
"Test123": "READ"
17+
}
1518
},
1619
"/controller": {
1720
"users": {

rego/nifi_input.rego

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ resource_safeDescr := input.requestedResource.safeDescription
1010
resource_context := input.resourceContext
1111
action := input.action.name
1212
user_name := input.user.name
13-
user_groups := split(input.user.name.groups, ",")
13+
user_groups := split(input.user.groups, ",")
1414
user_context := input.userContext
1515
isAccessAttempt := input.properties.isAccessAttempt
16-
isAnonymous := input.properties.isAnonymous
16+
isAnonymous := input.properties.isAnonymous
17+
18+
# test := true if {
19+
# action == "read"
20+
# }

rego/nifi_rules.rego

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ allow := {
3030
} if {
3131
nifi_glob.res_is_global_type
3232
nifi_inp.action == "read"
33-
nifi_glob.global_policy_user_read
33+
nifi_glob.global_policy_read
3434
}
3535

3636
# check for writing permission
@@ -40,7 +40,7 @@ allow := {
4040
} if {
4141
nifi_glob.res_is_global_type
4242
nifi_inp.action == "write"
43-
nifi_glob.global_policy_user_write
43+
nifi_glob.global_policy_write
4444
}
4545

4646
# check for full permission when action is read
@@ -50,7 +50,7 @@ allow := {
5050
} if {
5151
nifi_glob.res_is_global_type
5252
nifi_inp.action == "read"
53-
nifi_glob.global_policy_user_full
53+
nifi_glob.global_policy_full
5454
}
5555

5656
# check for full permission when action is write
@@ -60,7 +60,7 @@ allow := {
6060
} if {
6161
nifi_glob.res_is_global_type
6262
nifi_inp.action == "write"
63-
nifi_glob.global_policy_user_full
63+
nifi_glob.global_policy_full
6464
}
6565

6666
# check for denied permission
@@ -70,7 +70,7 @@ allow := {
7070
"message": sprintf("Action %s on global resource %s denied.", [nifi_inp.action, nifi_inp.resource_name])
7171
} if {
7272
nifi_glob.res_is_global_type
73-
nifi_glob.global_policy_user_denied
73+
nifi_glob.global_policy_denied
7474
}
7575

7676

0 commit comments

Comments
 (0)