pci-service — Centralized Encrypted Card Data Store

By Engineering Team•October 10, 2026•4 min read

Responsibility

pci-service is the central, tenant-isolated store for card-data attributes (card token, last 4 digits, brand) — the PCI-scoped counterpart to pii-service’s personal-data store, sharing the same underlying implementation rather than a hand-maintained duplicate.

  • Generic encrypted attribute store — the same UpsertAttributes/GetAttributes/DeleteAttributes EAV surface as pii-service, keyed by (tenant_id, entity_type, entity_id, attribute_key).
  • Encryption at rest — every plaintext_value is AES-256-GCM-encrypted with a fresh random nonce before insert, decrypted only inside a Get* call, keyed by its own PCI_ENCRYPTION_KEY env var (never shared with pii-service’s key).
  • Per-call audit trail — every write/read/delete writes one row_attribute_audit_log entry (caller_service, transaction_id, action, entity_type, entity_id), same shape as pii-service’s table, different schema.
  • gRPC-only, no direct database access from outside this service — no HTTP/REST surface; no other service may query its PostgreSQL schema directly.

Tech Stack

Concern Choice
Language Rust
gRPC tonic server only — no outbound gRPC client, no REST/HTTP surface
Data store PostgreSQL (SeaORM), schema "pci-service" — same shared Postgres instance as pii-service/user-secure-engine, isolated by schema, one schema per owning microservice
Shared logic rust-lang-core-lib’s domain::encrypt/service::encrypt/repository::encrypt — identical implementation consumed by pii-service; only the concrete SeaORM entity and gRPC handler are local to each service
Template @templates/rust-postgres-microservice
Encryption AES-256-GCM, PCI_ENCRYPTION_KEY (32-byte base64 env var)
Migration tracking pci_service_migrations — a service-scoped table, not the shared seaql_migrations table

Ports

Gateway gRPC (host → container) Service Name
— (internal only, no HTTP/Nginx route) 50057 → 50053 pci-service

50054/50055 are already taken by pii-service/shop-service on the host side — pci-service’s host mapping was deliberately picked to avoid that collision; the container-internal port (50053) is identical to every other Rust gRPC-only service’s convention.

Data

Table Purpose
user_pci_attributes Generic EAV rows, unique index on (tenant_id, entity_type, entity_id, attribute_key) — same shape as pii-service’s user_pii_attributes, card-data values only (card token, last 4, brand).
row_attribute_audit_log One row per UpsertAttributes/GetAttributes/DeleteAttributes call — same table name and shape as pii-service’s own, different schema.

Implementation Notes

  • The entire domain/service layer (RowAttribute* types, RowAttributeService, the AES-256-GCM cipher) is shared with pii-service through rust-lang-core-lib — only the compile-time macro attributes (table_name/schema_name on the SeaORM entity) and the gRPC handler mapping proto messages to/from the shared input types are local to this service. This is the concrete example of “extract only what’s actually identical, leave what’s genuinely per-service in the service.”
  • payment-service is the only confirmed real caller today — wiring a card token/last4/brand into pci-service at the point payment-service records a payment method, rather than payment-service storing card data itself.
  • Schema name "pci-service" (not a shared tenant/pci schema) follows the same per-microservice-schema convention pii-service already set.

Full module reference: pci-service/CLAUDE.md.