Repository navigation
Add pluggable native Geo providers and protected CloudFront ingress #439
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
Changes from all commits
590dff9
93b4177
c8ee48f
5ddc0d3
6f3ebdb
8663acc
1df9f7a
22741b6
7045bcf
414e52a
add18fc
fad18a1
1bd161a
6d07cbc
3a0e5eb
6365062
645703b
302697e
c1cec8e
cf291a1
c02ee54
c77f6a3
d08b764
ab11255
49fb2f4
b818707
5bf4a67
dd34d19
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,7 @@ use tokio::time::{Instant as NativeInstant, sleep_until}; | |
| use crate::config_store::AxumConfigStore; | ||
| use crate::config_store_limits::ConfigStoreLimits; | ||
| use crate::connection::{ConnectionExit, serve_http1_with_shutdown}; | ||
| use crate::geo::NativeGeo; | ||
| use crate::ingress_config::AxumIngressConfig; | ||
| use crate::key_value_store::PersistentKvStore; | ||
| use crate::native_stores::{self, NativeSourcePlan, NativeStoreOverrides, NativeStoreSource}; | ||
|
|
@@ -511,9 +512,10 @@ fn serve_local( | |
| ) | ||
| } | ||
|
|
||
| #[derive(Clone, Debug)] | ||
| #[derive(Clone)] | ||
|
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. ♻ Keep A small manual impl, matching the redaction style already used for impl fmt::Debug for NativeGeo {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Off => f.write_str("Off"),
Self::Selected { policy, id, .. } => f
.debug_struct("Selected")
.field("policy", policy)
.field("id", id)
.finish_non_exhaustive(),
}
}
} |
||
| struct NativeHosting { | ||
| diagnostics: NativeDiagnosticsHandle, | ||
| geo: NativeGeo, | ||
| policy: TrustedProxyPolicy, | ||
| request_records: bool, | ||
| } | ||
|
|
@@ -524,6 +526,7 @@ impl Default for NativeHosting { | |
| diagnostics: NativeDiagnosticsHandle::new(), | ||
| policy: TrustedProxyPolicy::no_trust(), | ||
| request_records: true, | ||
| geo: NativeGeo::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -750,13 +753,14 @@ where | |
| log::warn!(target: BOOT_LOG_TARGET, "application head limits exceed Axum raw ingress limits; the parser rejects first"); | ||
| } | ||
| let session = NativeSession::new(native.diagnostics, native.request_records)?; | ||
| let mut service = AxumServiceState::with_transport( | ||
| let mut service = AxumServiceState::with_native_transport( | ||
| app, | ||
| transport, | ||
| executor, | ||
| json_body_limit, | ||
| session, | ||
| native.policy, | ||
| native.geo, | ||
| ) | ||
| .with_phase(reader.clone()); | ||
| if let Some(registry) = stores.config { | ||
|
|
@@ -1119,6 +1123,7 @@ where | |
| policy, | ||
| request_records, | ||
| diagnostics: NativeDiagnosticsHandle::new(), | ||
| geo: NativeGeo::default(), | ||
| }, | ||
| )) | ||
| } | ||
|
|
@@ -1295,6 +1300,13 @@ where | |
| &'startup PreparedStores, | ||
| ) -> LocalStartupFuture<'startup>, | ||
| { | ||
| let geo = options.native_geo()?; | ||
| let native = NativeHosting { | ||
| diagnostics: options.diagnostics(), | ||
| policy: options.trusted_proxy_policy(), | ||
| request_records: options.request_records(), | ||
| geo, | ||
| }; | ||
| run_local( | ||
| ListenerSource::Bind(options.addr()), | ||
| signals, | ||
|
|
@@ -1317,17 +1329,7 @@ where | |
| ); | ||
| failure("initializer", "application", &category) | ||
| })?; | ||
| Ok(( | ||
| app, | ||
| stores, | ||
| transport, | ||
| options.json_body_limit(), | ||
| NativeHosting { | ||
| diagnostics: options.diagnostics(), | ||
| policy: options.trusted_proxy_policy(), | ||
| request_records: options.request_records(), | ||
| }, | ||
| )) | ||
| Ok((app, stores, transport, options.json_body_limit(), native)) | ||
| }, | ||
| ) | ||
| } | ||
|
|
@@ -2382,7 +2384,8 @@ mod tests { | |
| OsString::from("EDGEZERO__ADAPTER__JSON_BODY_LIMIT_BYTES"), | ||
| binary, | ||
| )]) | ||
| .expect_err("recognized binary setting"); | ||
| .err() | ||
| .expect("recognized binary setting"); | ||
| assert!(error.to_string().contains("JSON_BODY_LIMIT_BYTES")); | ||
| assert_eq!(error.chain().count(), 1); | ||
| for (path, category) in [ | ||
|
|
@@ -2393,7 +2396,8 @@ mod tests { | |
| OsString::from(format!("EDGEZERO__ADAPTER__{path}")), | ||
| OsString::from_vec(b"PRIVATE_SENTINEL\xff".to_vec()), | ||
| )]) | ||
| .expect_err("owned binary limit must fail"); | ||
| .err() | ||
| .expect("owned binary limit must fail"); | ||
| assert!(owned_error.to_string().contains(category)); | ||
| assert!(!format!("{owned_error:?}").contains("PRIVATE_SENTINEL")); | ||
| assert_eq!(owned_error.chain().count(), 1); | ||
|
|
@@ -4272,6 +4276,53 @@ mod native_store_tests { | |
| Ok(format!("{}:{state}", value.as_str())) | ||
| } | ||
|
|
||
| #[cfg(not(feature = "geo-cloudfront"))] | ||
| #[tokio::test(flavor = "current_thread")] | ||
| async fn geo_unavailable_selection_fails_before_runner_resources() { | ||
| use crate::geo::{NativeGeoSelection, ProtectedCloudFrontAlb}; | ||
| let root = tempfile::tempdir().unwrap(); | ||
| let options = options() | ||
| .with_config_dir(root.path()) | ||
| .unwrap() | ||
| .with_data_dir(root.path()) | ||
| .unwrap() | ||
| .with_geo(NativeGeoSelection::CloudFront { | ||
| policy: ProtectedCloudFrontAlb::new(["127.0.0.1/32"], "x-origin-verify-fixture") | ||
| .unwrap(), | ||
| }); | ||
| let address = options.addr(); | ||
| let prepared = Rc::new(Cell::new(false)); | ||
| let initialized = Rc::new(Cell::new(false)); | ||
| let prepare_observed = Rc::clone(&prepared); | ||
| let initialize_observed = Rc::clone(&initialized); | ||
| let mut overrides = NativeStoreOverrides::default(); | ||
| overrides | ||
| .prepare_config("first", async move { | ||
| prepare_observed.set(true); | ||
| Err(NativeStorePreparationError::Unavailable) | ||
| }) | ||
| .unwrap(); | ||
| // Existing Tokio runtime would reject nested runner construction if validation were late. | ||
| let error = run_app_with_native_stores::<CustomApp, _, _>( | ||
| options, | ||
| overrides, | ||
| future::pending::<()>(), | ||
| move |_app, _stores| { | ||
| Box::pin(async move { | ||
| initialize_observed.set(true); | ||
| Ok(()) | ||
| }) | ||
| }, | ||
| ) | ||
| .unwrap_err(); | ||
| assert!(error.to_string().contains("unavailable")); | ||
| assert!(!prepared.get()); | ||
| assert!(!initialized.get()); | ||
| assert_eq!(fs::read_dir(root.path()).unwrap().count(), 0); | ||
| let listener = StdTcpListener::bind(address).expect("runner never bound listener"); | ||
| drop(listener); | ||
| } | ||
|
|
||
| #[test] | ||
| fn ready_and_rc_deferred_inputs_share_completed_registries_with_requests() { | ||
| let options = options(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.