mirror of
https://github.com/hanzoai/kms.git
synced 2026-10-17 11:18:16 +00:00
The current KMS is a pure Go binary. Per DEPRECATED.md the Node.js + PostgreSQL + Redis Infisical fork was replaced — "no Node.js / Postgres / Redis dependencies." The KMS Go runtime contains zero Redis references; the `REDIS_URL` / `REDIS_HOST` knobs in these examples were leftover from the deprecated stack and are never read. Remove the orphaned Redis declarations from the three HSM compose examples and the Zymbit k8s manifest: - zymbit-hsm/compose.yml: redis service, REDIS_URL env, depends_on, volume - zymbit-hsm/kubernetes-deployment.yaml: Redis Deployment/Service/PVC, REDIS_HOST/PORT ConfigMap keys, redis egress NetworkPolicy rule - aws-cloudhsm/compose.yml: redis service, REDIS_URL env, depends_on, volume - google-cloud-hsm/compose.yml: redis service, REDIS_URL env, depends_on, volume No consumer migration needed — nothing read Redis. Postgres left intact.
Zymbit HSM Integration Examples
This directory contains example configurations for deploying KMS with Zymbit HSM support on various platforms.
Prerequisites
- Hardware: Zymbit SCM/HSM4 module installed on supported device (Raspberry Pi, Jetson, etc.)
- Software: Zymbit SDK and PKCS#11 library installed
- Configuration: Zymbit device initialized with PIN set
Files
docker-compose.yml- Docker Compose deployment with Zymbit HSMkubernetes-deployment.yaml- Full Kubernetes deployment manifests.env.example- Environment variable template
Quick Start
Docker Compose
-
Prepare environment:
# Copy example environment file cp .env.example .env.secrets # Edit .env.secrets with actual values nano .env.secrets -
Generate secrets:
# Generate encryption key openssl rand -hex 32 # Generate auth secret openssl rand -hex 32 -
Start services:
docker-compose up -d -
Verify deployment:
# Check logs docker-compose logs -f kms # Health check curl http://localhost/api/status/health
Kubernetes
-
Label nodes with Zymbit hardware:
kubectl label nodes <node-name> hardware.zymbit.com/hsm=true -
Update secrets in
kubernetes-deployment.yaml:- Replace
HSM_PINwith actual Zymbit PIN - Replace
ENCRYPTION_KEYwith generated key - Replace
AUTH_SECRETwith generated secret - Replace
DB_PASSWORDwith secure password
- Replace
-
Deploy to cluster:
kubectl apply -f kubernetes-deployment.yaml -
Verify deployment:
# Check pod status kubectl get pods -n kms-zymbit # View logs kubectl logs -n kms-zymbit deployment/kms # Port forward for testing kubectl port-forward -n kms-zymbit svc/kms-service 8080:80 # Health check curl http://localhost:8080/api/status/health
Configuration
Required Environment Variables
| Variable | Description | Example |
|---|---|---|
HSM_ENABLED |
Enable HSM support | true |
HSM_PROVIDER |
HSM provider type | zymbit |
HSM_LIB_PATH |
PKCS#11 library path | /usr/lib/libzk_pkcs11.so |
HSM_PIN |
Zymbit PIN | 12345678 |
HSM_SLOT |
HSM slot number | 0 |
HSM_KEY_LABEL |
Key identifier | lux-kms-key |
ENCRYPTION_KEY |
KMS encryption key | 32-byte hex |
AUTH_SECRET |
Auth secret | Random string |
DB_CONNECTION_URI |
Database URI | postgresql://... |
Optional Environment Variables
| Variable | Description | Default |
|---|---|---|
ZYMBIT_DEVICE_PATH |
Zymbit device path | /dev/zymkey |
ZYMBIT_TAMPER_CHECK |
Enable tamper detection | true |
LOG_LEVEL |
Logging level | info |
JWT_EXPIRATION |
JWT expiration | 1h |
REDIS_URL |
Redis connection | redis://redis:6379 |
Security Best Practices
-
Secrets Management:
- Never commit actual secrets to version control
- Use Kubernetes secrets or external secret managers
- Rotate secrets regularly
-
Physical Security:
- Install Zymbit in tamper-evident enclosure
- Monitor tamper detection events
- Enable secure boot
-
Network Security:
- Use NetworkPolicy to restrict traffic
- Enable TLS for all external communication
- Use private networks for database access
-
Access Control:
- Use RBAC for Kubernetes deployments
- Limit privileged container access
- Audit all HSM operations
Monitoring
Prometheus Metrics
KMS exposes Prometheus metrics at /metrics:
# View all metrics
curl http://localhost/metrics
# Key HSM metrics:
# - hsm_operations_total{operation="encrypt"}
# - hsm_operations_total{operation="decrypt"}
# - hsm_operation_duration_seconds
# - hsm_tamper_checks_total
Health Checks
# Overall health
curl http://localhost/api/status/health
# HSM-specific health
curl http://localhost/api/v1/hsm/health
Troubleshooting
Common Issues
-
Device not found:
# Check device ls -l /dev/zymkey # Rebind if needed sudo zkbind -i2c 1 -
Permission denied:
# Check device permissions ls -l /dev/zymkey /dev/i2c-1 # Docker needs --privileged or --device flags # Kubernetes needs privileged: true -
PIN errors:
# Reset PIN sudo zksetpin # Ensure PIN matches HSM_PIN in secrets -
Key not found:
# List keys pkcs11-tool --module /usr/lib/libzk_pkcs11.so --login --list-objects # Create key if missing pkcs11-tool --module /usr/lib/libzk_pkcs11.so --login \ --keypairgen --key-type AES:32 --label "lux-kms-key"
Performance Tuning
Docker
# In docker-compose.yml
services:
kms:
deploy:
resources:
limits:
cpus: '1.0'
memory: 512M
reservations:
cpus: '0.5'
memory: 256M
Kubernetes
# In kubernetes-deployment.yaml
resources:
requests:
memory: "256Mi"
cpu: "250m"
limits:
memory: "512Mi"
cpu: "500m"
Backup and Recovery
Database Backup
# Docker Compose
docker-compose exec postgres pg_dump -U kms kms > backup.sql
# Kubernetes
kubectl exec -n kms-zymbit postgres-0 -- pg_dump -U kms kms > backup.sql
Key Backup
Important: Zymbit keys are hardware-bound and cannot be exported. For disaster recovery:
- Use multiple Zymbit devices with replicated keys
- Maintain backup devices in secure location
- Document key recreation procedures