Last active
September 21, 2020 10:16
-
-
Save shalomb/524fc74d2598ce85e044e1973e8e394b to your computer and use it in GitHub Desktop.
OPA Test Run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"roles": [ | |
{ | |
"operation": "read", | |
"resource": "widgets", | |
"name": "widget-reader" | |
}, | |
{ | |
"operation": "write", | |
"resource": "widgets", | |
"name": "widget-writer" | |
} | |
], | |
"bindings": [ | |
{ | |
"user": "inspector-alice", | |
"role": "widget-reader" | |
}, | |
{ | |
"user": "maker-bob", | |
"role": "widget-writer" | |
} | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"input": { | |
"subject": { | |
"user": "maker-bob" | |
}, | |
"action": { | |
"resource": "widgets", | |
"operation": "write" | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# opa run --server \ | |
--log-format json \ | |
--set decision_logs.console=true \ | |
-l debug \ | |
./data.json ./policy.rego |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example_rbac | |
default allow = false | |
allow { | |
user_has_role[role_name] | |
role_has_permission[role_name] | |
} | |
user_has_role[role_name] { | |
role_binding = data.bindings[_] | |
role_binding.role = role_name | |
role_binding.user = input.subject.user | |
} | |
role_has_permission[role_name] { | |
role = data.roles[_] | |
role.name = role_name | |
role.operation = input.action.operation | |
role.resource = input.action.resource | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ mkdir /tmp/opa-tests | |
$ cd /tmp/opa-tests | |
$ cat <<EOF > input.json | |
{ | |
"input": { | |
"subject": { | |
"user": "maker-bob" | |
}, | |
"action": { | |
"resource": "widgets", | |
"operation": "write" | |
} | |
} | |
} | |
EOF | |
$ curl -fslLX POST -d "@input.json" 'http://dev.authzaas.in.pan-net.eu:8181/v1/data/example_rbac/allow' | jq -S . | |
{ | |
"result": true | |
} | |
$ curl -fslLX POST -d "@input.json" 'http://dev.authzaas.in.pan-net.eu:8181/v1/data/example_rbac/user_has_role' | jq -S . | |
{ | |
"result": [ | |
"widget-writer" | |
] | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment