<@U08614ZV82F> any examples of people using ReBAC ...
# permit-saas
a
@Ask Inkeep any examples of people using ReBAC to enable public link sharing? Similar to Google docs: • I want to be able to share a public link to a resource. • Anyone who visits the URL should be able to read the associated resources. (regardless of whether they are even logged in / authenticated) • Any authenticated user should be able to comment • Users with permissions on the resource can do more restricted things I'd like to keep using permit for these cases to hopefully get an audit log of unauthenticated visits as well as be able to link authenticated users back to docs they viewed / commented on
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
While the Permit.io documentation includes examples of Google Drive-style permissions with ReBAC, the specific public link sharing scenario you describe isn't directly covered in the available sources. The Google Drive examples demonstrate (1) : • Direct file access where users can be viewers, commenters, or editors • Folder-level access that cascades to files within • Account admin access providing highest permissions • "General access to 'Everyone in account'" for sharing files with all account members However, these examples require authenticated users with assigned roles . The documentation shows creating users like:
Copy code
await permit.api.sync_user(
    {
        "key": "<mailto:john@acme.com|john@acme.com>",
    }
)
And assigning them roles on resources:
Copy code
await permit.api.role_assignments.assign(
    {
        "user": "<mailto:john@acme.com|john@acme.com>",
        "role": "viewer",
        "resource_instance": "file:2023_report",
    }
)
For audit logging, Permit.io does provide comprehensive audit logs that capture (2) : • Timestamp of attempted actions • User/machine who attempted the action • Description of the attempted action • The resource targeted • Authorization decision (Permitted or Denied) • Reasoning behind the authorization decision To implement true public link sharing with unauthenticated access while maintaining audit logs, you'd likely need to create a special "anonymous" user entity or extend the current model. The sources don't provide a specific example of this pattern. Would you like me to provide a general approach based on authorization patterns, or would you prefer to reach out to Permit.io support at Email for guidance on implementing this specific use case?
To learn more, see the sources I considered: [[1] Modeling Google Drive Permissions with ReBAC](https://docs.permit.io/modeling/google-drive) [[2] Best Practices for Authorization Audit Logs](https://www.permit.io/blog/audit-logs)
a
@Ask Inkeep I have been experimenting with trying to create a resource / resource group / user group that would cover this case and so far haven't found a great solution. For example, i tried creating ABAC Dynamic Role (User Sets) for both "authenticated" and "unauthenticated" where the code would just pass in a string "unauthenticated" for the user key in those cases and the actual user's ID in cases where they are authenticated but may not have higher access. Meanwhile I assigned ABAC Dynamic Resource (Resource Sets) to the "Task" resource that needs to be shared such that if an attribute is set, it will be in the resource set public_review. Then I granted view access to both of the user sets for this resource set. Still didn't seem to work
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
Your approach with ABAC User Sets and Resource Sets is on the right track. Let me help debug this based on the documentation. When creating User Sets (Dynamic Roles) , they need conditions that evaluate against user attributes (1) . For example:
Copy code
{
  "allOf": [
    {
      "user.university": {
        "equals": "Stanford"
      }
    },
    {
      "user.is_full_time": true
    }
  ]
}
The key issue might be in how you're passing attributes during the check. According to the documentation, you need to pass user attributes in the permit.check call (2) :
Copy code
const permitted = await permit.check(
  {
    key: user,
    attributes: { strongAuth: !!OTP, location },
  },
  "create",
  {
    type: "Transaction",
    attributes: { ...transaction },
    tenant,
  }
) ;
(3) For your public sharing scenario, ensure you're: 1. ​*Passing the correct attributes in the check call*​ - The "unauthenticated" user needs attributes that match your User Set conditions (1) 2. ​*Including resource attributes*​ - Your Resource Set conditions need to match attributes passed in the resource object:
Copy code
const permitted = await permit.check(userKey, "read", {
  type: "file",
  attributes: {
    owners: [
      "d08c85a349994aeb89a3f02c08bdb340",
      "48fb889360604253a5189580b48694cf",
    ],
  },
}) ;
(4) 3. ​*Verifying the condition syntax*​ - Resource Set conditions should look like:
Copy code
{
  "allOf": [
    {
      "resource.amount": {
        "less-than-equals": 1000
      }
    }
  ]
}
(3) To help debug further, could you share: 1. Which Workspace / Project / Env you're using 2. The exact SDK calls you're making (as code or CURL) 3. Which PDP version you're running 4. Any relevant logs from your PDP This will help identify why the permissions aren't being granted as expected.
To learn more, see the sources I considered: [[1] Building Your First ABAC Policy](https://docs.permit.io/how-to/build-policies/abac/building-abac-policy) [[2] Defining Attributes](https://docs.permit.io/how-to/build-policies/abac/defining-attributes) [[3] Fintech / Banking Demo Application](https://docs.permit.io/modeling/mesa-verde) [[4] ABAC Design Patterns](https://docs.permit.io/how-to/build-policies/abac/patterns)
a
Looks like my weak link is the ABAC Dynamic Resource (Resource Sets) Not sure what is going on. I have a resource Task, that has an attribute privacy_status. I set up the ABAC so that when resource.privacy_status equals 'public_review', it should be part of the group 'public_review' I set this attribute on the task instance and when I try to access it, it seems to only look at the task checks, not the public_review checks
@Ask Inkeep ☝️
a
Thanks for tagging me @Abe Clark. I'll look through relevant sources and get back to you shortly.
Based on your description, the issue is likely with how resource attributes are being passed during the check. When using ABAC with Resource Sets, you need to pass the resource attributes in your permit.check call (1) . Here's how the check should look:
Copy code
permitted = await permit.check(
    # User with attributes
    {
        "key": "<mailto:check@permit.io|check@permit.io>",
        "attributes": {
            "location": "England",
            "department": "Engineering",
        },
    },
    # Action
    "action",
    # Resource with attributes
    {
        "type": "resource",
        "attributes": {
            "hasApproval": "true",
        },
        "tenant": "tenant",
    }
)
For your Task resource with
privacy_status
attribute, the check should include:
Copy code
permitted = await permit.check(
    # the user object
    {
        # the user key
        "key": "<mailto:check@permit.io|check@permit.io>",
        # just-in-time attributes on the user
        "attributes": {
            "location": "England",
            "department": "Engineering",
        },
    },
    # the action the user is trying to do
    "action",
    # Resource
    {
        # the type of the resource (the resource key)
        "type": "resource",
        # just-in-time attributes on the resource
        "attributes": {
            "hasApproval": "true",
        },
        # the tenant the resource belong to
        "tenant": "tenant",
    }
)
The key point is that resource attributes must be passed at check time as "just-in-time attributes" . These attributes are merged with (and override) any persisted resource attributes . To help debug this further, could you provide: 1. Which Workspace / Project / Env you're using 2. What calls you're performing (as SDK code or CURL) 3. Which PDP version you're running 4. Relevant logs from your PDP This will help our engineers investigate why the Resource Set conditions aren't being evaluated correctly.
To learn more, see the sources I considered: [[1] Running a demo](https://docs.permit.io/overview/connecting-your-app)
a
Bingo -- needed to pass the attribute at check time. Kinda strange that is the case 🤔 I'd think you would be able to sync those attributes and then check based on the cached value. But 👍
o
You can either pass the attribute at check time, load it in via OPAL, save it on a resource instance
a
gotcha -- I don't think the resource instance was working. This is what happens when you save the attributes in the GUI to the resource instance I assume. Coudln't get it to work that way, but worked when I passed in directly
p
Hey, thanks for reaching out ! It seems our team is a little busy right now, a human will be with you within the next hour or so. In the meantime, can I help you ?