also question regarding 'default' tenants. shouldn...
# permit-saas
e
also question regarding 'default' tenants. shouldn't leaving out tenant (for other api endpoints for examples) default to
default
tenant? i'm noticing that in some of my other apis, when I withold tenant,it doesn't append anything to the 'default' tenant only my other one created. Do I always have to enforce
default
tenant at all times if I only want one?
a
Hi @Engineering Swantide, I'm an AI assistant for Permit.io. I'll analyze available sources and get back to you shortly.
You're right to expect that behavior! The Java SDK configuration shows that there's a
defaultTenant
setting that defaults to
"default"
and a
useDefaultTenantIfEmpty
flag that defaults to
true
(1) .
Copy code
// multi tenancy config
private String defaultTenant = "default";
private Boolean useDefaultTenantIfEmpty = true;
The PermitConfig documentation explains that
getDefaultTenant()
returns "the key of the default tenant used for permission checks if a tenant is not specified (or known) for the resource provided to permit.check() " and
shouldUseDefaultTenantIfEmpty()
returns "whether the default tenant should be used if the resource tenant is not specified" . This means when you don't specify a tenant in your API calls, it should automatically use the "default" tenant. If you're seeing users being created without tenant assignments when you omit the tenant parameter, this might be unexpected behavior. To ensure users are always assigned to the default tenant, you have a couple of options: 1. Explicitly include the tenant in your API calls - for example, when creating or syncing users, include
"tenant": "default"
(2) 2. Include role assignments during user creation with the tenant specified :
Copy code
role_assignments: [{ role: "manager", tenant: "default" }];
If you're experiencing different behavior where omitting the tenant doesn't default to "default", this could be a configuration issue or potentially a bug in your implementation.
To learn more, see the sources I considered: [[1] permitio/permit-java/src/main/java/io/permit/sdk/PermitConfig.java](https://github.com/permitio/permit-java/blob/master/src/main/java/io/permit/sdk/PermitConfig.java) [[2] Sync your First User](https://docs.permit.io/overview/sync-your-first-user-with-sdk)
e
regarding
node
sdk
a
Appreciate the feedback! Feel free to ask me again with additional guidance or context.
o
@Ask Inkeep please check for the inconsistency around the node.js SDK
a
Thanks for tagging me @Or Weis. I'll look through relevant sources and get back to you shortly.
Looking at the Node.js SDK, there is indeed a configuration for default tenant behavior. In the enforcer code, the
normalizeResource
method shows how the SDK handles empty tenants (1) :
Copy code
private normalizeResource(resource: IResource) : IResource {
  const normalizedResource: IResource = Object.assign({}, resource) ;

  // if tenant is empty, we might auto-set the default tenant according to config
  if (!normalizedResource.tenant && this.config.multiTenancy.useDefaultTenantIfEmpty) {
    normalizedResource.tenant = this.config.multiTenancy.defaultTenant;
  }

  return normalizedResource;
}
This shows that the Node.js SDK does have
multiTenancy.useDefaultTenantIfEmpty
and
multiTenancy.defaultTenant
configuration options that should automatically apply the default tenant when none is specified . However, this normalization appears to only apply to the
check()
enforcement methods in the enforcer . The API client methods for user creation and role assignments (in the
/api
directory) don't show the same automatic default tenant application (2) . This means: • For permission checks (
permit.check()
) , omitting the tenant should default to "default" if configured • For API operations like user creation or role assignments, you may need to explicitly specify the tenant If you're experiencing inconsistent behavior where some API endpoints don't respect the default tenant setting, you should explicitly include
tenant: "default"
in your API calls to ensure consistent behavior across all operations. To help our engineers investigate this potential inconsistency: 1. Which Workspace / Project / Env are you using? 2. What specific API calls are you making (please share the SDK code) ? 3. Which PDP version are you running? 4. Could you share relevant logs from your PDP showing the behavior?
o
@Engineering Swantide - can you please: 1. Follow the advice of the AI here 2. list the SDK functions you had issues with ?
e
Copy code
multiTenancy: {
    defaultTenant: 'default'
  },
doesn't appear to work for the methods i'm working with. So far, it only seems to be
permit.api.roleAssignments.bulkUnassign(allMembersToRemove)
the one I shared previously. of the
IRoleAssignmentsApi.blukAssign
in
permitio/build/api/role-assignments
o
Alright, sounds like oversight, we’ll open a ticket. Sounds like you have a workaround for now
e
theres also,
permit.api.resourceInstances.create
that also has tenant as optional, but when I exclude it, it doesn't upsert into
default
tenant ( Its the only tenant now available after deleting the other one) While it doesn't fail it doesn't upsert to what I would expect to be the
default
tenant, I must pass in
default
to tenant (even though its optional)
yea I just think types and documentation is out of sync, not really blocking. Just bit confusing looking at the definitions 😅
Just wanted to put it on y'alls radar
👍 1
But could I ask. I'm assuming this is expected? always needing to pass in
tenant
?
o
I think the correct behavior would be for this to consistently default
tenant
to
"default"
But yes it sounds in some of these APIs you have to pass in
tenant
I think this is a minor issue; which was just ignored up until now both by our team and other customers
e
gotcha, ok. I'll just continue to enforce passing tenant regardless for now then. Thanks.
ack 1