This design outlines a robust, scalable authorization model for a multi-tenant SaaS platform. It combines RBAC (for coarse-grained, role-centric control) with ABAC (for fine-grained, context-aware decisions). Policies are evaluated via a centralized engine (OPA - Open Policy Agent). Tenant isolation is enforced at multiple layers. Auditing ensures compliance, and threat modeling (using STRIDE) identifies and mitigates risks.
Decision: allow: true/false, with reason for explanation.
Cache decisions in Redis (TTL 5min, key: authz:${tenant_id}:${user_id}:${resource_type}:${action}).
Fallback: Deny by default. Failsafe: If OPA unreachable, deny.
Decision Modes:
Mode
Use Case
Test
Dry-run for policy dev
Partial
Allow if policy undefined
Sequence Diagram (Mermaid):
mermaid
sequenceDiagram
participant Client
participant Gateway
participant Service
participant OPA
participant DB/Cache
Client->>Gateway: API Request (JWT)
Gateway->>Service: Forward (tenant_id)
Service->>DB/Cache: Fetch roles/attrs
Service->>OPA: POST /v1/data/authz/allow
OPA->>Service: {allow: true, reason: "..."}
alt allow
Service->>Client: 200 OK
else deny
Service->>Client: 403 Forbidden
end
3. Tenant Isolation Strategies
Layered Defense:
Layer
Mechanism
Network
K8s NetworkPolicies: Tenant namespaces (e.g., ns-tenant-123). Services only access own namespace.
Database
Postgres RLS policies: CREATE POLICY tenant_isolation ON resources USING (tenant_id = current_setting('app.current_tenant')); Set via SET app.current_tenant = 'tenant-123';. Separate schemas per tenant for high-scale.
Storage
S3 buckets with tenant prefixes (e.g., s3://bucket/tenant-123/objects/). IAM policies restrict access.
Cache
Redis keys prefixed: tenant-123:user-456:roles. Multi-tenant Redis with ACLs.
Authorization
All policies enforce input.tenant_id == resource.tenant_id.
Tenant Onboarding: Auto-provision namespace, DB schema, OPA bundle.
4. Auditing and Logging
What to Log: Every authz decision + mutations.
Field
Value Example
timestamp
RFC3339
tenant_id
tenant-123
user_id
user-456
action
read:reports
resource_id
report-789
decision
allow/deny
reason
OPA output
input_attrs
JSON snippet
request_id
UUID
Storage: ClickHouse/Elasticsearch for high-volume. Retention: 90 days (GDPR-compliant).
Implementation: Middleware logs to Kafka, then sinks to audit store. Searchable via Kibana.
Alerts: Anomalies (e.g., repeated denies from one IP) via ELK stack.
5. Threat Modeling (STRIDE)
Using STRIDE framework to identify threats and mitigations:
Threat Category
Threat Examples
Mitigations
Spoofing
Fake tenant_id in JWT
JWT validation (JWKS rotation, short TTL). Mutual TLS.
Tampering
Modify requests/resources
HMAC signatures, OPA input validation. DB constraints.
Repudiation
Deny actions
Immutable audit logs (append-only). Signed logs.
Information Disclosure
Tenant data leak
RLS + tenant checks in every query/policy. Encrypt at rest (PGP). Least-privilege IAM.
Denial of Service
OPA overload, noisy tenant
Rate limiting per tenant (Redis). OPA circuit breaker. Resource quotas in K8s.
Elevation of Privilege
Role escalation, tenant breakout
RBAC least-privilege. ABAC context checks. Peer reviews for policies.
This model is production-ready, flexible for 1000s of tenants, and aligns with Zero Trust principles. For customizations (e.g., ReBAC for relationships), extend with Zanzibar-inspired graph DB (e.g., SpiceDB). Let me know if you need code samples or diagrams!