Skip to main content

Cross-Tenant Authentication

OctoMesh supports a hierarchical tenant model where a parent tenant can authenticate users in child tenants. This allows organizations to maintain a single user directory while granting access to multiple isolated tenants.

How It Works​

Parent Tenant (e.g., "octosystem")
├── User: alice (local user)
├── User: bob (local user)
│
└── Child Tenant (e.g., "customer-project")
├── OctoTenantIdentityProvider → points to "octosystem"
├── ExternalTenantUserMapping: alice → roles: [Development, DashboardViewer]
└── ExternalTenantUserMapping: bob → roles: [TenantManagement]
  1. alice logs into customer-project using her octosystem credentials
  2. The Identity Service finds the OctoTenantIdentityProvider pointing to octosystem
  3. It validates alice's credentials against the parent tenant
  4. It finds an ExternalTenantUserMapping for alice, granting her the Development and DashboardViewer roles
  5. A JWT token is issued with tenant_id: customer-project, home_tenant_id: octosystem, and the mapped roles

Two things are required for cross-tenant authentication to work:

  • An OctoTenantIdentityProvider in the child tenant pointing to the parent (created automatically when the child tenant is created)
  • An ExternalTenantUserMapping for each user that should have access (created via admin provisioning or manually)

Granting Access to a Child Tenant​

This is the most common scenario: you are logged into the parent tenant (e.g., octosystem) and want to grant yourself or another user access to a child tenant (e.g., meshtest). You do not need access to the child tenant to do this.

Quick Start: Grant Yourself Access​

# 1. Log into the parent (system) tenant
octo-cli -c Config -tid "octosystem"
octo-cli -c LogIn -i

# 2. Provision yourself in the child tenant (grants all roles + TenantOwners group)
octo-cli -c ProvisionCurrentUser -ttid "meshtest"

# 3. Log into the child tenant (token now includes meshtest in allowed_tenants)
octo-cli -c Config -tid "meshtest"
octo-cli -c LogIn -i

That's it. You now have full access to meshtest.

What ProvisionCurrentUser Does​

  1. Creates an ExternalTenantUserMapping with all available roles in the target tenant
  2. Adds the mapping to the TenantOwners group (granting all default roles via group inheritance)
  3. If the target tenant is still initializing (CK model not loaded), retries automatically
  4. Prints the source tenant and user the mapping was written for

Nested Tenants (Grandchildren)​

ProvisionCurrentUser also works for a tenant two or more levels below your home tenant, from any of your contexts. Example: you are a user of octosystem, you are provisioned in the child customer-a, and you create the grandchild customer-a-site1 below it.

# From the home tenant (recommended)
octo-cli -c Config -tid "octosystem"
octo-cli -c ProvisionCurrentUser -ttid "customer-a-site1"

# Or from the context of the intermediate tenant: you act there as the cross-tenant user xt_octosystem_<you>
octo-cli -c Config -tid "customer-a"
octo-cli -c ProvisionCurrentUser -ttid "customer-a-site1"

Both calls write the same mapping: for your home identity (octosystem / your user), never for the cross-tenant user of the intermediate tenant. The output names it:

Current user provisioned in target tenant 'customer-a-site1': mapping written for user 'you@example.com' (<user-id>) of tenant 'octosystem'

Afterwards every context of yours reaches the grandchild: the token exchange from your octosystem token (the way octo-cli and the MCP server switch tenants) and the one from your customer-a token. If the identity service cannot resolve the home identity of the calling cross-tenant user (for example because the home tenant was deleted), the call fails with HTTP 409, writes nothing and tells you to run it from your home tenant.

Mappings written by older versions from an intermediate context were keyed on the cross-tenant user; with them the exchange from your home token is refused with tenant_not_provisioned. Run ProvisionCurrentUser once from your home tenant to add the home mapping.

Grant a Specific User Access​

To provision another user with selected roles:

