SlideShare uma empresa Scribd logo
1 de 73
Baixar para ler offline
Open Policy Agent
Language Introduction
openpolicyagent.org
OPA: Add fine-grained policy to other projects
OPA
Cloud
Orchestrator
Risk Management
Linux
Container Execution, SSH, sudo
OPA
Hashicorp
Terraform
OPA
Microservice APIs
Istio Linkerd
OPA
Placement &
Admission Control
openpolicyagent.org
Use OPA to policy-enable your project
Integrate
Offload policy decisions from your project to OPA
Author
Write OPA policies that make decisions
Manage
Deploy OPA, retrieve policy, audit decisions, monitor health
1
2
3
Agenda
● How Policies are Invoked
● Simple Policies
● Policies with Iteration
● Additional Topics
○ Modularity
○ Negation
○ Any/All
○ Non-boolean Decisions
How Policies are Invoked
● Overview
● Example:
○ HTTP API Authorization
openpolicyagent.org
How Policies are Invoked
DataLogic
openpolicyagent.org
How Policies are Invoked
DataLogic
POST v1/data/<policy-name>
{“input”: <JSON>}
1. Decision Request
Any JSON value:
● "alice"
● ["api", "v1", "cars"]
● {"headers": {...}}
openpolicyagent.org
How Policies are Invoked
DataLogic
200 OK
{“result”: <JSON>}
1. Decision Request 2. Decision Response
Any JSON value:
● true, false
● "bob"
● {"servers": ["server-001", 
]}
POST v1/data/<policy-name>
{“input”: <JSON>}
Any JSON value:
● "alice"
● ["api", "v1", "cars"]
● {"headers": {...}}
openpolicyagent.org
How Policies are Invoked
DataLogic
200 OK
{“result”: <JSON>}
Input is JSON. Policy decision is JSON.
1. Decision Request 2. Decision Response
POST v1/data/<policy-name>
{“input”: <JSON>}
Any JSON value:
● true, false
● "bob"
● {"servers": ["server-001", 
]}
Any JSON value:
● "alice"
● ["api", "v1", "cars"]
● {"headers": {...}}
openpolicyagent.org
Example: HTTP API Authorization
DataLogic
openpolicyagent.org
Example: HTTP API Authorization
DataLogic
1. Example Request to OPA
POST v1/data/http/authz/allow
{"input": {
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"}}
1
openpolicyagent.org
Example: HTTP API Authorization
DataLogic
1. Example Request to OPA
2. Example Policy in OPA
POST v1/data/http/authz/allow
{"input": {
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"}}
package http.authz
allow {
input.user == “bob”
}
1
2
openpolicyagent.org
Example: HTTP API Authorization
DataLogic
1. Example Request to OPA
2. Example Policy in OPA
3. Example Response from OPA
POST v1/data/http/authz/allow
{"input": {
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"}}
package http.authz
allow {
input.user == “bob”
}
{“result”: true}
1
2
3
Agenda
● How Policies are Invoked
● Simple Policies
● Policies with Iteration
● Additional Topics
○ Modularity
○ Negation
○ Non-boolean Decisions
Simple Policies
● Lookup values
● Compare values
● Assign values
● Create rules
● Create functions
● Use context (data)
openpolicyagent.org
Lookup and Compare Values
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Input
input.method
input.path[0]
Lookup values.
openpolicyagent.org
Lookup and Compare Values
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Input
input.method == “GET”
input.path[0] == “finance”
input.user != input.method
Lookup values. Compare values.
openpolicyagent.org
Lookup and Compare Values
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Input
input.method == “GET”
input.path[0] == “finance”
input.user != input.method
startswith(input.path[1], “sal”)
count(input.path) > 2
Lookup values. Compare values.
See 50+ operators documented at openpolicyagent.org/docs/language-reference.html
openpolicyagent.org
path := input.path
path[2] == "alice"
Assign Values to Variables
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Input Assign variables.
Use variables like input.
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow = true {
input.method == "GET"
input.user == "bob"
}
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow = true {
input.method == "GET"
input.user == "bob"
}
Rule Head
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow = true {
input.method == "GET"
input.user == "bob"
}
Rule Head
Name allow
Value true
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow {
input.method == "GET"
input.user == "bob"
}
Rule Head
Name allow
Value true
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow {
input.method == "GET"
input.user == "bob"
}
Rule Body
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow {
input.method == "GET"
input.user == "bob"
}
Rule Body
Multiple statements
in rule body
are ANDed together.
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules have a Head and a Body.
allow {
input.method == "GET"
input.user == "bob"
}
Rule Body
Multiple statements
in rule body
are ANDed together.
allow is true IF
input.method equals "GET" AND
input.user equals "bob"
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Multiple rules with same name.
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
openpolicyagent.org
Input
Create Rules
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Multiple rules with same name.
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}Rule Head
Multiple statements
with same head
are ORed together.
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules can be undefined.
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules can be undefined.
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
Different method.
"POST" instead of "GET"
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Rules can be undefined.
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
Different method.
"POST" instead of "GET"
Neither rule matches.
allow is undefined (not false!)
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Use default keyword.
default allow = false
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Use default keyword.
default allow = false
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
default <name> = <value>
If no rules match
default value is returned.
openpolicyagent.org
Create Rules
Input
{
"method": "POST",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Use default keyword.
default allow = false
allow {
input.method == "GET"
input.user == "bob"
}
allow {
input.method == "GET"
input.user == input.path[2]
}
default <name> = <value>
If no rules match
default value is returned.
at most one default per rule set
openpolicyagent.org
Create Functions
Input
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Path is a string now.
openpolicyagent.org
Create Functions
Input
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Example rule
default allow = false
allow {
trimmed := trim(input.path, "/")
path := split(trimmed, "/")
path = ["finance", "salary", user]
input.user == user
}
Path is a string now.
openpolicyagent.org
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Create Functions
Input Example rule
default allow = false
allow {
trimmed := trim(input.path, "/")
path := split(trimmed, "/")
path = ["finance", "salary", user]
input.user == user
}
Path is a string now.
Avoid duplicating
common logic like
string manipulation
openpolicyagent.org
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Create Functions
Input Put common logic into functions
default allow = false
allow {
path := split_path(input.path)
path = ["finance", "salary", user]
input.user == user
}
split_path(str) = parts {
trimmed := trim(str, "/")
parts := split(trimmed, "/")
}
Path is a string now.
Avoid duplicating
common logic like
string manipulation
openpolicyagent.org
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Create Functions
Input Functions are Rules with arguments.
read_method(str) = true {
str == "GET"
}
read_method(str) = true {
str == "HEAD"
}
openpolicyagent.org
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Create Functions
Input Functions are Rules with arguments.
read_method(str) = true {
str == "GET"
}
read_method(str) = true {
str == "HEAD"
}
"Function" Head
Multiple statements
with same head
are ORed together.
openpolicyagent.org
{
"method": "GET",
"path": "/finance/salary/alice",
"user": "bob"
}
Create Functions
Input Functions are Rules with arguments.
read_method(str) {
str == "GET"
}
read_method(str) {
str == "HEAD"
}
"Function" Head
Multiple statements
with same head
are ORed together.
openpolicyagent.org
Policies can use Context from Outside World
PUT v1/data/<path> HTTP/1.1
Content-Type: application/json
<JSON>
Load Context/Data Into OPA
DataLogic
openpolicyagent.org
{
"users": {
"alice": {"department": "legal"},
"bob": {"department": "hr"},
"janet": {"department": "r&d"}
}
}
{
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"
}
Policies Use Context
Data (context)
Policy
allow {
# Users can access their own salary
input.user == input.path[2]
}
allow {
# HR can access any salary
user := data.users[input.user]
user.department == "hr"
}
Input
openpolicyagent.org
Summary
Lookup values input.path[1]
Compare values "bob" == input.user
Assign values user := input.user
Rules <head> { <body> }
Rule Head <name> = <value> { 
 } or <name> { 
 }
Rule Body <statement-1>; <statement-2>; 
 (ANDed)
Multiple Rules with same name <rule-1> OR <rule-2> OR ...
Default Rule Value default <name> = <value>
Functions Rules with arguments
Context Reference with data. instead of input.
Agenda
● How Policies are Invoked
● Simple Policies
● Policies with Iteration
● Additional Topics
○ Modularity
○ Negation
○ Any/All
○ Non-boolean Decisions
Policies With Iteration
● Iteration
● Virtual documents
● Virtual documents vs Functions
openpolicyagent.org
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
...
],
...
}
# allow if resource is at element 0
allow {
input.resource == data.resources[0].id
input.user == data.resources[0].owner
}
What about Arrays?
Allow if user owns resource.
Not sure where resource is in array
{
"user": "alice"
"resource": "54cf10",
}
Input
Data
openpolicyagent.org
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
...
],
...
}
# allow if resource is at element 0
allow {
input.resource == data.resources[0].id
input.user == data.resources[0].owner
}
# OR if resource is at element 1
allow {
input.resource == data.resources[1].id
input.user == data.resources[1].owner
}
What about Arrays?
Allow if user owns resource.
Not sure where resource is in array
{
"user": "alice"
"resource": "54cf10",
}
Input
Data
openpolicyagent.org
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
...
],
...
}
# allow if resource is at element 0
allow {
input.resource == data.resources[0].id
input.user == data.resources[0].owner
}
# OR if resource is at element 1
allow {
input.resource == data.resources[1].id
input.user == data.resources[1].owner
}
...
What about Arrays?
Allow if user owns resource.
Not sure where resource is in array
{
"user": "alice"
"resource": "54cf10",
}
Input
Data
Problem: Unknown number of elements.
Cannot write allow for every index.
openpolicyagent.org
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
...
],
...
}
# allow if resource is anywhere in array
allow {
input.resource == data.resources[index].id
input.user == data.resources[index].owner
}
Iterate over Arrays
Allow if user owns resource.
Not sure where resource is in array
{
"user": "alice"
"resource": "54cf10",
}
Input
Data
openpolicyagent.org
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
...
],
...
}
# allow if resource is anywhere in array
allow {
input.resource == data.resources[index].id
input.user == data.resources[index].owner
}
Iterate over Arrays
Allow if user owns resource.
Not sure where resource is in array
{
"user": "alice"
"resource": "54cf10",
}
Input
Data
Solution:
● allow is true if SOME value for index makes
the rule body true.
● OPA automatically iterates over values for
index.
● allow is true for index = 0
openpolicyagent.org
Iterate over Everything
Iterate over arrays/dictionaries (whether input or data)
# Iterate over array indexes/values
resource_obj := data.resources[index]
# Iterate over dictionary key/values
user_obj := data.users[name]
# Doesn’t matter whether input or data
value := input[key]
# Use _ to ignore variable name
# Iterate over just the array values
resource_obj := data.resources[_]
{
"method": "GET",
"path": ["resources", "54cf10"],
"user": "bob"
}
Input
{
"resources": [
{"id": "54cf10", "owner": "alice"},
{"id": "3df429": "owner": "bob"}
],
"users": {
"alice": {"admin": false},
"bob": {"admin": true},
"charlie": {"admin": true},
}
}
Data
openpolicyagent.org
Duplicated Logic Happens with Iteration too
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
Data
allow {
user := data.users[_]
user.admin == true
user.name == input.user
input.method == “GET”
}
allow {
user := data.users[_]
user.admin == true
user.name == input.user
input.method == “POST”
}
Duplicated logic with iteration
openpolicyagent.org
Duplicated Logic Happens with Iteration too
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
Data
allow {
user := data.users[_]
user.admin == true
user.name == input.user
input.method == “GET”
}
allow {
user := data.users[_]
user.admin == true
user.name == input.user
input.method == “POST”
}
Duplicated logic with iteration
Avoid duplicating
common logic like a
search for admins
openpolicyagent.org
Create a Virtual Document
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
Data
allow {
admin[input.user]
input.method == “GET”
}
allow {
admin[input.user]
input.method == “POST”
}
admin[user.name] {
user := data.users[_]
user.admin == true
}
Duplicated logic with iteration
admin is a set that contains all of the admin names
Sets are an extension of JSON.
admin == { "bob", "charlie" }
openpolicyagent.org
Different Syntaxes for Virtual Sets
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
admin[user.name] {
user := data.users[_]
user.admin == true
}
Data Rule Syntax
admin = {user.name |
user := data.users[_]
user.admin == true
}
Set Comprehension Syntax
openpolicyagent.org
Different Syntaxes for Virtual Sets
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
admin[user.name] {
user := data.users[_]
user.admin == true
}
Data Rule Syntax
admin = {user.name |
user := data.users[_]
user.admin == true
}
Set Comprehension Syntax
Supports OR with
multiple rules.
No support for OR.
openpolicyagent.org
Create Virtual Dictionaries too
{
“users”: [
{"name": "alice", "admin": false, “dept”: “eng”},
{"name": "bob", "admin": true, “dept”: “hr”},
{"name": "charlie", "admin": true, “dept”: “eng”},
}
}
Data
admin[user.name] = user.dept {
user := data.users[_]
user.admin == true
}
Rule Syntax
admin = {user.name: user.dept |
user := data.users[_]
user.admin == true
}
Dictionary Comprehension Syntax
openpolicyagent.org
Virtual Docs support iteration. Functions don’t.
admin[user_name] = user.dept {
user := data.users[_]
user.admin == true
user.name == user_name
}
admin(user_name) = user.dept {
user := data.users[_]
user.admin == true
user.name == user_name
}
Dictionary Function
# lookup bob’s department
admin[“bob”]
# iterate over all user/dept pairs
admin[user] = department
# iterate over everyone in HR
admin[user] == “hr”
# lookup bob’s department
admin(“bob”)
# iterate over all user/dept pairs
Can’t. Write different function.
# iterate over everyone in HR
Can’t.
openpolicyagent.org
Virtual Documents must be finite. Functions don’t.
Can’t express split_path.
Virtual docs must be “safe”.
Safety means the set of all
input/output pairs is finite.
split_path takes any string as
input. There are infinitely
strings.
split_path(str) = parts {
trimmed := trim(str, "/")
parts := split(trimmed, "/")
}
Virtual Doc Function
Agenda
● How Policies are Invoked
● Simple Policies
● Policies with Iteration
● Additional Topics
○ Modularity
○ Negation
○ Any/All
○ Non-boolean Decisions
openpolicyagent.org
People can Create Multiple Policies and Delegate
package http.service_graph
allow {
input.source == “frontend”
input.destination == “finance”
}
...
Service graph policy
package http.org_chart
allow {
admin[user.input]
}
...
Organization chart policy
package http.authz
import data.http.service_graph
import data.http.org_chart
allow {
org_chart.allow
service_graph.allow
}
Entry point policy
openpolicyagent.org
Policies can use Negation
package http.service_graph
deny {
input.source == “frontend”
input.destination == “finance”
}
...
Service graph policy
package http.org_chart
allow {
admin[user.input]
}
Organization chart policy
package http.authz
import data.http.service_graph
import data.http.org_chart
allow {
org_chart.allow
not service_graph.deny
not deny
}
deny { ... }
Entry point policy
openpolicyagent.org
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
}
}
Any vs. All
Data Check if all users are admins. Wrong ans:
all_admins = true {
data.users[user_name].admin == true
}
openpolicyagent.org
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
}
}
Any vs. All
Data Check if all users are admins. Wrong ans:
all_admins = true {
data.users[user_name].admin == true
}
Problem: all_admins is true if ANY users are admins.
openpolicyagent.org
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
}
}
Any vs. All
Data Check if all users are admins.
all_admins = true {
not any_non_admins
}
any_non_admins = true {
user := data.users[user_name]
not user.admin
}
Solution:
1. Check if any users
are NOT admins
2. Complement (1)
openpolicyagent.org
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
}
}
Any vs. All
Data Check if all users are admins.
all_admins = true {
not any_non_admins
}
any_non_admins = true {
user := data.users[user_name]
not user.admin
}
Solution:
1. Check if any users
are NOT admins
2. Complement (1)
openpolicyagent.org
allow/deny are NOT special. Decisions are JSON
DataLogic
POST v1/data/http/authz/admin
{"input": {
"method": "GET",
"path": ["finance", "salary", "alice"],
"user": "bob"}}
2. Example Policy
1. Example Request
3. Example Response
{“result”: [“bob”, “charlie”]}
package http.authz
import data.http.service_graph
import data.http.org_chart
admin[x] {
org_chart.admin[x]
}
admin[x] {
service_graph.admin[x]
}
Sets defined with
multiple rules
are unioned together.
Policy decision can be any
JSON data: boolean, number,
string, null, array, or dictionary.
Sets are serialized to JSON
arrays.
openpolicyagent.org
Thank You!
github.com/open-policy-agent/opa
slack.openpolicyagent.org
openpolicyagent.org
Policy Example with Join
openpolicyagent.org
Policies Iterate to Search for Data
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
},
“orgs”: {
“00”: {“name”: “HR”},
“11”: {“name”: “Legal”},
“22”: {“name”: “Research”},
“33”: {“name”: “IT”},
“44”: {“name”: “Accounting”},
}
}
Data Search for the data you need
user_obj user_name org_name
{"admin": true, ...} bob Research
{"admin": true, ...} charlie IT
# Find admin users and their organization
user_obj := data.users[user_name];
user_obj.admin == true;
org_name := data.orgs[user_obj.org_code].name
Variable assignments that satisfy search criteria
openpolicyagent.org
Policies Give Names to Search Results
Data Name the search results
admins[[org_name, user_name]] {
user_obj := data.users[user_name]
user_obj.admin == true
org_name := data.orgs[user_obj.org_code].name
}
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
},
“orgs”: {
“00”: {“name”: “HR”},
“11”: {“name”: “Legal”},
“22”: {“name”: “Research”},
“33”: {“name”: “IT”},
“44”: {“name”: “Accounting”},
}
}
admins is a set that contains
all of the [org_name, user_name] pairs
that make the body true.
admins == {
["Research", "bob"],
["IT", "charlie"],
}
openpolicyagent.org
Policies Apply Search Results to Make Decisions
Input
{
“users”: {
"alice": {"admin": false, “org_code”: “11”},
"bob": {"admin": true, “org_code”: “22”},
"charlie": {"admin": true, “org_code”: “33”}
},
“orgs”: {
“00”: {“name”: “HR”},
“11”: {“name”: “Legal”},
“22”: {“name”: “Research”},
...
Apply the search results
allow {
# allow admins to do everything
admins[[_, input.user]]
}
admins[[org_name, user_name]] {
user_obj := data.users[user_name]
user_obj.admin == true
org_name := data.orgs[user_obj.org_code].name
}
Check if bob is an admin
Lookup IT admins
Iterate over all pairs
admins[[_, “bob”]]
admins[[“IT”, name]]
admins[x]
{
"method": "GET",
"path": ["resources", "54cf10"],
"user": "bob"
}
Data

Mais conteĂșdo relacionado

Mais procurados

Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)
Istio's mixer  policy enforcement with custom adapters (cloud nativecon 17)Istio's mixer  policy enforcement with custom adapters (cloud nativecon 17)
Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)Torin Sandall
 
Kubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentKubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentCloudOps2005
 
Implementing Authorization
Implementing AuthorizationImplementing Authorization
Implementing AuthorizationTorin Sandall
 
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIsHydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIsMarkus Lanthaler
 
Enforcing Bespoke Policies in Kubernetes
Enforcing Bespoke Policies in KubernetesEnforcing Bespoke Policies in Kubernetes
Enforcing Bespoke Policies in KubernetesTorin Sandall
 
JSON-LD for RESTful services
JSON-LD for RESTful servicesJSON-LD for RESTful services
JSON-LD for RESTful servicesMarkus Lanthaler
 
Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Matt Raible
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practicesAnkita Mahajan
 
Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)Abhishek Koserwal
 
Practical DevSecOps: Fundamentals of Successful Programs
Practical DevSecOps: Fundamentals of Successful ProgramsPractical DevSecOps: Fundamentals of Successful Programs
Practical DevSecOps: Fundamentals of Successful ProgramsMatt Tesauro
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloakGuy Marom
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs RESTGreeceJS
 
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and HailoMicroservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailogjuljo
 
JSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebJSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebGregg Kellogg
 
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan VMware Tanzu
 
Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips confluent
 
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdf
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdfCNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdf
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdfLibbySchulze
 
RedisGraph A Low Latency Graph DB: Pieter Cailliau
RedisGraph A Low Latency Graph DB: Pieter CailliauRedisGraph A Low Latency Graph DB: Pieter Cailliau
RedisGraph A Low Latency Graph DB: Pieter CailliauRedis Labs
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsHostedbyConfluent
 
