Hello, I was wondering If someone might be able to...
# permit-saas
c
Hello, I was wondering If someone might be able to help with an issue I’m having. The documentation calls out that you should be able to create an ABAC Dynamic Role which looks at an attribute which is set on a resource. docs.permit.io/how-to/build-policies/abac/patterns?…#… This doesn’t seem to work, there are no Resource ABAC attributes appearing in the dropdown, contrary to what the docs says “Create a user set with the condition
user.owned_files
array contains (ref)
resource.id
.” Could you please advise? Kind regards, Chris
a
Hi @Christie Molloy, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
Hi Chris, the pattern in the docs depends on resource attributes existing before they can be referenced in a condition. The steps for the "ownership via list on user profile" pattern are: 1. Add an array attribute to the user, for example
owned_files
, and store the keys of the resources the user owns. 2. Add an attribute to the resource, for example
id
, that your application fills with the key of the resource it checks. 3. Create a user set with the condition
user.owned_files
array contains (ref)
resource.id
. 4. Grant the user set its actions in the Policy Editor.(1) Step 2 is the likely cause of the empty dropdown. The
resource.id
option only appears if you've defined an attribute named
id
on the resource type (for example
file
) in the resource's attribute settings. Resource attributes are defined on the resource itself, so check that: • The attribute is created on the right resource (the one your check uses as
type
). • The
user.owned_files
attribute is an array type, since the
array contains (ref)
operator applies to arrays. Once both attributes exist, the check passes the values like this:
Copy code
const permitted = await permit.check(  
 {  
 key: "john@permit.io",  
 attributes: { owned_files: ["readme", "budget"] },  
 },  
 "read",  
 {  
 type: "file",  
 attributes: { id: "readme" },  
 }  
);
(1) Also note that ABAC checks require a container PDP (for example at `http://localhost:7766`), because the Cloud PDP doesn't evaluate ABAC policies.(1) If the
id
attribute exists on the resource and it still doesn't appear in the dropdown, I'd like our engineers to investigate. Please share: 1. Which Workspace / Project / Env you are using 2. What calls you are performing (as SDK code or CURL) 3. Which PDP version you are running 4. Relevant logs from your PDP
To learn more, see the sources I considered: [[1] ABAC Design Patterns](https://docs.permit.io/how-to/build-policies/abac/patterns)
c
I have added an attribute to a resource
d
Hi @Christie Molloy, which project/env are you working on? Can you explain what you would like to achieve so I can point you in the right direction?
c
Hi, it’s Proj: VIOCore, Env: Staging. I’m trying to assert ownership via a list on a user’s attributes, but the resource ID needs to be passed through at time-of-check. I also can’t / don’t want to use resources instances because they are scoped to tenants.
d
You can do this with plain attributes, no resource instances needed (so no tenant scoping issue): 1. User Attributes - _Add Attribute_: create an attribute of type
array
(e.g.
owned_files
) and store the IDs of the resources each user owns. 2. Policy Editor - _Resources_: expand the resource type your check uses and add an attribute
id
. 3. Create a User Set with the condition
user.owned_files
→
array contains (ref)
-
resource.id
. The resource attribute shows up in the value field once you pick the
(ref)
operator, not in the left-hand dropdown. 4. Grant the user set its actions in the Policy Editor. 5. In
permit.check()
, pass the ID on the resource:
attributes: { id: "<resource id>" }
, and send the check to a container PDP (the Cloud PDP doesn’t evaluate ABAC). Note that a user set matches in every tenant, so add tenant conditions if you need to limit it. If it still doesn’t work, which user attribute and which resource type (and its attribute name) are you using? I’ll check them in Staging.
c
Sure, that is what I have been trying to do. But the resource attribute does not appear in the dropdown. User Set called “UserScopeJurisdiction (user_scope_jurisdiction)” should have the following condiction, user.scope_jurisdictions array_contains (ref) resource.businessKey
the resource is “jurisdiction”
d
I can reproduce this in VIOCore / Staging.
businessKey
on
jurisdictions
is set up correctly (string), but the User Set builder only lists user attributes in both dropdowns, so resource attributes can’t be picked from the list. You are correct this doesn’t match the docs, and we will fix this. Two ways to get unblocked in the meantime: 1. In the User Set, choose
user.scope_jurisdictions
→
array contains (ref)
, then type
resource.businessKey
directly into the value field (it accepts typed text) and save. 2. If that doesn’t save or evaluate correctly, create the set through the API:
Copy code
{
  "key": "user_scope_jurisdiction",
  "name": "UserScopeJurisdiction",
  "type": "userset",
  "conditions": {
    "allOf": [
      { "user.scope_jurisdictions": { "array_contains": { "ref": "resource.businessKey" } } }
    ]
c
This seems to have worked, thank you!
🚀 1