# Still logged into the system tenant
octo-cli -c CreateAdminProvisioningMapping \
-ttid "meshtest" \
-stid "octosystem" \
-suid "<user-id>" \
-sun "alice" \
-rids "Development,DashboardViewer"

The user must log out and log back in to receive the updated allowed_tenants claim.

List and Delete Provisioned Users​

# List all provisioned users in target tenant
octo-cli -c GetAdminProvisioningMappings -ttid "meshtest"

# Delete a provisioning
octo-cli -c DeleteAdminProvisioningMapping -ttid "meshtest" -mid "<mapping-rtid>"

Complete Workflow: New Tenant from Scratch​

# 1. Log into the system tenant
octo-cli -c Config -tid "octosystem"
octo-cli -c LogIn -i

# 2. Create the child tenant
octo-cli -c Create -tid "new-project" -db "new_project_db"

# 3. Provision yourself (no access to child tenant needed)
octo-cli -c ProvisionCurrentUser -ttid "new-project"

# 4. Log into the new tenant
octo-cli -c Config -tid "new-project"
octo-cli -c LogIn -i

# 5. Optionally provision other users
octo-cli -c CreateAdminProvisioningMapping \
-ttid "new-project" \
-stid "octosystem" \
-suid "<bob-user-id>" \
-sun "bob" \
-rids "DashboardViewer,ReportingViewer"
info

When a new child tenant is created, an OctoTenantIdentityProvider pointing to the parent is automatically created. You do not need to create it manually.

note

Until at least one user is provisioned in a child tenant, the login page displays "This tenant is not available. Please contact your administrator." — the login form is not shown.

Users of Sibling Tenants​

A user of a tenant that is not an ancestor — for example a sibling under the same parent — can be granted access too, with groups of the target tenant, when the source tenant permits it. The user is found only by exact user name or e-mail. See Cross-Tenant Access for Sibling Tenants.

Key Concepts​

OctoTenant Identity Provider​

An OctoTenant identity provider delegates authentication to a parent tenant. When a user tries to log in and no local user is found, the Identity Service walks up the tenant hierarchy (via OctoTenantIdentityProviders) to find and authenticate the user.

  • The hierarchy supports up to 10 levels of depth
  • Cycle detection prevents infinite loops
  • The provider can be configured with AllowSelfRegistration and DefaultGroupRtId

External Tenant User Mappings​

An external tenant user mapping links a user from a parent tenant to a set of roles (and optionally groups) in the child tenant. Without a mapping, an authenticated cross-tenant user has no roles in the child tenant.

Each mapping contains:

PropertyDescription
SourceTenantIdThe parent tenant where the user originates
SourceUserIdThe user's ID in the parent tenant
SourceUserNameThe user's name in the parent tenant
RoleIdsRoles assigned in the child tenant
GroupNamesGroups the user belongs to in the child tenant

Uniqueness of Mappings​

A mapping is unique per source tenant and source user within a target tenant. A user from a parent tenant has exactly one mapping in a child tenant, and that one mapping carries all of the user's roles and groups there.

Creating a second mapping for the same source tenant and source user is refused with HTTP 409 Conflict. This applies to every way of creating one: CreateExternalTenantUserMapping, CreateAdminProvisioningMapping, the admin provisioning with groups, and the corresponding REST calls. The response is a problem document with the error code ExternalTenantUserMappingAlreadyExists and the id of the existing mapping (existingMappingId); the title and detail name the existing mapping and tell you to update its roles instead.

HTTP 409
{
"title": "A mapping for this source user already exists",
"code": "ExternalTenantUserMappingAlreadyExists",
"existingMappingId": "<mapping-rtid>"
}

octo-cli ends the command with a non-zero exit code and prints this response body as the error text. To give a user additional roles, change the existing mapping instead of creating another one:

octo-cli -c UpdateExternalTenantUserMapping -id "<existingMappingId>" -rids "Development,DashboardViewer,TenantManagement"

The user receives the new roles with the next token (sign in again, or exchange the token).

