Skip to content

Commit 0de511a

Browse files
learn stuff
Signed-off-by: ivan katliarchuk <[email protected]>
1 parent 5b7a971 commit 0de511a

File tree

7 files changed

+77
-1
lines changed

7 files changed

+77
-1
lines changed

playground/ex13/denied_provisioners.rego

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ denied_provisioners = ["local-exec"]
1010

1111

1212
array_contains(arr, elem) {
13-
arr[_] = elem
13+
arr[_] = elem
1414
}
1515

1616
module_name(path) = name {

playground/ex17/enforce_aws_resource.rego

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
# before "not array_contains..."
66
#
77
# startswith(resources.type,"aws_")
8+
# https://www.scalr.com/blog/opa-series-part-1-open-policy-agent-and-terraform
89

910
package terraform
1011

playground/ex26/data.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"attributes": {
3+
"user": [
4+
"read:books"
5+
],
6+
"moderator": [
7+
"read:books",
8+
"write:books"
9+
],
10+
"administrator": [
11+
"read:books",
12+
"write:books",
13+
"read:store",
14+
"write:store"
15+
]
16+
}
17+
}

playground/ex26/mapping.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"user": [
3+
"read:books"
4+
],
5+
"moderator": [
6+
"read:books",
7+
"write:books"
8+
],
9+
"administrator": [
10+
"read:books",
11+
"write:books",
12+
"read:store",
13+
"write:store"
14+
]
15+
}

playground/ex26/policy.rego

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# https://stackoverflow.com/questions/71420104/opa-authorization-policies-with-scopes-and-roles?rq=1
2+
package whatever.authz
3+
4+
context_scope == data["attributes"][principal_role][_]
5+
6+
# context_scope := concat(":", [input.context.action, input.context.resource])
7+
context_scope = data["attributes"][principal_role][_]
8+
9+
default allow = false
10+
11+
allow if {
12+
token_has_context_scope
13+
principal_has_resource_access
14+
}
15+
16+
token_has_context_scope if {
17+
context_scope == input.token.scopes[_]
18+
}
19+
20+
principal_has_resource_access if {
21+
principal_role := input.principal.roles[_]
22+
context_scope == data[principal_role][_]
23+
}

playground/ex27/authorizer.rego

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package authorizer
2+
3+
default username := null
4+
5+
decode_user(jwt) := user_id {
6+
// logic to decode token & return user_id
7+
}

playground/ex27/policy.rego

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package user
2+
3+
import data.authorizer.*
4+
5+
default allow := false
6+
7+
user_id := x {
8+
x := decode_user(input.jwt)
9+
}
10+
11+
allow := true {
12+
user_id != null
13+
}

0 commit comments

Comments
 (0)