JSON-LD and MongoDB
JSON-LD and MongoDBJSON-LD and MongoDB
JSON-LD and MongoDBGregg Kellogg
 

Mais procurados (20)

Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)
Istio's mixer  policy enforcement with custom adapters (cloud nativecon 17)Istio's mixer  policy enforcement with custom adapters (cloud nativecon 17)
Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)
 
Kubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy AgentKubernetes Security with Calico and Open Policy Agent
Kubernetes Security with Calico and Open Policy Agent
 
Implementing Authorization
Implementing AuthorizationImplementing Authorization
Implementing Authorization
 
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIsHydra: A Vocabulary for Hypermedia-Driven Web APIs
Hydra: A Vocabulary for Hypermedia-Driven Web APIs
 
Enforcing Bespoke Policies in Kubernetes
Enforcing Bespoke Policies in KubernetesEnforcing Bespoke Policies in Kubernetes
Enforcing Bespoke Policies in Kubernetes
 
JSON-LD for RESTful services
JSON-LD for RESTful servicesJSON-LD for RESTful services
JSON-LD for RESTful services
 
Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022
 
Rest api standards and best practices
Rest api standards and best practicesRest api standards and best practices
Rest api standards and best practices
 
Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)Draft: building secure applications with keycloak (oidc/jwt)
Draft: building secure applications with keycloak (oidc/jwt)
 
