Skip to content

Commit cfdd2cb

Browse files
committed
Add some comments to rego
1 parent c2b1dde commit cfdd2cb

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

coderd/rbac/policy.rego

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ bool_flip(b) = flipped {
1919
flipped = true
2020
}
2121

22-
# perms_grant returns a set of boolean values (true, false).
22+
# perms_grant returns a set of boolean values {true, false}.
23+
# True means a positive permission in the set, false is a negative permission.
2324
# It will only return `bool_flip(perm.negate)` for permissions that affect a given
2425
# resource_type, resource_id, and action.
2526
# The empty set is returned if no relevant permissions are found.
@@ -41,7 +42,7 @@ perms_grant(permissions) = grants {
4142
default site = {}
4243
site = grant {
4344
# Boolean set for all site wide permissions.
44-
grant = { v | # Use set comprehension to remove dulpicate values
45+
grant = { v | # Use set comprehension to remove duplicate values
4546
# For each role, grab the site permission.
4647
# Find the grants on this permission list.
4748
v = perms_grant(input.subject.roles[_].site)[_]
@@ -53,7 +54,7 @@ user = grant {
5354
# Only apply user permissions if the user owns the resource
5455
input.object.owner != ""
5556
input.object.owner == input.subject.id
56-
grant = { v | # Use set comprehension to remove dulpicate values
57+
grant = { v |
5758
# For each role, grab the user permissions.
5859
# Find the grants on this permission list.
5960
v = perms_grant(input.subject.roles[_].user)[_]
@@ -84,12 +85,15 @@ org_non_member {
8485
}
8586

8687
# org is two rules that equate to the following
87-
# if !org_non_member { return org_member }
88-
# else {false}
88+
# if org_non_member { return {false} }
89+
# else { org_member }
8990
#
9091
# It is important both rules cannot be true, as the `org` rules cannot produce multiple outputs.
91-
default org = []
92+
default org = {}
9293
org = set {
94+
# We have to do !org_non_member because rego rules must evaluate to 'true'
95+
# to have a value set.
96+
# So we do "not not-org-member" which means "subject is in org"
9397
not org_non_member
9498
set = org_member
9599
}
@@ -112,6 +116,8 @@ allow {
112116
site[_]
113117
}
114118

119+
# OR
120+
115121
# org allow
116122
allow {
117123
# No site or org deny
@@ -121,6 +127,8 @@ allow {
121127
org[_]
122128
}
123129

130+
# OR
131+
124132
# user allow
125133
allow {
126134
# No site, org, or user deny

0 commit comments

Comments
 (0)