Slackbot
06/21/2023, 3:28 PMOr Weis
06/21/2023, 3:39 PMDoug Ramirez
06/21/2023, 3:43 PMwhen
clause that filters on a list of identifiers that have been loaded into OPA. What's the syntax for referencing that list?Doug Ramirez
06/21/2023, 3:44 PMpermit(
principal in Role::"sales",
action in Action::"create",
resource
)
when {
(resource.name == "rate_codes" ||
resource.name == "rate_models" ||
resource.name == "campaign" ||
resource.name == "mailer")
};
I'd like to load that list of names into OPA, rather than hard-coding them in the rule.Or Weis
06/21/2023, 3:45 PMOr Weis
06/21/2023, 3:45 PMDoug Ramirez
06/21/2023, 3:45 PMwhen {
resource.name in [some_array_in_OPA]
};
Or Weis
06/21/2023, 3:46 PMI’d like to load that list of names into OPA, rather than hard-coding them in the rule.Are we talking OPA or Cedar ? those are of course not the same
Doug Ramirez
06/21/2023, 3:47 PMOr Weis
06/21/2023, 3:48 PMDoug Ramirez
06/21/2023, 3:50 PMpermitio/opal-server:latest
and permitio/opal-client-cedar:latest
and I can send requests to the /v1/is_authorized
endpoint for decisions. And, I can send context
to the endpoint, but I would like to move that fetch of context to Cedar.
Does that make sense?Or Weis
06/21/2023, 3:51 PMDoug Ramirez
06/21/2023, 3:51 PM{
"principal": "Role::\"sales\"",
"action": "Action::\"read\"",
"resource": "Resource::\"rate_codes\"",
"context": {
"id": "abc123",
"ids": [
"abc123",
"xyz456"
]
}
}
But, I'd prefer to only send the id
and have Cedar(?) have a cache of the ids
.Doug Ramirez
06/21/2023, 3:52 PMOr Weis
06/21/2023, 3:52 PMDoug Ramirez
06/21/2023, 3:55 PMpermit(
principal in Role::"sales",
action in [Action::"read", Action::"update", Action::"delete"],
resource
)
when {
context.ids.contains(context.id)
};
How would I write the policy to reference that data (array) in the above use case, instead of the list that's passed in via context?Doug Ramirez
06/21/2023, 3:56 PMOr Weis
06/21/2023, 3:56 PMDoug Ramirez
06/21/2023, 3:56 PMOr Weis
06/21/2023, 3:59 PMDoug Ramirez
06/21/2023, 4:01 PMOmer Zuarets
06/21/2023, 4:08 PM{
"uid": {
"type": "User",
"id": "alice"
},
"attrs": {
"age": 25,
"name": "alice",
"userId": "897345789237492878"
},
"parents": []
}
and your authorization query is on User::alice
, then the principal
will have the attributes from the data and you’ll be able to perform principal.age > 20
inside the when block ( same goes for action and resource ), context is a bit different, you provide the data inside the request and you can simply enforce conditions on itOmer Zuarets
06/21/2023, 4:12 PMDoug Ramirez
06/21/2023, 4:14 PMDoug Ramirez
06/21/2023, 4:15 PMDoug Ramirez
06/21/2023, 4:15 PM{
"uid": {
"type": "User",
"id": "alice"
},
"attrs": {
"age": 25,
"name": "alice",
"userId": "897345789237492878",
"account_numbers": [
"abc",
"def"
]
},
"parents": []
}
Omer Zuarets
06/21/2023, 4:18 PMUser::"alice"
has the parents Account::"abc"
and Account::"def"
, and by doing this you can perform the condition principal in Account::"abc"
Doug Ramirez
06/21/2023, 4:19 PMOmer Zuarets
06/21/2023, 4:21 PMDoug Ramirez
06/21/2023, 6:46 PMallowed
key only has a single value.
{
"attrs": {
"allowed": "mailer"
},
"parents": [],
"uid": {
"id": "admin",
"type": "Role"
}
},
permit(
principal in Role::"admin",
action in [Action::"export"],
resource
)
when {
resource.name == principal.allowed
};
However, if I try to add a list of resources to the admin role this error gets raised:
{
"attrs": {
"allowed": [
"mailer",
"rate_analysis"
]
},
"parents": [],
"uid": {
"id": "admin",
"type": "Role"
}
},
permit(
principal in Role::"admin",
action in [Action::"export"],
resource
)
when {
resource.name in principal.allowed
};
{
"decision": "Deny",
"diagnostics": {
"reason": [],
"errors": [
"while evaluating policy admin_0.cedar, encountered the following error: type error: expected (entity of type any_entity_type), got string"
]
}
}
I'm loading data into OPA via a data.json file. And, I'm wondering what syntax mistake I'm making.Omer Zuarets
06/21/2023, 7:00 PM