-
Notifications
You must be signed in to change notification settings - Fork 12
Add native secret-store config resolution #1036
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
base: main
Are you sure you want to change the base?
Changes from all commits
00de4e9
0fdfcbe
2783e00
3dc7370
0db2e11
3e2b3d2
b47ced8
58730d7
1b17ce0
76f6f13
44e9eaf
3f6e29d
d71c660
6c35ce9
43c7577
edfbcb0
22176da
3b2c64c
c7c382a
55f0a23
e45ff8e
9831ee4
3c48d39
71df1aa
4258a6b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ use trusted_server_core::auction::endpoints::handle_auction; | |
| use trusted_server_core::auction::{AuctionOrchestrator, build_orchestrator}; | ||
| use trusted_server_core::cache_policy::EdgeCacheHeader; | ||
| #[cfg(target_arch = "wasm32")] | ||
| use trusted_server_core::config_payload::settings_from_config_blob; | ||
| use trusted_server_core::config_payload::{DEFAULT_SECRET_STORE_ID, settings_from_config_blob}; | ||
| use trusted_server_core::ec::EcContext; | ||
| use trusted_server_core::ec::admin::{ | ||
| admin_ec_lookup_not_supported as core_admin_ec_lookup_not_supported, | ||
|
|
@@ -22,6 +22,8 @@ use trusted_server_core::ec::registry::PartnerRegistry; | |
| use trusted_server_core::error::{IntoHttpResponse as _, TrustedServerError}; | ||
| use trusted_server_core::integrations::{IntegrationRegistry, ProxyDispatchInput}; | ||
| use trusted_server_core::platform::RuntimeServices; | ||
| #[cfg(target_arch = "wasm32")] | ||
| use trusted_server_core::platform::StoreName; | ||
| use trusted_server_core::proxy::{ | ||
| handle_first_party_click, handle_first_party_proxy, handle_first_party_proxy_rebuild, | ||
| handle_first_party_proxy_sign, | ||
|
|
@@ -44,11 +46,23 @@ use crate::platform::build_runtime_services; | |
| // --------------------------------------------------------------------------- | ||
|
|
||
| #[cfg(target_arch = "wasm32")] | ||
| static CLOUDFLARE_CONFIG_JSON: std::sync::OnceLock<String> = std::sync::OnceLock::new(); | ||
| thread_local! { | ||
| static CLOUDFLARE_CONFIG_JSON: std::cell::OnceCell<String> = const { std::cell::OnceCell::new() }; | ||
| static CLOUDFLARE_ENV: std::cell::OnceCell<worker::Env> = const { std::cell::OnceCell::new() }; | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
| } | ||
|
|
||
| #[cfg(target_arch = "wasm32")] | ||
| pub fn set_cloudflare_config_json(value: String) { | ||
| let _ = CLOUDFLARE_CONFIG_JSON.set(value); | ||
| CLOUDFLARE_CONFIG_JSON.with(|slot| { | ||
| let _ = slot.set(value); | ||
| }); | ||
| } | ||
|
|
||
| #[cfg(target_arch = "wasm32")] | ||
| pub fn set_cloudflare_env(env: worker::Env) { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 thinking —
Storing the current env each request would remove the question entirely: thread_local! {
static CLOUDFLARE_ENV: std::cell::RefCell<Option<worker::Env>> =
const { std::cell::RefCell::new(None) };
}
#[cfg(target_arch = "wasm32")]
pub fn set_cloudflare_env(env: worker::Env) {
CLOUDFLARE_ENV.with(|slot| {
slot.replace(Some(env));
});
}with the reader in |
||
| CLOUDFLARE_ENV.with(|slot| { | ||
| let _ = slot.set(env); | ||
| }); | ||
| } | ||
|
|
||
| /// Application state built once at startup and shared across all requests. | ||
|
|
@@ -76,18 +90,22 @@ fn load_startup_settings() -> Result<Settings, Report<TrustedServerError>> { | |
|
|
||
| #[cfg(not(target_arch = "wasm32"))] | ||
| fn load_startup_settings() -> Result<Settings, Report<TrustedServerError>> { | ||
| Settings::from_toml(include_str!("../../../trusted-server.example.toml")) | ||
| Err(Report::new(TrustedServerError::Configuration { | ||
| message: "Cloudflare startup settings require a Worker config binding".to_string(), | ||
| }) | ||
| .attach("use TrustedServerApp::routes_with_settings for host tests")) | ||
| } | ||
|
|
||
| #[cfg(target_arch = "wasm32")] | ||
| fn settings_from_cloudflare_config_json() -> Result<Settings, Report<TrustedServerError>> { | ||
| let raw_config = CLOUDFLARE_CONFIG_JSON.get().ok_or_else(|| { | ||
| let raw_config = CLOUDFLARE_CONFIG_JSON.with(|slot| slot.get().cloned()); | ||
| let raw_config = raw_config.ok_or_else(|| { | ||
| Report::new(TrustedServerError::Configuration { | ||
| message: "Cloudflare TRUSTED_SERVER_CONFIG is required".to_string(), | ||
| }) | ||
| .attach("set TRUSTED_SERVER_CONFIG to JSON containing the app_config blob envelope") | ||
| })?; | ||
| let value: serde_json::Value = serde_json::from_str(raw_config).map_err(|error| { | ||
| let value: serde_json::Value = serde_json::from_str(&raw_config).map_err(|error| { | ||
| Report::new(TrustedServerError::Configuration { | ||
| message: "invalid Cloudflare TRUSTED_SERVER_CONFIG JSON".to_string(), | ||
| }) | ||
|
|
@@ -101,7 +119,16 @@ fn settings_from_cloudflare_config_json() -> Result<Settings, Report<TrustedServ | |
| message: "Cloudflare TRUSTED_SERVER_CONFIG missing app_config".to_string(), | ||
| }) | ||
| })?; | ||
| settings_from_config_blob(envelope) | ||
| let env = CLOUDFLARE_ENV | ||
| .with(|slot| slot.get().cloned()) | ||
| .ok_or_else(|| { | ||
| Report::new(TrustedServerError::Configuration { | ||
| message: "Cloudflare Worker environment is unavailable during startup".to_string(), | ||
| }) | ||
| })?; | ||
| let secret_store = crate::platform::CloudflareSecretStoreAdapter { env }; | ||
| let default_secret_store = StoreName::from(DEFAULT_SECRET_STORE_ID); | ||
|
ChristianPavilonis marked this conversation as resolved.
|
||
| settings_from_config_blob(envelope, &secret_store, &default_secret_store) | ||
| } | ||
|
|
||
| /// Build the application state from explicit settings. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.