Skip to content

Minimal Schema Architecture for Certificate Storage

Docs for PKI Manager 3.17.0 (released 2026-11-24), from main 4d59c30 (30 commits after the release). Page last changed in 1.0.0.

Source: backlog/decisions/decision-004 - Minimal-Schema-Architecture-for-Certificate-Storage.md

The PKI Manager application needed to decide how to store certificate and CA data across two systems:

  • Local SQLite database (for querying and application state)
  • Cosmian KMS (for cryptographic key material and certificate storage)

Initial implementation stored complete certificate data in both locations, leading to:

  • Data duplication between local DB and KMS
  • Increased database size from large PEM-encoded certificates
  • Maintenance burden of keeping both stores synchronized
  • Unclear source of truth for certificate data

We needed an architecture that would:

  • Eliminate data duplication
  • Maintain fast query performance for lists and searches
  • Establish clear single source of truth
  • Minimize KMS API calls for acceptable performance

We will implement a minimal schema approach with hybrid storage:

  1. KMS References (essential)

    • kms_certificate_id - Reference to fetch certificate from KMS
    • kms_key_id - Reference to private/public keys
  2. Query Optimization Fields (denormalized for performance)

    • subject_dn - For searching by subject
    • serial_number - For unique identification
    • not_before, not_after - For expiry filtering
  3. Application State (not in X.509 certificate)

    • status - active/revoked/expired
    • revocation_date, revocation_reason - Workflow tracking
  • Complete certificate PEM data
  • Private/public key material
  • Certificate metadata
  • ❌ certificate_pem - Fetch from KMS on-demand
  • ❌ key_algorithm - Extract from certificate when needed
  • List operations: Use local DB metadata only (fast)
  • Detail views: Fetch certificate from KMS on first access
  • Export operations: Fetch from KMS when generating files
  • No local caching of fetched PEM data
  • Created migration 0002_minimal_schema.sql
  • Added KMSService.getCertificate() method
  • Updated CA procedures to fetch on-demand
  • Applied migration successfully
  • backend/src/db/schema.ts - Minimal schema definition
  • backend/src/kms/client.ts - Added getCertificate() KMIP operation
  • backend/src/kms/service.ts - Service wrapper with audit logging
  • backend/src/trpc/procedures/ca.ts - On-demand fetching in getById
  • backend/src/db/migrations/0002_minimal_schema.sql - Schema migration
  • ✅ CA creation test passing
  • ✅ 88 total tests passing
  • Certificate procedures require similar updates (tracked in task-2)
  1. Single Source of Truth: KMS is authoritative for all certificate data
  2. Reduced Database Size: Large PEM strings eliminated from local storage
  3. No Data Synchronization: Certificate data can’t drift between systems
  4. Clean Architecture: Clear separation between query optimization and cryptographic storage
  5. Fast List Operations: Local metadata enables sub-millisecond queries
  1. KMS Dependency: Certificate detail views require KMS availability
  2. Additional Network Calls: 1 KMS call per detail view/export operation
  3. Latency: ~50-100ms per KMS fetch (acceptable for detail views)
  4. Migration Complexity: Required recreating tables in SQLite
  1. Implementation Effort: Certificate procedures need same pattern as CAs
  2. Frontend Impact: Minimal - already expects full data in detail views only
  3. Testing: Test expectations updated to match new response schema

Measured:

  • List operations: No change (uses local DB metadata)
  • Detail views: +50-100ms for KMS fetch (acceptable)
  • Export operations: +50-200ms depending on chain depth

Scalability:

  • Local DB queries: O(log n) with indexes - excellent
  • KMS fetches: O(1) per certificate - acceptable
  • Memory: Reduced from ~5KB per cert (PEM) to ~500B (metadata)
  • Task task-2: Complete minimal schema migration for certificate procedures
  • Migration: backend/src/db/migrations/0002_minimal_schema.sql
  • KMS Documentation: Cosmian KMS KMIP specification

PKI Manager is a personal project of Oriol Rius, built for his own use. It is not a commercial product. About this project