-
Notifications
You must be signed in to change notification settings - Fork 30
feat(cachet): add encrypt feature for authenticated value encryption
#558
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
schgoo
wants to merge
33
commits into
main
Choose a base branch
from
cachet_encrypt
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,924
−447
Open
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
e2cfa1b
Add bytes encryption layer for cachet
schgoo cc909f4
add decrypt failed event and some more documentation
schgoo 3c91aa6
Fix PR comments
schgoo 3b0e843
Make encryption a plugin. Add symcrypt option
schgoo 9fe3bb0
Add symcrypt encryption example
schgoo 89a1f10
Remove symcrypt built-in. No opinion on encryption crate for now, onl…
schgoo 4baabe2
doc fix
schgoo 0f1235e
Fix coverage job
schgoo 1819df7
Mutation test and test fixes
schgoo d3e4bc4
Coverage
schgoo cfbe843
Merge branch 'main' into cachet_encrypt
schgoo 42c7fa9
Potential fix for pull request finding
schgoo 8525616
Rename ciphers to protectors, following industry conventions. Add Moc…
schgoo 67c5d14
Merge with cachet_encrypt
schgoo 2b1ede5
Don't use hardcoded nonce even in mock implementation
schgoo 23fcc7b
Better fix
schgoo 3117baa
Merge with main
schgoo 0389c64
Reorganization
schgoo a282c8b
Init tracing in encryption tests
schgoo d953132
Ignore mutant tests in mock value protector
schgoo edbc687
PR comment nits
schgoo 24dd547
Merge branch 'main' of https://github.com/microsoft/oxidizer into cac…
schgoo 0e53fe7
PR comment fix. Small bugfix
schgoo 9f2613e
Merge with main
schgoo 572982c
Merge branch 'main' into cachet_encrypt
schgoo 02108f5
Merge branch 'main' of https://github.com/microsoft/oxidizer into cac…
schgoo d05a356
Doc updates for PR comment
schgoo d383fe2
Merge branch 'cachet_encrypt' of https://github.com/microsoft/oxidize…
schgoo 69e63be
PR comment fixes. Add test-util cache event handler
schgoo b19d807
Add test for fallback to second remote tier when first has soft failu…
schgoo 53b335e
Lots of refactoring.
schgoo ddada8c
Some comment changes
schgoo ec21d73
Merge with main
schgoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| //! The `.protect_with()` pipeline stage for the serialization builder. | ||
| //! | ||
| //! `.protect_with(protector)` is available on a [`SerializeBuilder`] that has not yet | ||
| //! been protected. It appends an authenticated-protection stage to the value pipeline | ||
| //! and flips the builder's `PROTECTED` type-state to `true`, so the method disappears | ||
| //! and protection cannot be configured twice. | ||
|
|
||
| use std::marker::PhantomData; | ||
| use std::sync::Arc; | ||
|
|
||
| use super::serialize::SerializeBuilder; | ||
| use crate::ValueProtector; | ||
| use crate::transform::ProtectorCodec; | ||
|
|
||
| impl<K, V, Pre> SerializeBuilder<K, V, Pre, false> { | ||
| /// Protects values with the given [`ValueProtector`] before they reach any storage | ||
| /// tier, binding each to its storage key. | ||
| /// | ||
| /// Available after [`serialize`](crate::CacheBuilder::serialize), and only if | ||
| /// protection isn't already configured. The protector — backed by your approved | ||
| /// cryptographic library — receives the storage key as context and must bind it (see | ||
| /// the [`ValueProtector`] contract). Keys are never protected; a value that fails | ||
| /// authentication reads as a miss, so the fallback chain continues to the next tier. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```ignore | ||
| /// let cache = Cache::builder::<String, String>(clock) | ||
| /// .memory() | ||
| /// .serialize() | ||
| /// .protect_with(my_protector) // any `ValueProtector` implementation | ||
| /// .fallback(remote) | ||
| /// .build(); | ||
| /// ``` | ||
| #[must_use] | ||
| pub fn protect_with(self, protector: impl ValueProtector + 'static) -> SerializeBuilder<K, V, Pre, true> { | ||
| let protect = ProtectorCodec::new(Arc::new(protector), self.telemetry.clone()); | ||
| SerializeBuilder { | ||
| pre: self.pre, | ||
| pool: self.pool, | ||
| protect: Some(Box::new(protect)), | ||
| clock: self.clock, | ||
| telemetry: self.telemetry, | ||
| stampede_protection: self.stampede_protection, | ||
| _phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new per-access protection stage has no benchmark or allocation guard — Performance · Low · Structural
Every insert reaching a protected fallback and every protected fallback hit executes serialization, context construction, an additional dynamic codec stage, and the caller's protector. The existing
cachetbenchmarks cover plain wrapper/fallback operations but no serialize/protect path, so this hot-path cost and its allocations per operation can regress without evidence. No magnitude is claimed here; the path frequency is one protection call per affected remote-tier access. This partially misses Pragmatic Rust guideline M-HOTPATH, which requires identifying, profiling, and optimizing the hot path early.Direction: Add paired benchmarks for protected insert and fallback hit across representative payload sizes and single-/multi-span keys, recording wall time, instruction count, and allocations per operation against an unprotected serialization baseline.
Done when: The path has a reproducible baseline and regression gate, and any optimization is resolved by measurement—landed with evidence or closed as not worthwhile.