fix: key separation, audit coverage, tenant store semantics - #7
Merged
Conversation
Security: - Derive audit HMAC key and tenant master key via HKDF with domain-separated info strings instead of reusing raw master key bytes. The existing derive_audit_key() was already written but never wired into the Vault builder. - Add audit event emission to encrypt_field_deterministic and decrypt_field_deterministic. Previously only the randomized encrypt/decrypt paths were audited. Bug fix: - InMemoryKeyRepository::store_tenant_key now returns Ok(()) when a tenant key already exists (matching PostgreSQL ON CONFLICT DO NOTHING), instead of erroneously returning TenantAlreadyErased. Improvements: - TenantKeyManager::get_tenant_key: eliminate redundant lock-drop- relock pattern. Clone wrapped_key under single lock acquisition. - Add Vault::decrypt_stream_with_version for explicit DEK version. - Add defensive u32 overflow guard in encrypt_stream chunk count. - Add 20 integration tests covering all changes with e2e production simulation. Bump version to 0.1.1.
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
derive_audit_key()that was never called.InMemoryKeyRepository::store_tenant_keynow returnsOk(())for existing active keys, matching PostgreSQLON CONFLICT DO NOTHINGsemantics.TenantKeyManager::get_tenant_key.Vault::decrypt_stream_with_versionfor explicit DEK version control.u32overflow guard in stream encryption chunk count.Bump version to 0.1.1.
Test plan
cargo test --workspace— 370 tests pass (350 unit + 20 new)cargo clippy --all-targets --all-features -- -D warnings— 0 warningscargo fmt --all -- --check— passcargo doc --no-deps --all-features— pass