Existing duplicates keep working. Mappings created before this rule can leave a user with more than one mapping in the same tenant. Sign-in and token exchange do not fail in that case. The oldest mapping is used to find the user, and the identity service writes one warning to its log per sign-in or exchange (using the oldest ...) naming the mapping ids. The roles the user receives are the union of the roles and groups of all of their mappings, so no access is lost. Delete the surplus mappings to remove the warning; use GetExternalTenantUserMappings -stid "<source tenant>" to find them.

Cross-Tenant User Prefix​

When a cross-tenant user logs in for the first time, the Identity Service creates a local user record in the child tenant with the prefix xt_{parentTenantId}_{username}. This local record is linked to the external tenant user mapping.

Managing Mappings in the Child Tenant​

Once you have access to the child tenant, you can also manage user mappings directly from within that tenant. This gives you more granular control than admin provisioning.

Create a Mapping​

# Switch to the child tenant context
octo-cli -c Config -tid "customer-project"
octo-cli -c LogIn -i

# Create a mapping for a parent tenant user
octo-cli -c CreateExternalTenantUserMapping \
-stid "octosystem" \
-suid "<user-id-from-parent>" \
-sun "alice" \
-rids "Development,DashboardViewer"

List and Delete Mappings​

# List all mappings
octo-cli -c GetExternalTenantUserMappings

# Filter by source tenant
octo-cli -c GetExternalTenantUserMappings -stid "octosystem"

# Delete a mapping
octo-cli -c DeleteExternalTenantUserMapping -id "<mapping-rtid>"

Manually Create an OctoTenant Identity Provider​

This is only necessary if you need to point a child tenant to a different parent than the one it was created from, or if the provider was deleted:

octo-cli -c AddOctoTenantIdentityProvider \
-n "Parent Tenant" \
-ptid "octosystem" \
-e true

Non-Interactive Tenant Switching (Token Exchange)​

Browser sessions switch tenants via the cross-tenant auto-login endpoints. Non-browser clients — most importantly the MCP Services (switch_tenant tool) — use RFC 8693 Token Exchange instead: a valid access token from the user's current tenant is exchanged at /connect/token for an access token of the target tenant.

The exchange enforces the same rules as an interactive cross-tenant login:

  1. The subject token must be valid and carry a user context
  2. The user must have cross-tenant access to the target tenant (validated against the tenant hierarchy and the target tenant's ExternalTenantUserMapping); for a user who is themselves a cross-tenant shadow user (xt_…), the check runs from their home tenant — the common ancestor — so switching between sibling tenants works
  3. The shadow user is found or created in the target tenant, and roles are re-resolved there — the issued token carries the target tenant's tenant_id and target-resolved roles, never the source tenant's roles

Denied exchanges fail with unauthorized_client and are written to the audit event log. No refresh token is issued for exchanged tokens; clients re-exchange from the still-valid original token.

Allowed Tenants Resolution​

At token issuance, the Identity Service resolves which tenants a user may access. The algorithm has four phases:

  1. Login tenant — always included
  2. Home tenant — for cross-tenant users (username starts with xt_), their parent tenant is extracted and included
  3. Ancestor tenants — walks up the tenant hierarchy by following OctoTenantIdentityProvider parent references (up to 10 levels, with cycle detection)
  4. Descendant tenants — BFS traversal down through child tenants, checking for ExternalTenantUserMapping entries matching the user. This cascades through multiple levels (e.g., octosystem → customer-project → sub-project)

The resulting list is emitted as allowed_tenants claims in the JWT access token. Clients use it to offer the tenants a user can switch to; services do not authorize with it. A request to another tenant needs a token of that tenant (sign in there or use the token exchange), see Tenant Authorization and Tenant Generations.

Example​

octosystem (parent)
├── customer-project (child)
│ └── sub-project (grandchild)

When user alice from octosystem has an ExternalTenantUserMapping in customer-project, and her cross-tenant identity xt_octosystem_alice has a mapping in sub-project, her allowed_tenants will include all three tenants.