feat(vault): add encryption-at-rest vault for environment variables#219
Open
feat(vault): add encryption-at-rest vault for environment variables#219
Conversation
Add a new `moltis-vault` crate that encrypts sensitive data at rest using XChaCha20-Poly1305 AEAD with Argon2id-derived keys. The vault integrates transparently with the authentication flow: it initializes on first password setup, auto-unseals on login, and rotates keys on password change. Key hierarchy: Password → Argon2id → KEK → unwrap DEK → encrypt data. A recovery key (128-bit, shown once at setup) provides emergency access. Integration points: - CredentialStore: env vars encrypted when vault is unsealed - auth_middleware: vault_guard blocks API when sealed (423 Locked) - auth_routes: vault status/unlock/recovery endpoints + hooks in setup/login/change-password handlers - GonData: vault_status exposed to frontend - Feature flag: `vault` (default on in gateway + CLI) Includes 38 vault crate tests, 3 auth integration tests, and documentation in docs/src/vault.md.
Contributor
Merging this PR will not alter performance
Comparing Footnotes
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
moltis-vaultcrate implementing XChaCha20-Poly1305 encryption-at-rest with Argon2id key derivation423 Lockedwhen sealed (not when uninitialized)env:{key}) to prevent ciphertext swappingwindow.__MOLTIS__.vaultStatus) for frontenddocs/src/vault.mdCrate structure (
crates/vault/)vault.rsVaultstruct with init/unseal/seal/encrypt/decrypt/change_passwordkdf.rsxchacha20.rskey_wrap.rsrecovery.rsmigration.rserror.rsVaultErrorenum via thiserrortraits.rsVaultBackendtrait for testingIntegration points
auth_routes.rs: Vault init on setup (returns recovery key), unseal on login, re-wrap on password changeauth_middleware.rs: Vault guard layer blocks API when sealedcredential_store.rs: Encrypt/decrypt env vars via vaultstate.rs:vault: Option<Arc<Vault>>field on GatewayStateserver.rs: Vault initialization at startuptemplates.rs: Vault status in gon dataValidation
Completed
cargo check -p moltis-vault— compiles cleancargo test -p moltis-vault— 38 tests passcargo test -p moltis-auth --features vault— 40 tests passcargo test -p moltis-gateway— 49 tests passcargo check -p moltis(full CLI) — compiles cleanjust format— formattedmdbook build— docs build successfullyRemaining
local-validate.sh(requires PR number)Manual QA