@@ -2,8 +2,10 @@ package authz
2
2
import future.keywords.in
3
3
import future.keywords.every
4
4
5
- # https://play.openpolicyagent.org/p/Jlzq5gIjkd
6
- # grant_allow: https://play.openpolicyagent.org/p/9wpE9x6Tg2
5
+ # A great playground: https://play.openpolicyagent.org/
6
+ # TODO: Add debug instructions to do in the cli. Running really short on time, the
7
+ # playground is sufficient for now imo. In the future we can provide a tidy bash
8
+ # script for running this against predefined input.
7
9
8
10
# bool_flip lets you assign a value to an inverted bool.
9
11
# You cannot do 'x := !false', but you can do 'x := bool_flip(false)'
@@ -38,8 +40,10 @@ perms_grant(permissions) = grants {
38
40
# result is the default value.
39
41
default site = {}
40
42
site = grant {
41
- # Boolean set for all site wide permissions
42
- grant = { v |
43
+ # Boolean set for all site wide permissions.
44
+ grant = { v | # Use set comprehension to remove dulpicate values
45
+ # For each role, grab the site permission.
46
+ # Find the grants on this permission list.
43
47
v = perms_grant (input.subject.roles[_].site)[_]
44
48
}
45
49
}
@@ -49,13 +53,16 @@ user = grant {
49
53
# Only apply user permissions if the user owns the resource
50
54
input.object.owner != " "
51
55
input.object.owner == input.subject.id
52
- grant = { v |
56
+ grant = { v | # Use set comprehension to remove dulpicate values
57
+ # For each role, grab the user permissions.
58
+ # Find the grants on this permission list.
53
59
v = perms_grant (input.subject.roles[_].user)[_]
54
60
}
55
61
}
56
62
57
63
# Organizations are more complex. If the user has no roles that specifically indicate the org_id of the object,
58
64
# then we want to block the action. This is because that means the user is not a member of the org.
65
+ # A non-member cannot access any org resources.
59
66
60
67
# org_member returns the set of permissions associated with a user if the user is a member of the
61
68
# organization
@@ -94,6 +101,8 @@ org = set {
94
101
95
102
# The allow block is quite simple. Any set with `false` cascades down in levels.
96
103
# Authorization looks for any `allow` statement that is true. Multiple can be true!
104
+ # Note that the absense of `allow` means "unauthorized".
105
+ # An explicit `"allow": true` is required.
97
106
98
107
# site allow
99
108
allow {
0 commit comments