SaaS architecture

Roles and Permissions Handling in SaaS Applications

A B2B SaaS product should handle roles and permissions per customer tenant: define permissions as small, named actions, bundle them into roles, assign roles to users inside a specific tenant, and check the permission, not the role name, on the server for every request. Start with a few default roles, then let larger customers build their own roles from the permissions you allow.

This guide covers the architecture behind that answer: the layers involved, a tenant-scoped data model, enforcement, customer-defined roles, enterprise requirements and testing. For the basics of designing roles and the admin screens around them, see our guide to user roles and permissions. For the RBAC model itself, see what RBAC is.

The Three Layers of SaaS Access Control

Access in a multi-tenant product depends on three separate questions: which customer account the user is acting in, what they are allowed to do there, and what that account has paid for. Keep each in its own layer.

LayerQuestion it answersExampleWho controls it
Tenant membershipWhich customer accounts does this user belong to, and which one are they acting in now?Jane is a member of Acme and of Acme’s EU subsidiaryThe customer’s admins, often through SSO and SCIM
Roles and permissionsWhat may this user do inside this tenant?Jane has the Billing Manager role in Acme, which includes invoices.approveThe customer’s admins, within limits you set
Plan entitlementsWhat has this tenant paid for?Acme’s plan includes the Approvals featureYou, the vendor, based on the subscription

An action should succeed only when all three agree: Jane is acting in Acme, her role there grants invoices.approve, and Acme’s plan includes approvals. Keeping the layers apart means a plan downgrade doesn’t require rewriting every customer’s roles, and a role change doesn’t accidentally unlock a paid feature.

How Permission Needs Evolve as You Grow

Few products need fine-grained permissions on day one. The requirements usually arrive in three phases, and the data model you pick early decides how painful the later phases are.

Phase 1: All or nothing

Early on, two roles are enough: Admin, who can do everything within their tenant, and Read-only, who can see everything but change nothing. Even here, model them as roles made of permissions rather than as an is_admin flag, so you can add roles later without touching every check in the code.

Phase 2: Business-specific roles

As customers ask for more control, you add roles such as Editor, Reporter or Billing Manager. Each adds permissions on top of Read-only or removes sensitive ones from Admin. These are still roles you define and every customer shares.

Phase 3: Every enterprise customer is different

Larger customers organize access in their own ways, and shared roles stop fitting:

  • By structure. Each business unit or product group sees only its own projects and needs different actions on them.
  • By function. All engineers get one set of permissions and all designers another, regardless of team.
  • By geography. European staff and US staff see different data, often for GDPR or CCPA reasons.

At this stage customers need to define their own roles, and some need access scoped below the tenant level.

A Tenant-Scoped Data Model

A role assignment always belongs to a tenant. The same user can be an Admin in one customer account and a Viewer in another, so a role can never be stored on the user alone. A minimal relational model:

CREATE TABLE permissions (
  key                TEXT PRIMARY KEY,
  description        TEXT NOT NULL,
  custom_role_policy TEXT NOT NULL CHECK (custom_role_policy IN ('assignable', 'always', 'never'))
);

CREATE TABLE roles (
  id        UUID PRIMARY KEY,
  tenant_id UUID REFERENCES tenants(id),
  name      TEXT NOT NULL,
  UNIQUE NULLS NOT DISTINCT (tenant_id, name)
);

CREATE TABLE role_permissions (
  role_id        UUID NOT NULL REFERENCES roles(id),
  permission_key TEXT NOT NULL REFERENCES permissions(key),
  PRIMARY KEY (role_id, permission_key)
);

CREATE TABLE tenant_members (
  user_id   UUID NOT NULL REFERENCES users(id),
  tenant_id UUID NOT NULL REFERENCES tenants(id),
  PRIMARY KEY (user_id, tenant_id)
);

CREATE TABLE member_roles (
  user_id   UUID NOT NULL,
  tenant_id UUID NOT NULL,
  role_id   UUID NOT NULL REFERENCES roles(id),
  PRIMARY KEY (user_id, tenant_id, role_id),
  FOREIGN KEY (user_id, tenant_id) REFERENCES tenant_members(user_id, tenant_id)
);

Membership and roles are separate tables, so a user can belong to a tenant before they have any role there. A role with no tenant_id is a default role you define for every tenant; a role with a tenant_id is a custom role one customer created. Make sure a role from one tenant can never be assigned in another: the permission check below enforces this in its query, and a database trigger can block such assignments outright.

The permission check always takes the tenant as an input, and that tenant comes from the authenticated session, never from a request parameter the user can change. The route checks the plan entitlement and the permission, scopes the record lookup to the tenant, and writes an audit entry:

async function hasPermission(userId: string, tenantId: string, permissionKey: string): Promise<boolean> {
  const result = await db.query(
    `SELECT 1
       FROM member_roles mr
       JOIN roles r ON r.id = mr.role_id
       JOIN role_permissions rp ON rp.role_id = mr.role_id
      WHERE mr.user_id = $1
        AND mr.tenant_id = $2
        AND (r.tenant_id = $2 OR r.tenant_id IS NULL)
        AND rp.permission_key = $3
      LIMIT 1`,
    [userId, tenantId, permissionKey]
  );
  return (result.rowCount ?? 0) > 0;
}

app.post("/invoices/:invoiceId/approve", async (request, response) => {
  const { userId, tenantId } = request.session;
  const allowed =
    (await tenantHasFeature(tenantId, "approvals")) &&
    (await hasPermission(userId, tenantId, "invoices.approve"));
  if (!allowed) {
    return response.status(403).end();
  }
  const invoice = await invoices.findOne({ id: request.params.invoiceId, tenantId });
  if (!invoice) {
    return response.status(404).end();
  }
  await invoices.approve(invoice.id, userId);
  await auditLog.record({ tenantId, userId, action: "invoices.approve", resourceId: invoice.id });
  response.status(204).end();
});