Practical DevSecOps: Fundamentals of Successful Programs
Practical DevSecOps: Fundamentals of Successful ProgramsPractical DevSecOps: Fundamentals of Successful Programs
Practical DevSecOps: Fundamentals of Successful Programs
 
Secure your app with keycloak
Secure your app with keycloakSecure your app with keycloak
Secure your app with keycloak
 
GraphQL vs REST
GraphQL vs RESTGraphQL vs REST
GraphQL vs REST
 
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and HailoMicroservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
Microservices Architectures: Become a Unicorn like Netflix, Twitter and Hailo
 
JSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social WebJSON-LD: JSON for the Social Web
JSON-LD: JSON for the Social Web
 
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan
Secure Credential Management with CredHub - DaShaun Carter & Sharath Sahadevan
 
Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips Kafka Security 101 and Real-World Tips
Kafka Security 101 and Real-World Tips
 
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdf
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdfCNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdf
CNCF Online - Data Protection Guardrails using Open Policy Agent (OPA).pdf
 
RedisGraph A Low Latency Graph DB: Pieter Cailliau
RedisGraph A Low Latency Graph DB: Pieter CailliauRedisGraph A Low Latency Graph DB: Pieter Cailliau
RedisGraph A Low Latency Graph DB: Pieter Cailliau
 
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John FallowsEnd-to-end Streaming Between gRPC Services Via Kafka with John Fallows
End-to-end Streaming Between gRPC Services Via Kafka with John Fallows
 
