provisioning/docs/src/security/kms-service.md

191 lines
5.9 KiB
Markdown
Raw Normal View History

# KMS Service - Key Management Service
A unified Key Management Service for the Provisioning platform with support for multiple backends.
> **Source**: `provisioning/platform/kms-service/`
## Supported Backends
- **Age**: Fast, offline encryption (development)
- **RustyVault**: Self-hosted Vault-compatible API
- **Cosmian KMS**: Enterprise-grade with confidential computing
- **AWS KMS**: Cloud-native key management
- **HashiCorp Vault**: Enterprise secrets management
## Architecture
2026-01-14 01:56:30 +00:00
```
┌─────────────────────────────────────────────────────────┐
│ KMS Service │
├─────────────────────────────────────────────────────────┤
│ REST API (Axum) │
│ ├─ /api/v1/kms/encrypt POST │
│ ├─ /api/v1/kms/decrypt POST │
│ ├─ /api/v1/kms/generate-key POST │
│ ├─ /api/v1/kms/status GET │
│ └─ /api/v1/kms/health GET │
├─────────────────────────────────────────────────────────┤
│ Unified KMS Service Interface │
├─────────────────────────────────────────────────────────┤
│ Backend Implementations │
│ ├─ Age Client (local files) │
│ ├─ RustyVault Client (self-hosted) │
│ └─ Cosmian KMS Client (enterprise) │
└─────────────────────────────────────────────────────────┘
2026-01-12 04:42:18 +00:00
```
## Quick Start
### Development Setup (Age)
2026-01-14 01:56:30 +00:00
```
# 1. Generate Age keys
mkdir -p ~/.config/provisioning/age
age-keygen -o ~/.config/provisioning/age/private_key.txt
age-keygen -y ~/.config/provisioning/age/private_key.txt > ~/.config/provisioning/age/public_key.txt
# 2. Set environment
export PROVISIONING_ENV=dev
# 3. Start KMS service
cd provisioning/platform/kms-service
cargo run --bin kms-service
2026-01-12 04:42:18 +00:00
```
### Production Setup (Cosmian)
2026-01-14 01:56:30 +00:00
```
# Set environment variables
export PROVISIONING_ENV=prod
export COSMIAN_KMS_URL=https://your-kms.example.com
export COSMIAN_API_KEY=your-api-key-here
# Start KMS service
cargo run --bin kms-service
2026-01-12 04:42:18 +00:00
```
## REST API Examples
### Encrypt Data
2026-01-14 01:56:30 +00:00
```
curl -X POST http://localhost:8082/api/v1/kms/encrypt \
-H "Content-Type: application/json" \
-d '{
"plaintext": "SGVsbG8sIFdvcmxkIQ==",
"context": "env=prod,service=api"
}'
2026-01-12 04:42:18 +00:00
```
### Decrypt Data
2026-01-14 01:56:30 +00:00
```
curl -X POST http://localhost:8082/api/v1/kms/decrypt \
-H "Content-Type: application/json" \
-d '{
"ciphertext": "...",
"context": "env=prod,service=api"
}'
2026-01-12 04:42:18 +00:00
```
## Nushell CLI Integration
2026-01-14 01:56:30 +00:00
```
# Encrypt data
"secret-data" | kms encrypt
"api-key" | kms encrypt --context "env=prod,service=api"
# Decrypt data
$ciphertext | kms decrypt
# Generate data key (Cosmian only)
kms generate-key
# Check service status
kms status
kms health
# Encrypt/decrypt files
kms encrypt-file config.yaml
kms decrypt-file config.yaml.enc
2026-01-12 04:42:18 +00:00
```
## Backend Comparison
| Feature | Age | RustyVault | Cosmian KMS | AWS KMS | Vault |
2026-01-12 04:42:18 +00:00
| --------- | ----- | ------------ | ------------- | --------- | ------- |
| **Setup** | Simple | Self-hosted | Server setup | AWS account | Enterprise |
| **Speed** | Very fast | Fast | Fast | Fast | Fast |
| **Network** | No | Yes | Yes | Yes | Yes |
| **Key Rotation** | Manual | Automatic | Automatic | Automatic | Automatic |
| **Data Keys** | No | Yes | Yes | Yes | Yes |
| **Audit Logging** | No | Yes | Full | Full | Full |
| **Confidential** | No | No | Yes (SGX/SEV) | No | No |
| **License** | MIT | Apache 2.0 | Proprietary | Proprietary | BSL/Enterprise |
| **Cost** | Free | Free | Paid | Paid | Paid |
| **Use Case** | Dev/Test | Self-hosted | Privacy | AWS Cloud | Enterprise |
## Integration Points
1. **Config Encryption** (SOPS Integration)
2. **Dynamic Secrets** (Provider API Keys)
3. **SSH Key Management**
4. **Orchestrator** (Workflow Data)
5. **Control Center** (Audit Logs)
## Deployment
### Docker
2026-01-14 01:56:30 +00:00
```
FROM rust:1.70 as builder
WORKDIR /app
COPY . .
RUN cargo build --release
FROM debian:bookworm-slim
RUN apt-get update && \
apt-get install -y ca-certificates && \
rm -rf /var/lib/apt/lists/*
COPY --from=builder /app/target/release/kms-service /usr/local/bin/
ENTRYPOINT ["kms-service"]
2026-01-12 04:42:18 +00:00
```
### Kubernetes
2026-01-14 01:56:30 +00:00
```
apiVersion: apps/v1
kind: Deployment
metadata:
name: kms-service
spec:
replicas: 2
template:
spec:
containers:
- name: kms-service
image: provisioning/kms-service:latest
env:
- name: PROVISIONING_ENV
value: "prod"
- name: COSMIAN_KMS_URL
value: "https://kms.example.com"
ports:
- containerPort: 8082
2026-01-12 04:42:18 +00:00
```
## Security Best Practices
1. **Development**: Use Age for dev/test only, never for production secrets
2. **Production**: Always use Cosmian KMS with TLS verification enabled
3. **API Keys**: Never hardcode, use environment variables
4. **Key Rotation**: Enable automatic rotation (90 days recommended)
5. **Context Encryption**: Always use encryption context (AAD)
6. **Network Access**: Restrict KMS service access with firewall rules
7. **Monitoring**: Enable health checks and monitor operation metrics
## Related Documentation
- **User Guide**: [KMS Guide](../user/RUSTYVAULT_KMS_GUIDE.md)
- **Migration**: [KMS Simplification](../migration/KMS_SIMPLIFICATION.md)