Name permissions after the resource and the action, such as invoices.read and invoices.approve, and check those keys in code. Checking role names (“is this user a Billing Manager?”) breaks as soon as a customer creates a custom role that should also approve invoices.

Enforcing Permissions on Every Request

Check permissions on the server for every request; hiding a button in the UI is not access control. Broken access control is ranked first in the OWASP Top 10:2025, which reports that 100% of the applications tested had some form of it. The OWASP Authorization Cheat Sheet sets out the baseline:

  • Deny by default. If no rule grants an action, refuse it.
  • Validate permissions on every request, whether it comes from your UI, an API client or a background job acting for a user.
  • Enforce least privilege. Give each role the minimum it needs.
  • Log authorization decisions, especially denials and changes to roles.

Permissions in tokens vs. lookups

Many products put the user’s roles and permissions for the active tenant into the access token, usually a JWT, so APIs can check them without a database call. That is fast, but the token reflects the moment it was issued. If an admin removes a permission, the user keeps it until the token expires. Three ways to handle that:

  • Keep access tokens short-lived, minutes rather than hours, so changes take effect quickly. See our guide to refresh tokens.
  • Issue a new token when roles change for the current user, or force a refresh.
  • For high-risk actions such as deleting data or changing billing, check the current permissions in the database instead of trusting the token.

If you look permissions up on every request, cache the result per user and tenant for a short time and clear the cache when that tenant’s roles change. API keys and machine-to-machine tokens that act for a tenant need the same treatment: give them their own roles or scopes in that tenant rather than an all-powerful key.

Also decide how to represent users who belong to several tenants. The simplest approach is one active tenant per token: switching tenants issues a new token with that tenant’s roles, so a request can never mix permissions from two customers.

Letting Customers Define Their Own Roles

Customer-defined roles solve the Phase 3 problem without you shipping a new role for every request, as long as you set guardrails: classify each permission as assignable, always included or never available to custom roles (the custom_role_policy column above), and stop admins from assigning roles more powerful than their own. Our guide to self-service role configuration covers the guardrails and the admin experience in detail.

Enterprise Requirements to Plan For

Enterprise customers add four requirements: identity provider group mapping, account hierarchies, access hygiene and controlled support access.

Mapping identity provider groups to roles

Enterprise customers want access driven by their identity provider. With SSO and SCIM, a group such as finance-admins maps to a role in your product. Decide whether IdP mappings override roles assigned by hand, and whether roles update at every login or only when SCIM sends a change.

Sub-accounts and hierarchies

Customers with subsidiaries, regions or reseller relationships need account hierarchies. A role granted at a parent account often needs to apply to its sub-accounts, while users in a sub-account must not see the parent or their siblings.

Over-permissions, under-permissions and inactive users

Least privilege fails in three common ways:

  • Over-permission. Users hold more access than their job needs, which widens the damage if their account is compromised and makes costly mistakes possible. Granular custom roles are the fix.
  • Under-permission. A user needs one more action, and the only way to grant it is a much broader role. An access-request flow, like requesting access to a shared document, lets the user ask for exactly what they need and notifies the tenant’s admin.
  • Inactive users. Accounts that are no longer used, such as departed employees or finished contractors, keep their access. Notify tenant admins about long-inactive users or deactivate them automatically, and use SCIM so deprovisioning in the customer’s IdP removes access in your product.

Support access

Your own support team will need to see inside customer tenants. Make that access explicit: time-limited, approved or at least visible to the customer, and recorded in an audit log the customer can review. Never route it through a shared admin account.

Testing for Cross-Tenant Access

Authorization bugs rarely show up in normal use, so test for them on purpose. A useful minimum suite:

  • A user in tenant A requests a resource ID that belongs to tenant B and gets a 403 or 404, never the data.
  • A user with no role in a tenant is denied everything there.
  • Changing the tenant ID in a request body or URL doesn’t change which tenant’s data is returned.
  • A custom role can’t include a permission classified as never assignable.
  • Removing a permission takes effect within your token lifetime, and immediately for high-risk actions.

When Roles Alone Aren’t Enough

Roles describe what kind of user someone is. They struggle with rules like “editors can change documents in their own project” or “managers can approve expenses under $5,000.” The OWASP cheat sheet notes that attribute-based (ABAC) and relationship-based (ReBAC) access control are typically preferable for application development because they handle fine-grained rules like these. In practice, most B2B products keep tenant-scoped roles as the base and add attribute or relationship checks for the few resources that need them. Our comparison of RBAC, ABAC and PBAC covers the trade-offs.

Roles and Permissions with Frontegg

Frontegg provides these pieces as managed features. According to Frontegg’s roles documentation:

  • Roles can be shared or tenant-specific. A role can be assigned to all accounts in an environment or to a specific account, and a default role can be added to users when they sign up.
  • Customers can build their own roles. Enabling the Roles page in the self-service portal lets each account create custom roles, with every permission classified as Assignable, Always or Never. Custom roles are part of the Enterprise plan on Frontegg’s pricing page.
  • Role levels prevent escalation. Users can only assign roles at their own level or a lower-privileged one, and a strict mode can block equal-level assignments too.
  • Permissions are keys in the token. Permission keys name the resource and action and are stored in the user’s JWT, and Frontegg’s token claims documentation notes that backend SDKs rely on those claims for access checks.
  • Plans and permissions work together. With entitlements, users need both the required permission and the feature enabled for their account.
  • Hierarchies are supported. In account hierarchies, a role assigned at a parent account applies to all sub-accounts in that branch.

Start For Free

Looking to take your User Management to the next level?
Sign up. It's free