-
Notifications
You must be signed in to change notification settings - Fork 0
Add provider-neutral secret store support #230
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
Merged
Merged
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
2e9a547
chore: add .worktrees/ to .gitignore
e3250bb
feat(core): add SecretStore trait, SecretHandle, and contract test macro
766ed91
refactor(core): use Bytes::into() for zero-copy UTF-8 conversion in S…
6c8cc08
feat(core): add secret_handle() to RequestContext and Secrets extractor
6aadb54
feat(core): add [stores.secrets] manifest schema and secret_store_name()
514f164
feat(fastly): add FastlySecretStore adapter and dispatch_with_secrets
d79d67e
style: apply rustfmt to Task 4 changes
75bdc67
feat(cloudflare): add CloudflareSecretStore adapter and dispatch_with…
ccbfa67
feat(cloudflare): add CloudflareSecretStore adapter and dispatch_with…
8b705f9
feat(axum): add EnvSecretStore for local dev and wire into service/de…
000710b
feat(cli): log secret store binding info during edgezero build
d030304
test: add secret store contract tests across all adapters
9e7b8de
fix(secret-store): address security findings from review
aa53635
test(axum): add TCP integration tests for secret store wiring
a9ac734
feat(demo): add secrets_echo handler and [stores.secrets] manifest co…
9c6746f
docs(guide): document runtime secret store configuration
3da648b
refactor(secret-store): collapse two-trait design into single SecretS…
44f39b3
Address PR review findings on secret-store branch
aca876b
Test uses InMemorySecretStore instead of env mutation
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
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
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,150 @@ | ||
| //! Environment variable secret store for local development. | ||
| //! | ||
| //! Reads secrets from the process environment. Set secrets as environment | ||
| //! variables before starting the dev server: | ||
| //! | ||
| //! ```bash | ||
| //! API_KEY=mysecret cargo edgezero dev | ||
| //! ``` | ||
|
|
||
| use async_trait::async_trait; | ||
| use bytes::Bytes; | ||
| use edgezero_core::secret_store::{SecretError, SecretStore}; | ||
|
|
||
| /// Secret store for local development that reads secrets from environment variables. | ||
| /// | ||
| /// When `[stores.secrets]` is declared in `edgezero.toml`, the dev server | ||
| /// creates an `EnvSecretStore` that reads secrets from the process environment. | ||
| pub struct EnvSecretStore; | ||
|
|
||
| impl EnvSecretStore { | ||
| pub fn new() -> Self { | ||
| Self | ||
| } | ||
| } | ||
|
|
||
| impl Default for EnvSecretStore { | ||
| fn default() -> Self { | ||
| Self::new() | ||
| } | ||
| } | ||
|
|
||
| #[async_trait(?Send)] | ||
| impl SecretStore for EnvSecretStore { | ||
| async fn get_bytes(&self, name: &str) -> Result<Option<Bytes>, SecretError> { | ||
| #[cfg(unix)] | ||
| { | ||
| use std::os::unix::ffi::OsStringExt; | ||
|
|
||
| match std::env::var_os(name) { | ||
| Some(value) => Ok(Some(Bytes::from(value.into_vec()))), | ||
| None => Ok(None), | ||
| } | ||
| } | ||
|
|
||
| #[cfg(not(unix))] | ||
| { | ||
| match std::env::var(name) { | ||
| Ok(value) => Ok(Some(Bytes::from(value.into_bytes()))), | ||
| Err(std::env::VarError::NotPresent) => Ok(None), | ||
| Err(std::env::VarError::NotUnicode(_)) => Err(SecretError::Internal( | ||
| anyhow::anyhow!("secret store returned an invalid Unicode value"), | ||
| )), | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| use bytes::Bytes; | ||
| use std::ffi::OsString; | ||
| use std::sync::OnceLock; | ||
|
|
||
| fn env_guard() -> &'static tokio::sync::Mutex<()> { | ||
| static GUARD: OnceLock<tokio::sync::Mutex<()>> = OnceLock::new(); | ||
| GUARD.get_or_init(|| tokio::sync::Mutex::new(())) | ||
| } | ||
|
|
||
| struct EnvOverride { | ||
|
prk-Jr marked this conversation as resolved.
Outdated
|
||
| key: &'static str, | ||
| original: Option<OsString>, | ||
| } | ||
|
|
||
| impl EnvOverride { | ||
| fn set(key: &'static str, value: impl AsRef<std::ffi::OsStr>) -> Self { | ||
| let original = std::env::var_os(key); | ||
| std::env::set_var(key, value); | ||
| Self { key, original } | ||
| } | ||
|
|
||
| fn clear(key: &'static str) -> Self { | ||
| let original = std::env::var_os(key); | ||
| std::env::remove_var(key); | ||
| Self { key, original } | ||
| } | ||
| } | ||
|
|
||
| impl Drop for EnvOverride { | ||
| fn drop(&mut self) { | ||
| if let Some(ref original) = self.original { | ||
| std::env::set_var(self.key, original); | ||
| } else { | ||
| std::env::remove_var(self.key); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn get_bytes_returns_none_when_var_not_set() { | ||
| let _guard = env_guard().lock().await; | ||
| let _env = EnvOverride::clear("__EDGEZERO_TEST_MISSING_VAR_XYZ__"); | ||
| let store = EnvSecretStore::new(); | ||
| let result = store | ||
| .get_bytes("__EDGEZERO_TEST_MISSING_VAR_XYZ__") | ||
| .await | ||
| .unwrap(); | ||
| assert!(result.is_none()); | ||
| } | ||
|
|
||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn get_bytes_returns_value_when_var_set() { | ||
| let _guard = env_guard().lock().await; | ||
| let _env = EnvOverride::set("__EDGEZERO_TEST_SECRET__", "test_value_123"); | ||
| let store = EnvSecretStore::new(); | ||
| let result = store.get_bytes("__EDGEZERO_TEST_SECRET__").await.unwrap(); | ||
| assert_eq!(result, Some(Bytes::from("test_value_123"))); | ||
| } | ||
|
|
||
| #[cfg(unix)] | ||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn get_bytes_preserves_non_utf8_secret_values() { | ||
| use std::os::unix::ffi::OsStringExt; | ||
|
|
||
| let _guard = env_guard().lock().await; | ||
| let _env = EnvOverride::set( | ||
| "__EDGEZERO_TEST_BINARY_SECRET__", | ||
| OsString::from_vec(vec![0xff, 0x61]), | ||
| ); | ||
| let store = EnvSecretStore::new(); | ||
| let result = store | ||
| .get_bytes("__EDGEZERO_TEST_BINARY_SECRET__") | ||
| .await | ||
| .unwrap(); | ||
| assert_eq!(result, Some(Bytes::from_static(&[0xff, 0x61]))); | ||
| } | ||
|
|
||
| // Contract tests: use InMemorySecretStore since EnvSecretStore needs | ||
| // real env vars, which are unsafe in parallel tests. | ||
| // The EnvSecretStore is tested individually above. | ||
| use edgezero_core::secret_store::InMemorySecretStore; | ||
| use edgezero_core::secret_store_contract_tests; | ||
|
|
||
| secret_store_contract_tests!(env_secret_contract, { | ||
| InMemorySecretStore::new([ | ||
| ("contract_key", Bytes::from("contract_value")), | ||
| ("contract_key_2", Bytes::from("another_value")), | ||
| ]) | ||
| }); | ||
| } | ||
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.
Uh oh!
There was an error while loading. Please reload this page.