app-storage: deterministic mock key per app_name#72
Merged
jgowdy-godaddy merged 1 commit intomainfrom Apr 17, 2026
Merged
Conversation
The ENCLAVEAPP_MOCK_STORAGE path added in #71 constructed a fresh MockEncryptionStorage via `::new()`, which generated a random AES-256 key. That breaks any test suite whose parent `cargo test` process writes encrypted state and then spawns a child binary (e.g. via `assert_cmd::cargo_bin(...)`) that reads it back — the child's `MockEncryptionStorage` has a different random key and `decrypt` fails with `aead::Error`. Derive the mock key deterministically from the app name: `SHA-256("enclaveapp-app-storage mock v1\0" || app_name)`. Every process instantiating storage for the same app now lands on the same AES key, so cross-process tests succeed. The derivation is explicitly non-secret — anyone with the app name can recompute it — which is fine because the mock is test-only. The existing `::new()` / `::default()` random path stays for consumers that want that semantics, and the `decrypt_wrong_key_fails` test still covers it.
jgowdy-godaddy
pushed a commit
that referenced
this pull request
Apr 17, 2026
#71 made the mock backend always-compiled so ENCLAVEAPP_MOCK_STORAGE could be honored at runtime without cargo feature gymnastics. That is a security hole for release binaries: anyone setting the env var on a production install would downgrade the hardware-backed backend to an AES-in-RAM mock. Restore the compile-time gate: - `mock` cargo feature opt-in, with aes-gcm/rand/sha2 as optional deps only pulled in by the feature. - `mock` module, `MockEncryptionStorage` re-export, `MOCK_STORAGE_ENV` constant, and the env-var check inside `create_encryption_storage` all gated on `#[cfg(feature = "mock")]`. - Release builds (no --features mock) have no path to the mock at all — setting ENCLAVEAPP_MOCK_STORAGE in production is a no-op. - Test builds enable the feature via downstream `[dev-dependencies]` with `features = ["mock"]`; cargo unifies features during `cargo test`, so the env var works in CI as intended. Keeps #72's deterministic key derivation inside the gated mock module so cross-process test spawning still works.
4 tasks
jgowdy-godaddy
added a commit
that referenced
this pull request
Apr 17, 2026
#71 made the mock backend always-compiled so ENCLAVEAPP_MOCK_STORAGE could be honored at runtime without cargo feature gymnastics. That is a security hole for release binaries: anyone setting the env var on a production install would downgrade the hardware-backed backend to an AES-in-RAM mock. Restore the compile-time gate: - `mock` cargo feature opt-in, with aes-gcm/rand/sha2 as optional deps only pulled in by the feature. - `mock` module, `MockEncryptionStorage` re-export, `MOCK_STORAGE_ENV` constant, and the env-var check inside `create_encryption_storage` all gated on `#[cfg(feature = "mock")]`. - Release builds (no --features mock) have no path to the mock at all — setting ENCLAVEAPP_MOCK_STORAGE in production is a no-op. - Test builds enable the feature via downstream `[dev-dependencies]` with `features = ["mock"]`; cargo unifies features during `cargo test`, so the env var works in CI as intended. Keeps #72's deterministic key derivation inside the gated mock module so cross-process test spawning still works. Co-authored-by: Jay Gowdy <jay@gowdy.me>
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
Follow-up to #71. `ENCLAVEAPP_MOCK_STORAGE=1` path was picking a random AES key per process, which breaks cross-process integration tests (parent encrypts, child spawned by assert_cmd reads — different random key → `aead::Error`). Derive the key deterministically from `app_name` so every process for a given app lands on the same key.
Test plan