JSON-LD and MongoDB
JSON-LD and MongoDBJSON-LD and MongoDB
JSON-LD and MongoDB
 

Semelhante a Rego Deep Dive

Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastAtlassian
 
2011 august-gdd-mexico-city-rest-json-oauth
2011 august-gdd-mexico-city-rest-json-oauth2011 august-gdd-mexico-city-rest-json-oauth
2011 august-gdd-mexico-city-rest-json-oauthikailan
 
The Open & Social Web - Kings of Code 2009
The Open & Social Web - Kings of Code 2009The Open & Social Web - Kings of Code 2009
The Open & Social Web - Kings of Code 2009Chris Chabot
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreStormpath
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreNate Barbettini
 
Connect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick StreuleConnect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick StreuleAtlassian
 
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)David Rodenas
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4DEVCON
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using DjangoNathan Eror
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for BeginnersJason Davies
 
Dynamic Authorization & Policy Control for Docker Environments
Dynamic Authorization & Policy Control for Docker EnvironmentsDynamic Authorization & Policy Control for Docker Environments
Dynamic Authorization & Policy Control for Docker EnvironmentsTorin Sandall
 
PHP Server side restful API - linkedin
PHP Server side restful API - linkedinPHP Server side restful API - linkedin
PHP Server side restful API - linkedinVĆ© Quang SÆĄn
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSMartin Hochel
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Stamatis Zampetakis
 
Gaelyk: Lightweight Groovy on the Google App Engine
Gaelyk: Lightweight Groovy on the Google App EngineGaelyk: Lightweight Groovy on the Google App Engine
Gaelyk: Lightweight Groovy on the Google App EngineTim Berglund
 
Android Data Binding from zero
Android Data Binding from zeroAndroid Data Binding from zero
Android Data Binding from zeroSeyyed davud hosseiny
 
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelvodQA
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsDylan Jay
 
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...Jitendra Bafna
 

Semelhante a Rego Deep Dive (20)

Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fastHow Bitbucket Pipelines Loads Connect UI Assets Super-fast
How Bitbucket Pipelines Loads Connect UI Assets Super-fast
 
2011 august-gdd-mexico-city-rest-json-oauth
2011 august-gdd-mexico-city-rest-json-oauth2011 august-gdd-mexico-city-rest-json-oauth
2011 august-gdd-mexico-city-rest-json-oauth
 
The Open & Social Web - Kings of Code 2009
The Open & Social Web - Kings of Code 2009The Open & Social Web - Kings of Code 2009
The Open & Social Web - Kings of Code 2009
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
Connect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick StreuleConnect Intergration Patterns: A Case Study - Patrick Streule
Connect Intergration Patterns: A Case Study - Patrick Streule
 
ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)ES3-2020-06 Test Driven Development (TDD)
ES3-2020-06 Test Driven Development (TDD)
 
Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4Python Code Camp for Professionals 4/4
Python Code Camp for Professionals 4/4
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Django for Beginners
Django for BeginnersDjango for Beginners
Django for Beginners
 
Dynamic Authorization & Policy Control for Docker Environments
Dynamic Authorization & Policy Control for Docker EnvironmentsDynamic Authorization & Policy Control for Docker Environments
Dynamic Authorization & Policy Control for Docker Environments
 
PHP Server side restful API - linkedin
PHP Server side restful API - linkedinPHP Server side restful API - linkedin
PHP Server side restful API - linkedin
 
Reactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJSReactive Type safe Webcomponents with skateJS
Reactive Type safe Webcomponents with skateJS
 
Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21Apache Calcite Tutorial - BOSS 21
Apache Calcite Tutorial - BOSS 21
 
Gaelyk: Lightweight Groovy on the Google App Engine
Gaelyk: Lightweight Groovy on the Google App EngineGaelyk: Lightweight Groovy on the Google App Engine
Gaelyk: Lightweight Groovy on the Google App Engine
 
Android Data Binding from zero
Android Data Binding from zeroAndroid Data Binding from zero
Android Data Binding from zero
 
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect ModelComprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
Comprehensive Browser Automation Solution using Groovy, WebDriver & Obect Model
 
Pyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web appsPyramid Lighter/Faster/Better web apps
Pyramid Lighter/Faster/Better web apps
 
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
MuleSoft Surat Live Demonstration Virtual Meetup#5 - Salesforce Composite Con...
 

Último

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 

Último (20)

Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 

