1) Goals and design principles
Goals
- Strong tenant isolation (no cross-tenant reads/writes, even under bugs/misconfig).
- Flexible authorization: RBAC for manageability + ABAC for expressiveness.
- Centralized, explainable policy evaluation with consistent enforcement.
- Comprehensive audit (who/what/when/why), plus policy-change history.
- Security-first design backed by threat modeling and mitigations.
Principles
- Default deny; allow must be explicit.
- Defense in depth: enforcement at gateway/service + datastore (RLS/partitioning).
- Least privilege and separation of duties for admin capabilities.
- Policies are versioned, testable, reviewable, and changes are audited.
- All authorization is tenant-scoped unless explicitly “platform/global”.
2) Core concepts (multi-tenant model)
Entities
- Tenant: top-level isolation boundary (
tenant_id).
- Principal: user/service account. Has immutable
principal_id.
- Membership: principal belongs to tenant, may belong to groups.
- Group: optional, for scale; groups get roles/policies.
- Role (RBAC): named bundle of permissions within a scope.
- Permission:
(resource_type, action) optionally with constraints.
- Resource: domain object with
tenant_id and attributes (owner, tags, sensitivity).
- Policy (ABAC): rules with conditions over subject/resource/environment.
Scopes
Every assignment is scoped:
scope = tenant:{tenant_id} (most common)
scope = resource:{resource_id} (object-specific grants)
scope = org/unit:{id} (if you have hierarchical tenants)
scope = platform (rare; internal ops)
A useful baseline rule: a principal can only act within a tenant where it has an active membership (unless platform service with explicit “cross-tenant” permission).
3) RBAC + ABAC: how they fit together
RBAC (primary for manageability)
Model roles as stable business concepts:
TenantAdmin: manage users/roles/policies (not billing unless granted)
ProjectOwner, Editor, Viewer
Auditor (read access + audit log access; no writes)
BillingAdmin, SupportAgent (separation of duties)
RBAC is implemented via role assignments:
role_assignment(principal_or_group, role, scope, tenant_id, constraints?)
ABAC (adds precision and context)
ABAC conditions refine access based on attributes:
- Subject attributes:
department, clearance, is_mfa, authn_strength, groups
- Resource attributes:
owner_id, project_id, classification, tags, region
- Environment attributes:
ip_range, time, device_posture, request_channel
Typical ABAC examples:
- “Editors can update documents only if
resource.classification <= subject.clearance”
- “Support can read tenant data only with ticket id and within time window”
- “PII fields are masked unless
subject.role in {PrivacyOfficer}”
Recommended combination pattern
- RBAC answers: “Is this action generally allowed for this role in this scope?”
- ABAC answers: “Is it allowed given current attributes/context and resource state?”
Keep roles simple; put edge conditions into ABAC rules.
4) Policy model (language-agnostic)
A policy rule structure:
- Target:
tenant_id (or * only for platform-internal rules)
resource_type
actions
- Effect:
allow or deny
- Conditions (boolean expression over attributes)
- Obligations (optional): masking, row filters, rate limits, step-up auth requirement
- Metadata:
policy_id, version, owner, created_at, review_due
Deny rules are valuable for safety:
- “Deny export if data is classified and user lacks export entitlement”
- “Deny cross-region access unless explicitly permitted”
Conflict resolution (choose explicitly and document it):
- Common: deny-overrides (any deny wins)
- Then: allow if any allow matches
- Else: deny
Policy storage
- Namespace by tenant:
policies/{tenant_id}/...
- Platform policies in separate namespace with extra review gates.
- Versioned and signed (or at least checksummed) for integrity.
5) Policy evaluation architecture (PEP/PDP)
Components
- PEP (Policy Enforcement Point): in API gateway and/or each service handler. Responsible for:
- collecting request context
- calling PDP
- enforcing decision + obligations
- PDP (Policy Decision Point): centralized service or embedded library/sidecar. Responsible for:
- loading policies
- evaluating decision
- returning
ALLOW/DENY + explanation/obligations
- PIP (Policy Information Point): attribute sources:
- directory (groups, roles)
- resource store (owner, tags)
- risk engine (device posture)
- ticketing system (support access)
Decision request format (example)
tenant_id
principal: {id, type, roles, groups, attributes}
action: "document.update"
resource: {type, id, tenant_id, attributes}
environment: {time, ip, authn_strength, request_id}
Evaluation steps (deterministic)
- Authenticate principal; validate token/signature; extract
principal_id.
- Resolve tenant context (from URL/host/header), then enforce:
- token is valid for that tenant (or explicitly platform-scoped).
- Load membership + role assignments for
(principal_id, tenant_id).
- Fetch resource attributes (or accept them only from trusted backend, not client).
- Evaluate policies with deny-overrides and default deny.
- Return:
- decision: allow/deny
- matched policies + reasons (for audit/debug)
- obligations (mask fields, apply row filter, require MFA step-up)
Performance notes
- Cache compiled policies per tenant (short TTL, event-driven invalidation).
- Provide bulk authorization endpoints (e.g., “which of these 200 resources can I read?”).
- For “list” operations, prefer server-side filtering (policy-driven queries), not post-filtering.
6) Tenant isolation (must be enforced at multiple layers)
Layer 1: Identity & tokens
- Tokens include immutable
principal_id and explicit tenant_id (or tenant memberships).
- Prevent “tenant switching” by requiring:
- requested
tenant_id must match token tenant context OR
- token must carry explicit entitlement to act in that tenant.
- Separate platform/internal identities from tenant identities (different audiences/issuers).
Layer 2: Application enforcement
- Every request must carry
tenant_id via one canonical mechanism:
- subdomain (
tenantA.app.com)
- path (
/tenants/{tenant_id}/...)
- header (only if gateway enforces it)
- Enforce “tenant_id is not optional” in all handlers and service calls.
- Validate resource belongs to tenant before any operation:
resource.tenant_id == context.tenant_id.
Layer 3: Data layer isolation
Pick one (or combine):
A) Strongest (costlier): separate databases per tenant
- Best isolation, easiest compliance story, more operational overhead.
B) Shared DB with hard isolation
- Every table has
tenant_id and all keys are (tenant_id, id) (composite primary key).
- Row-Level Security (RLS):
- Set
app.current_tenant per connection/transaction
- RLS policy:
tenant_id = current_setting('app.current_tenant')
- Add DB constraints to prevent cross-tenant relations.
C) Shared DB + partitioning by tenant
- Partition tables by
tenant_id to reduce blast radius and improve performance.
Encryption
- Per-tenant encryption keys (envelope encryption) for sensitive columns/blobs.
- Rotate keys; restrict key usage by tenant.
Layer 4: Policy isolation
- Policies are tenant-namespaced; a tenant admin cannot view/modify another tenant’s policies.
- “Global/platform” policies stored separately and require elevated review/approval.
7) Administrative model (delegation & safety)
Delegated admin
TenantAdmin can manage:
- memberships, groups
- role assignments
- tenant-scoped policies
- Cannot grant roles/policies that exceed a bounded “admin grant set” (prevents privilege escalation by policy editing).
Separation of duties
Split critical powers:
SecurityAdmin: can change auth policies
UserAdmin: can manage memberships
BillingAdmin: billing only
Auditor: read-only + audit access
Break-glass access (platform support)
- Time-bound, ticket-bound access with explicit approvals:
- requires MFA + justification
- emits high-severity audit events
- automatically expires
8) Audit design (decisions + changes)
What to audit
- Authorization decisions (at least for sensitive actions; optionally all):
- principal, tenant, action, resource, result
- matched policy IDs/versions
- reason codes (e.g., “DENY: classification too high”)
- request_id/trace_id, IP, user agent
- Administrative events:
- role assignments added/removed
- policy created/updated/deleted
- group membership changes
- key management events
- Data access for regulated data:
- read/export events, especially bulk export and PII
Audit properties
- Append-only storage (WORM/object lock) or tamper-evident chaining (hash chaining).
- Central aggregation (SIEM), alerting rules (e.g., repeated denies, unusual cross-geo access).
- Retention policies per tenant/compliance (e.g., 1–7 years).
- Tenant-scoped audit views; platform can access only with explicit support role and justification.
9) Threat model (STRIDE-style) + mitigations
Spoofing (identity)
Threats
- Forged JWT / stolen token
- Service-to-service impersonation
- Tenant context spoofing (header/path tampering)
Mitigations
- Strong JWT validation (issuer/audience/exp/nbf/jti), rotate keys, short lifetimes
- mTLS and workload identity for services
- Gateway-enforced tenant resolution; reject ambiguous tenant context
- Step-up auth for sensitive actions
Tampering (policies/data)
Threats
- Policy modification by tenant admin to escalate privileges
- Injection of fake attributes (client-supplied resource fields)
- Policy store corruption
Mitigations
- Bound admin powers (“cannot grant what you don’t have”)
- Only trusted services supply resource attributes; never trust client attributes
- Policy versioning, approvals for sensitive policy changes
- Integrity checks/signatures on policy bundles
Repudiation
Threats
- Users deny having performed actions
- Admins modify policies without trace
Mitigations
- Immutable audit logs with trace IDs, timestamps, actor identity
- Require justification fields for break-glass and sensitive admin ops
Information disclosure (cross-tenant leakage)
Threats
- Missing
tenant_id filters; IDOR across tenants
- Caching layer serving data across tenants
- Search/list endpoints leaking counts/metadata
Mitigations
- DB RLS or per-tenant DB; composite keys
- Cache keys include
tenant_id and auth context
- Authorization-aware search (filter at query-time), avoid returning existence hints
- Consistent object ownership checks
Denial of service
Threats
- Expensive policy evaluation (complex ABAC conditions)
- Policy store thrashing (cache busting)
- Audit log floods
Mitigations
- Compile policies; cap policy complexity; timeouts
- Rate limit per tenant/principal; circuit breakers
- Async audit pipelines with backpressure and sampling for low-risk events
Elevation of privilege / confused deputy
Threats
- Service uses its own privileges on behalf of user without scoping
- Over-broad platform roles
- Misconfigured role inheritance
Mitigations
- Use “on-behalf-of” tokens with user + tenant scope; enforce at PDP
- Separate service roles from user roles; least privilege
- Explicit allowlists for cross-tenant/platform operations
- Automated checks: “no policy grants action X unless role Y”
TOCTOU (time-of-check/time-of-use)
Threats
- Permission changes between check and use
- Resource attribute changes after authorization
Mitigations
- For critical actions: re-check authorization at commit time or enforce in DB transaction
- Use consistent reads/transactions; include resource version in decision context
10) Practical implementation guidance (what to build first)
Minimum secure baseline
- Tenant-scoped identity + membership
- RBAC roles per tenant + default deny
- PDP/PEP with consistent
(tenant, principal, action, resource) contract
- DB-level tenant isolation (RLS or per-tenant DB)
- Audit logs for admin changes + sensitive reads/writes
Then add
- ABAC conditions (classification, ownership, device posture)
- Obligations (masking, step-up auth)
- Break-glass workflows
- Policy testing + CI validation (unit tests for policies, regression suites)
If you share your domain objects (resource types/actions), tenancy shape (single-level vs org→projects), and deployment style (monolith vs microservices), I can propose a concrete policy schema and example policies (e.g., “ProjectOwner can manage documents within project; Support can read with ticket + expiry; Auditor can access logs only”).