I’m trying to figure out a clean way to model B2B ...
# permit-saas
s
I’m trying to figure out a clean way to model B2B type scenarios where the Tenants I create in Permit can group their Resources under an Account resource and manage roles on that via Groups. I was hoping to avoid syncing all my relationships into Permit and using JIT ABAC checks with the Account key for any of the Account’s resources as I have the Account key readily available for all resources in my app. It feels like I’m missing something obvious, but after reading through all the docs on ABAC and ReBAC it’s still not clicking. Any pointers?
a
Hi @Sam Jakos, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
You're on the right track thinking about Groups and Account resources. Permit's Groups API is designed for exactly this B2B scenario where you want to manage permissions at an account level without syncing all relationships (1) . Here's how you can model this cleanly: Using Groups for Account-Level Management The Groups API allows you to create groups that represent your Account resources, then assign both users and resource instances to these groups . When you assign roles to a group, they automatically cascade to group members through role derivation . For example, you can create an account group and assign resources to it:
Copy code
curl '<https://api.permit.io/v2/schema/{project_id}/{env_id}/groups>' \
  -H 'authorization: Bearer API_SECRET_KEY' \
  --data-raw '{"group_instance_key": "account-123", "group_resource_type_key": "accounts", "group_tenant": "default"}'
Then assign users to that account group with roles:
Copy code
curl -X PUT \
'<https://api.permit.io/v2/schema/{project_id}/{env_id}/groups/{group_resource_type_key}/users/{user_id}>' \
  -H 'authorization: Bearer API_SECRET_KEY' \
  --data-raw '{"tenant":"business"}'
JIT Checks with Account Context For your JIT ABAC approach, you can pass the Account key as an attribute during your permission checks. Since you have the Account key readily available, you can include it in the resource attributes:
Copy code
const isAuthorized = await permit.check(
  {
    key: "user-id",
    attributes: {
      // user attributes
    }
  },
  "action",
  {
    type: "resource-type",
    attributes: {
      account: "account-123"  // Your Account key
    }
  }
) ;
(2) Automated Role Derivation The Groups API automatically creates role derivations (1) . When you assign a role to a group, it creates: • A role derivation from the group member role to resource roles • Relations between the group and resources • Automatic permission inheritance for new members added to the group This means you don't need to sync all individual relationships - just the group memberships and the Account association. Alternative: Resource Instance Approach You could also model the Account as a resource with resource instances, then use resource instance roles (3) :
Copy code
await permit.api.roleAssignments.assign({
  role: "AccountAdmin",
  tenant: "default",
  resource_instance: `Account:${accountId}`,
  user: "user-id"
}) ;
This gives you account-level role assignments without needing to sync all child resource relationships. The key insight is that Groups handle the relationship management for you, while ABAC attributes let you pass the Account context at check time without pre-syncing everything.
To learn more, see the sources I considered: [[1] Groups API](https://docs.permit.io/api/rebac/groups) [[2] Fine-Grained Keycloak Authorization with ABAC and ReBAC](https://www.permit.io/blog/fine-grained-keycloak-authorization-with-abac-and-rebac) [[3] Fintech / Banking Demo Application](https://docs.permit.io/modeling/mesa-verde)
a
Hey @Sam Jakos , does the AI’s answer make sense ?
s
I think so. I missed that you can use the groups API to group resources when I was reading through the docs. I’ll give this a shot.
o
Adding a little more 1. Groups are coming to the UI this month 2. Note that groups are still ReBAC under the hood. You can model groups with ABAC without saving the data with Permit, like in this ownership example, note this is better when you don't have levels of nesting
s
Groups in the UI will be great. The ability to start layering in ReBAC is one of the biggest wins for me with Permit.
💜 1
I’m just trying avoid syncing all my application state needlessly right now.
ack 1
m
@Or Weis How is the work on the group UI going? 🙂
a
Hey @Michał Wójcik, The Groups feature is in development, and we’re waiting on a confirmed timeline. I’ve asked the team for an update and will share an ETA once it’s available.