Rego Deep Dive

  • 2. openpolicyagent.org OPA: Add fine-grained policy to other projects OPA Cloud Orchestrator Risk Management Linux Container Execution, SSH, sudo OPA Hashicorp Terraform OPA Microservice APIs Istio Linkerd OPA Placement & Admission Control
  • 3. openpolicyagent.org Use OPA to policy-enable your project Integrate Offload policy decisions from your project to OPA Author Write OPA policies that make decisions Manage Deploy OPA, retrieve policy, audit decisions, monitor health 1 2 3
  • 4. Agenda ● How Policies are Invoked ● Simple Policies ● Policies with Iteration ● Additional Topics ○ Modularity ○ Negation ○ Any/All ○ Non-boolean Decisions
  • 5. How Policies are Invoked ● Overview ● Example: ○ HTTP API Authorization
  • 7. openpolicyagent.org How Policies are Invoked DataLogic POST v1/data/<policy-name> {“input”: <JSON>} 1. Decision Request Any JSON value: ● "alice" ● ["api", "v1", "cars"] ● {"headers": {...}}
  • 8. openpolicyagent.org How Policies are Invoked DataLogic 200 OK {“result”: <JSON>} 1. Decision Request 2. Decision Response Any JSON value: ● true, false ● "bob" ● {"servers": ["server-001", 
]} POST v1/data/<policy-name> {“input”: <JSON>} Any JSON value: ● "alice" ● ["api", "v1", "cars"] ● {"headers": {...}}
  • 9. openpolicyagent.org How Policies are Invoked DataLogic 200 OK {“result”: <JSON>} Input is JSON. Policy decision is JSON. 1. Decision Request 2. Decision Response POST v1/data/<policy-name> {“input”: <JSON>} Any JSON value: ● true, false ● "bob" ● {"servers": ["server-001", 
]} Any JSON value: ● "alice" ● ["api", "v1", "cars"] ● {"headers": {...}}
  • 10. openpolicyagent.org Example: HTTP API Authorization DataLogic
  • 11. openpolicyagent.org Example: HTTP API Authorization DataLogic 1. Example Request to OPA POST v1/data/http/authz/allow {"input": { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob"}} 1
  • 12. openpolicyagent.org Example: HTTP API Authorization DataLogic 1. Example Request to OPA 2. Example Policy in OPA POST v1/data/http/authz/allow {"input": { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob"}} package http.authz allow { input.user == “bob” } 1 2
  • 13. openpolicyagent.org Example: HTTP API Authorization DataLogic 1. Example Request to OPA 2. Example Policy in OPA 3. Example Response from OPA POST v1/data/http/authz/allow {"input": { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob"}} package http.authz allow { input.user == “bob” } {“result”: true} 1 2 3
  • 14. Agenda ● How Policies are Invoked ● Simple Policies ● Policies with Iteration ● Additional Topics ○ Modularity ○ Negation ○ Non-boolean Decisions
  • 15. Simple Policies ● Lookup values ● Compare values ● Assign values ● Create rules ● Create functions ● Use context (data)
  • 16. openpolicyagent.org Lookup and Compare Values { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Input input.method input.path[0] Lookup values.
  • 17. openpolicyagent.org Lookup and Compare Values { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Input input.method == “GET” input.path[0] == “finance” input.user != input.method Lookup values. Compare values.
  • 18. openpolicyagent.org Lookup and Compare Values { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Input input.method == “GET” input.path[0] == “finance” input.user != input.method startswith(input.path[1], “sal”) count(input.path) > 2 Lookup values. Compare values. See 50+ operators documented at openpolicyagent.org/docs/language-reference.html
  • 19. openpolicyagent.org path := input.path path[2] == "alice" Assign Values to Variables { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Input Assign variables. Use variables like input.
  • 20. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow = true { input.method == "GET" input.user == "bob" }
  • 21. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow = true { input.method == "GET" input.user == "bob" } Rule Head
  • 22. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow = true { input.method == "GET" input.user == "bob" } Rule Head Name allow Value true
  • 23. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow { input.method == "GET" input.user == "bob" } Rule Head Name allow Value true
  • 24. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow { input.method == "GET" input.user == "bob" } Rule Body
  • 25. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow { input.method == "GET" input.user == "bob" } Rule Body Multiple statements in rule body are ANDed together.
  • 26. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Rules have a Head and a Body. allow { input.method == "GET" input.user == "bob" } Rule Body Multiple statements in rule body are ANDed together. allow is true IF input.method equals "GET" AND input.user equals "bob"
  • 27. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Multiple rules with same name. allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] }
  • 28. openpolicyagent.org Input Create Rules { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Multiple rules with same name. allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] }Rule Head Multiple statements with same head are ORed together.
  • 29. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Rules can be undefined. allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] }
  • 30. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Rules can be undefined. allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] } Different method. "POST" instead of "GET"
  • 31. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Rules can be undefined. allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] } Different method. "POST" instead of "GET" Neither rule matches. allow is undefined (not false!)
  • 32. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Use default keyword. default allow = false allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] }
  • 33. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Use default keyword. default allow = false allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] } default <name> = <value> If no rules match default value is returned.
  • 34. openpolicyagent.org Create Rules Input { "method": "POST", "path": ["finance", "salary", "alice"], "user": "bob" } Use default keyword. default allow = false allow { input.method == "GET" input.user == "bob" } allow { input.method == "GET" input.user == input.path[2] } default <name> = <value> If no rules match default value is returned. at most one default per rule set
  • 35. openpolicyagent.org Create Functions Input { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Path is a string now.
  • 36. openpolicyagent.org Create Functions Input { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Example rule default allow = false allow { trimmed := trim(input.path, "/") path := split(trimmed, "/") path = ["finance", "salary", user] input.user == user } Path is a string now.
  • 37. openpolicyagent.org { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Create Functions Input Example rule default allow = false allow { trimmed := trim(input.path, "/") path := split(trimmed, "/") path = ["finance", "salary", user] input.user == user } Path is a string now. Avoid duplicating common logic like string manipulation
  • 38. openpolicyagent.org { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Create Functions Input Put common logic into functions default allow = false allow { path := split_path(input.path) path = ["finance", "salary", user] input.user == user } split_path(str) = parts { trimmed := trim(str, "/") parts := split(trimmed, "/") } Path is a string now. Avoid duplicating common logic like string manipulation
  • 39. openpolicyagent.org { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Create Functions Input Functions are Rules with arguments. read_method(str) = true { str == "GET" } read_method(str) = true { str == "HEAD" }
  • 40. openpolicyagent.org { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Create Functions Input Functions are Rules with arguments. read_method(str) = true { str == "GET" } read_method(str) = true { str == "HEAD" } "Function" Head Multiple statements with same head are ORed together.
  • 41. openpolicyagent.org { "method": "GET", "path": "/finance/salary/alice", "user": "bob" } Create Functions Input Functions are Rules with arguments. read_method(str) { str == "GET" } read_method(str) { str == "HEAD" } "Function" Head Multiple statements with same head are ORed together.
  • 42. openpolicyagent.org Policies can use Context from Outside World PUT v1/data/<path> HTTP/1.1 Content-Type: application/json <JSON> Load Context/Data Into OPA DataLogic
  • 43. openpolicyagent.org { "users": { "alice": {"department": "legal"}, "bob": {"department": "hr"}, "janet": {"department": "r&d"} } } { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob" } Policies Use Context Data (context) Policy allow { # Users can access their own salary input.user == input.path[2] } allow { # HR can access any salary user := data.users[input.user] user.department == "hr" } Input
  • 44. openpolicyagent.org Summary Lookup values input.path[1] Compare values "bob" == input.user Assign values user := input.user Rules <head> { <body> } Rule Head <name> = <value> { 
 } or <name> { 
 } Rule Body <statement-1>; <statement-2>; 
 (ANDed) Multiple Rules with same name <rule-1> OR <rule-2> OR ... Default Rule Value default <name> = <value> Functions Rules with arguments Context Reference with data. instead of input.
  • 45. Agenda ● How Policies are Invoked ● Simple Policies ● Policies with Iteration ● Additional Topics ○ Modularity ○ Negation ○ Any/All ○ Non-boolean Decisions
  • 46. Policies With Iteration ● Iteration ● Virtual documents ● Virtual documents vs Functions
  • 47. openpolicyagent.org { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ... ], ... } # allow if resource is at element 0 allow { input.resource == data.resources[0].id input.user == data.resources[0].owner } What about Arrays? Allow if user owns resource. Not sure where resource is in array { "user": "alice" "resource": "54cf10", } Input Data
  • 48. openpolicyagent.org { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ... ], ... } # allow if resource is at element 0 allow { input.resource == data.resources[0].id input.user == data.resources[0].owner } # OR if resource is at element 1 allow { input.resource == data.resources[1].id input.user == data.resources[1].owner } What about Arrays? Allow if user owns resource. Not sure where resource is in array { "user": "alice" "resource": "54cf10", } Input Data
  • 49. openpolicyagent.org { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ... ], ... } # allow if resource is at element 0 allow { input.resource == data.resources[0].id input.user == data.resources[0].owner } # OR if resource is at element 1 allow { input.resource == data.resources[1].id input.user == data.resources[1].owner } ... What about Arrays? Allow if user owns resource. Not sure where resource is in array { "user": "alice" "resource": "54cf10", } Input Data Problem: Unknown number of elements. Cannot write allow for every index.
  • 50. openpolicyagent.org { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ... ], ... } # allow if resource is anywhere in array allow { input.resource == data.resources[index].id input.user == data.resources[index].owner } Iterate over Arrays Allow if user owns resource. Not sure where resource is in array { "user": "alice" "resource": "54cf10", } Input Data
  • 51. openpolicyagent.org { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ... ], ... } # allow if resource is anywhere in array allow { input.resource == data.resources[index].id input.user == data.resources[index].owner } Iterate over Arrays Allow if user owns resource. Not sure where resource is in array { "user": "alice" "resource": "54cf10", } Input Data Solution: ● allow is true if SOME value for index makes the rule body true. ● OPA automatically iterates over values for index. ● allow is true for index = 0
  • 52. openpolicyagent.org Iterate over Everything Iterate over arrays/dictionaries (whether input or data) # Iterate over array indexes/values resource_obj := data.resources[index] # Iterate over dictionary key/values user_obj := data.users[name] # Doesn’t matter whether input or data value := input[key] # Use _ to ignore variable name # Iterate over just the array values resource_obj := data.resources[_] { "method": "GET", "path": ["resources", "54cf10"], "user": "bob" } Input { "resources": [ {"id": "54cf10", "owner": "alice"}, {"id": "3df429": "owner": "bob"} ], "users": { "alice": {"admin": false}, "bob": {"admin": true}, "charlie": {"admin": true}, } } Data
  • 53. openpolicyagent.org Duplicated Logic Happens with Iteration too { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } Data allow { user := data.users[_] user.admin == true user.name == input.user input.method == “GET” } allow { user := data.users[_] user.admin == true user.name == input.user input.method == “POST” } Duplicated logic with iteration
  • 54. openpolicyagent.org Duplicated Logic Happens with Iteration too { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } Data allow { user := data.users[_] user.admin == true user.name == input.user input.method == “GET” } allow { user := data.users[_] user.admin == true user.name == input.user input.method == “POST” } Duplicated logic with iteration Avoid duplicating common logic like a search for admins
  • 55. openpolicyagent.org Create a Virtual Document { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } Data allow { admin[input.user] input.method == “GET” } allow { admin[input.user] input.method == “POST” } admin[user.name] { user := data.users[_] user.admin == true } Duplicated logic with iteration admin is a set that contains all of the admin names Sets are an extension of JSON. admin == { "bob", "charlie" }
  • 56. openpolicyagent.org Different Syntaxes for Virtual Sets { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } admin[user.name] { user := data.users[_] user.admin == true } Data Rule Syntax admin = {user.name | user := data.users[_] user.admin == true } Set Comprehension Syntax
  • 57. openpolicyagent.org Different Syntaxes for Virtual Sets { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } admin[user.name] { user := data.users[_] user.admin == true } Data Rule Syntax admin = {user.name | user := data.users[_] user.admin == true } Set Comprehension Syntax Supports OR with multiple rules. No support for OR.
  • 58. openpolicyagent.org Create Virtual Dictionaries too { “users”: [ {"name": "alice", "admin": false, “dept”: “eng”}, {"name": "bob", "admin": true, “dept”: “hr”}, {"name": "charlie", "admin": true, “dept”: “eng”}, } } Data admin[user.name] = user.dept { user := data.users[_] user.admin == true } Rule Syntax admin = {user.name: user.dept | user := data.users[_] user.admin == true } Dictionary Comprehension Syntax
  • 59. openpolicyagent.org Virtual Docs support iteration. Functions don’t. admin[user_name] = user.dept { user := data.users[_] user.admin == true user.name == user_name } admin(user_name) = user.dept { user := data.users[_] user.admin == true user.name == user_name } Dictionary Function # lookup bob’s department admin[“bob”] # iterate over all user/dept pairs admin[user] = department # iterate over everyone in HR admin[user] == “hr” # lookup bob’s department admin(“bob”) # iterate over all user/dept pairs Can’t. Write different function. # iterate over everyone in HR Can’t.
  • 60. openpolicyagent.org Virtual Documents must be finite. Functions don’t. Can’t express split_path. Virtual docs must be “safe”. Safety means the set of all input/output pairs is finite. split_path takes any string as input. There are infinitely strings. split_path(str) = parts { trimmed := trim(str, "/") parts := split(trimmed, "/") } Virtual Doc Function
  • 61. Agenda ● How Policies are Invoked ● Simple Policies ● Policies with Iteration ● Additional Topics ○ Modularity ○ Negation ○ Any/All ○ Non-boolean Decisions
  • 62. openpolicyagent.org People can Create Multiple Policies and Delegate package http.service_graph allow { input.source == “frontend” input.destination == “finance” } ... Service graph policy package http.org_chart allow { admin[user.input] } ... Organization chart policy package http.authz import data.http.service_graph import data.http.org_chart allow { org_chart.allow service_graph.allow } Entry point policy
  • 63. openpolicyagent.org Policies can use Negation package http.service_graph deny { input.source == “frontend” input.destination == “finance” } ... Service graph policy package http.org_chart allow { admin[user.input] } Organization chart policy package http.authz import data.http.service_graph import data.http.org_chart allow { org_chart.allow not service_graph.deny not deny } deny { ... } Entry point policy
  • 64. openpolicyagent.org { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} } } Any vs. All Data Check if all users are admins. Wrong ans: all_admins = true { data.users[user_name].admin == true }
  • 65. openpolicyagent.org { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} } } Any vs. All Data Check if all users are admins. Wrong ans: all_admins = true { data.users[user_name].admin == true } Problem: all_admins is true if ANY users are admins.
  • 66. openpolicyagent.org { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} } } Any vs. All Data Check if all users are admins. all_admins = true { not any_non_admins } any_non_admins = true { user := data.users[user_name] not user.admin } Solution: 1. Check if any users are NOT admins 2. Complement (1)
  • 67. openpolicyagent.org { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} } } Any vs. All Data Check if all users are admins. all_admins = true { not any_non_admins } any_non_admins = true { user := data.users[user_name] not user.admin } Solution: 1. Check if any users are NOT admins 2. Complement (1)
  • 68. openpolicyagent.org allow/deny are NOT special. Decisions are JSON DataLogic POST v1/data/http/authz/admin {"input": { "method": "GET", "path": ["finance", "salary", "alice"], "user": "bob"}} 2. Example Policy 1. Example Request 3. Example Response {“result”: [“bob”, “charlie”]} package http.authz import data.http.service_graph import data.http.org_chart admin[x] { org_chart.admin[x] } admin[x] { service_graph.admin[x] } Sets defined with multiple rules are unioned together. Policy decision can be any JSON data: boolean, number, string, null, array, or dictionary. Sets are serialized to JSON arrays.
  • 71. openpolicyagent.org Policies Iterate to Search for Data { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} }, “orgs”: { “00”: {“name”: “HR”}, “11”: {“name”: “Legal”}, “22”: {“name”: “Research”}, “33”: {“name”: “IT”}, “44”: {“name”: “Accounting”}, } } Data Search for the data you need user_obj user_name org_name {"admin": true, ...} bob Research {"admin": true, ...} charlie IT # Find admin users and their organization user_obj := data.users[user_name]; user_obj.admin == true; org_name := data.orgs[user_obj.org_code].name Variable assignments that satisfy search criteria
  • 72. openpolicyagent.org Policies Give Names to Search Results Data Name the search results admins[[org_name, user_name]] { user_obj := data.users[user_name] user_obj.admin == true org_name := data.orgs[user_obj.org_code].name } { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} }, “orgs”: { “00”: {“name”: “HR”}, “11”: {“name”: “Legal”}, “22”: {“name”: “Research”}, “33”: {“name”: “IT”}, “44”: {“name”: “Accounting”}, } } admins is a set that contains all of the [org_name, user_name] pairs that make the body true. admins == { ["Research", "bob"], ["IT", "charlie"], }
  • 73. openpolicyagent.org Policies Apply Search Results to Make Decisions Input { “users”: { "alice": {"admin": false, “org_code”: “11”}, "bob": {"admin": true, “org_code”: “22”}, "charlie": {"admin": true, “org_code”: “33”} }, “orgs”: { “00”: {“name”: “HR”}, “11”: {“name”: “Legal”}, “22”: {“name”: “Research”}, ... Apply the search results allow { # allow admins to do everything admins[[_, input.user]] } admins[[org_name, user_name]] { user_obj := data.users[user_name] user_obj.admin == true org_name := data.orgs[user_obj.org_code].name } Check if bob is an admin Lookup IT admins Iterate over all pairs admins[[_, “bob”]] admins[[“IT”, name]] admins[x] { "method": "GET", "path": ["resources", "54cf10"], "user": "bob" } Data