* feat(kms): implement key management service with local and vault backends Signed-off-by: junxiang Mu <1948535941@qq.com> * feat(kms): enhance security with zeroize for sensitive data and improve key management Signed-off-by: junxiang Mu <1948535941@qq.com> * remove Hashi word Signed-off-by: junxiang Mu <1948535941@qq.com> * refactor: remove unused request structs from kms handlers Signed-off-by: junxiang Mu <1948535941@qq.com> --------- Signed-off-by: junxiang Mu <1948535941@qq.com>
5.3 KiB
Dynamic KMS Configuration Playbook
RustFS exposes a first-class admin REST API that allows you to configure, start, stop, and reconfigure the KMS subsystem without restarting the server. This document walks through common operational scenarios.
Prerequisites
- RustFS is running and reachable on the admin endpoint (typically
http(s)://<host>/rustfs/admin/v3). - You have admin access and credentials (access key/secret or session token) with the
ServerInfoAdminActionpermission. - Optional:
awscurlor another SigV4-aware HTTP client to sign admin requests.
Before starting, confirm the KMS service manager is initialised:
awscurl --service s3 --region us-east-1 \
--access_key admin --secret_key admin \
http://localhost:9000/rustfs/admin/v3/kms/status
The initial response shows "status": "NotConfigured".
Initial Configuration Flow
-
Submit the configuration
awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ -X POST -d '{ "backend_type": "local", "key_dir": "/var/lib/rustfs/kms-keys", "default_key_id": "rustfs-master", "enable_cache": true, "cache_ttl_seconds": 900 }' \ http://localhost:9000/rustfs/admin/v3/kms/configure -
Start the service
awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ -X POST http://localhost:9000/rustfs/admin/v3/kms/start -
Verify
awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ http://localhost:9000/rustfs/admin/v3/kms/statusLook for
"status": "Running"and a backend summary.
Switching to Vault
To migrate from the local backend to Vault:
-
Prepare Vault:
vault secrets enable transit vault secrets enable -path=secret kv-v2 vault write transit/keys/rustfs-master type=aes256-gcm96 -
Configure the new backend without stopping service:
awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ -X POST -d '{ "backend_type": "vault", "address": "https://vault.example.com:8200", "auth_method": { "approle": { "role_id": "...", "secret_id": "..." } }, "mount_path": "transit", "kv_mount": "secret", "key_path_prefix": "rustfs/kms/keys", "default_key_id": "rustfs-master", "retry_attempts": 5, "timeout_seconds": 60 }' \ http://localhost:9000/rustfs/admin/v3/kms/reconfigure -
Confirm the new backend is active via
/kms/status. -
Run test uploads with
SSE-KMSheaders to ensure the new backend is serving requests.
Rotating the Default Key
-
Create a new key using the key management API:
awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ -X POST -d '{ "KeyUsage": "ENCRYPT_DECRYPT", "Description": "rotation-2024-09" }' \ http://localhost:9000/rustfs/admin/v3/kms/keys -
Set it as default via
reconfigure:awscurl --service s3 --region us-east-1 \ --access_key admin --secret_key admin \ -X POST -d '{ "backend_type": "vault", "default_key_id": "rotation-2024-09" }' \ http://localhost:9000/rustfs/admin/v3/kms/reconfigureOnly the fields supplied in the payload are updated; omitted fields keep their previous values.
-
Validate by uploading a new object and checking that
x-amz-server-side-encryption-aws-kms-key-idreports the new key.
Rolling Cache or Timeout Changes
Caching knobs help tune latency. To adjust them at runtime:
awscurl --service s3 --region us-east-1 \
--access_key admin --secret_key admin \
-X POST -d '{
"enable_cache": true,
"max_cached_keys": 2048,
"cache_ttl_seconds": 600,
"timeout_seconds": 20
}' \
http://localhost:9000/rustfs/admin/v3/kms/reconfigure
Pausing the KMS Service
Stopping the service keeps configuration in place but disables new KMS operations. Existing SSE objects remain accessible only if their metadata allows offline decryption.
awscurl --service s3 --region us-east-1 \
--access_key admin --secret_key admin \
-X POST http://localhost:9000/rustfs/admin/v3/kms/stop
Restart later with /kms/start.
Automation Tips
- Wrap REST calls in an idempotent script (see
scripts/for examples) so you can re-run configuration safely. - Use
--test-threads=1when running KMS e2e suites in CI; they spin up real servers and Vault instances. - In Kubernetes, run the configuration script as an init job that waits for both RustFS and Vault readiness before calling
/kms/configure. - Emit events to your observability platform: successful reconfigurations generate structured logs with the backend summary.
Rollback Strategy
If a new configuration introduces errors:
- Call
/kms/reconfigurewith the previous payload (keep a snapshot in version control). - If the backend is unreachable, call
/kms/stopto protect data from partial writes. - Investigate logs under
rustfs::kms::*and Vault audit logs. - Once the issue is resolved, reapply the desired configuration and restart.
Dynamic configuration makes backend maintenance safe and repeatable—ensure every change is scripted and traceable.