Multi-Tenant Digital Signing Service Design
This design outlines a scalable, secure multi-tenant digital signing service using HSM-backed keys . The system supports cryptographic signing operations (e.g., RSA/ECDSA for documents, code, JWTs) where private keys never leave the HSM . Key features include:
Tenant Isolation : Logical and physical separation of keys, data, and quotas.
Rate Limits : Per-tenant throttling to prevent abuse.
Failover : High availability with zero-downtime across regions.
Compliance Alignment : FIPS 140-3 Level 3 HSMs, audit logging, key rotation, GDPR/SOC 2/PCI-DSS/eIDAS support.
The architecture is cloud-agnostic but uses AWS examples for concreteness (e.g., CloudHSM). Alternatives: GCP Cloud HSM, Azure Dedicated HSM.
High-Level Architecture
mermaid Copy code
graph TB
subgraph "Client Layer"
Clients[Multi-Tenant Clients<br/>API Calls]
end
subgraph "API Gateway (Rate Limiting)"
Gateway[API Gateway<br/>(e.g., AWS API GW / Kong)<br/>Auth, Rate Limits, Routing]
end
subgraph "Control Plane"
TenantDB[(Multi-Tenant DB<br/>CockroachDB / Aurora<br/>Tenant Metadata, Quotas)]
IAM[Identity Service<br/>(OAuth/JWT Auth)]
end
subgraph "Data Plane (Signing Service)"
LoadBalancer[Global LB<br/>(Active-Active)]
AppServers[Signing Pods<br/>(Kubernetes/EKS)<br/>PKCS#11 to HSM]
HSMCluster[HSM Cluster<br/>(CloudHSM / Thales nShield)<br/>Partitioned Keys]
end
subgraph "Failover & Storage"
ReplicaDB[DB Replicas<br/>Multi-AZ/Region]
AuditLogs[Immutable Logs<br/>(S3 + Athena / ELK)]
Backup[Key Backups<br/>(HSM Export Tokens)]
end
subgraph "Monitoring"
Observability[Prometheus/Grafana<br/>+ Centralized Logging]
end
Clients --> Gateway
Gateway --> IAM
Gateway --> LoadBalancer
LoadBalancer --> AppServers
AppServers --> TenantDB
AppServers --> HSMCluster
TenantDB --> ReplicaDB
AppServers --> AuditLogs
HSMCluster --> Backup
Observability -.-> *
Core Components
1. Tenant Onboarding & Management
Tenant DB : Multi-tenant PostgreSQL/CockroachDB with row-level security (RLS) or schema-per-tenant.
Stores: Tenant ID, API keys, quotas (RPS, daily signs), key metadata (algorithm, label).
Partitioning: Hash on tenant_id for scalability.
Key Provisioning :
On tenant signup, generate keys inside HSM via PKCS#11/Cryptoki API.
HSM Partitions: One logical partition per tenant (e.g., Thales nShield Connect supports 1000+ partitions).
Key labels: tenant_{id}_signing_key_v1.
Rotation: Automated annual rotation; old keys marked deprecated.
2. HSM Integration (Key Security)
HSM Choice : FIPS 140-3 Level 3 (e.g., AWS CloudHSM Cluster with Cavium/Thales cards).
Multi-Tenancy : HSM partitions enforce isolation—no cross-tenant key access.
Clustering: 5+ HSMs per cluster for quorum (e.g., M of N activation).
Signing Flow :
code Copy code
Client → API GW → Signing Service → HSM (PKCS#11)
1. Authenticate tenant (JWT with tenant_id).
2. Load tenant-specific HSM partition (CKO_PRIVATE_KEY via C_FindObjects).
3. Submit signing request: C_SignInit() → C_Sign() → Return signature.
4. Keys never exported; operations are remote.
Backup/DR : HSM token backups to encrypted S3 (wrapped keys only).
3. API Layer & Rate Limiting
API Gateway : AWS API Gateway or Kong/Envoy.
Endpoints :
Endpoint Method Description Auth /signPOST Sign payload (doc/code/JWT) JWT + tenant_id /keysGET/POST List/generate keys Admin JWT /statusGET Signing status/quotas JWT
Rate Limits : Per-tenant, configurable:
code Copy code
Tenant A: 100 RPS, 1M/day
Tenant B: 10 RPS, 10K/day
Implemented via Redis counters: rate:tenant_{id}:minute.
Burst: Token bucket algorithm (e.g., 2x burst allowed).
Global fallback: Circuit breaker on 50% error rate.
Request/Response :
json Copy code
POST /v1/sign { "tenant_id": "abc", "payload": "base64_doc", "key_id": "key1" }
→ 202 { "signature": "base64_sig", "cert_chain": [...], "timestamp": "..." }
4. Signing Service (Data Plane)
Deployment : Kubernetes (EKS/GKE) with auto-scaling pods.
Language: Go/Rust for crypto perf (using pkcs11 lib).
Stateless: All state in DB/HSM.
Isolation :
Network: VPC peering; tenant traffic tagged.
RBAC: Pods use IAM roles scoped to tenant partitions.
mTLS between services.
Supported Algorithms : ECDSA P-256/384, EdDSA, RSA-2048/4096; SHA-256/384 hashing.
5. Failover & High Availability
Multi-Region Active-Active :
Region Role Components us-east-1 Primary HSM Cluster A, DB Primary eu-west-1 Secondary HSM Cluster B (geo-replicated keys), DB Replica
HSM Sync : Use HSM clustering or key mirroring (export/import wrapped keys).
Traffic Routing : Global Route 53 Latency/Geo DNS → Regional LBs.
Failover Time : <30s (health checks every 10s).
Database : CockroachDB for global replication; async for non-critical metadata.
Zero-Downtime Deploys : Blue-green with Kubernetes rolling updates.
6. Monitoring, Logging & Compliance
Observability :
Metrics: Sign ops/sec per tenant, HSM utilization, latency p99.
Logs: All requests/signs to immutable S3 (10-year retention); searchable via OpenSearch.
Alerts: PagerDuty on quota breaches, HSM quorum loss.
Compliance Alignment :
Standard Controls SOC 2 Type II Audit logs, access controls, annual pentests. GDPR/eIDAS Data residency (multi-region), consent tracking, DSA timestamps. PCI-DSS HSM for cardholder data signing (if applicable). FIPS 140-3 HSM validated; no software keys. Others Key ceremony videos, SOX for key rotation, ISO 27001.
Security :
WAF on API GW (SQLi/XSS).
Secret scanning; no env vars for keys.
Annual HSM audits.
Scalability & Cost Estimates
Throughput : 10K ops/sec per cluster (HSM-limited); scale by adding HSMs ($5K/month each).
Tenants : 10K+ (HSM partitions scale linearly).
Cost (AWS, 1K tenants, 1M signs/day) : ~10 K / m o n t h ( H S M 10K/month (HSM 10 K / m o n t h ( H S M 5K, EKS 2 K , D B 2K, DB 2 K , D B 1K, etc.).
Implementation Roadmap
MVP (4 weeks) : Single-region, basic HSM + API.
Beta (8 weeks) : Multi-tenant + rates + failover.
Prod (12 weeks) : Compliance certs + multi-region.
This design ensures security-first multi-tenancy with production-grade resilience. Questions on specifics (e.g., code snippets, Terraform)?