From ec23236b060e1bd4043cb0ba6cf568c4f13dae00 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Sat, 17 Aug 2024 17:29:15 +0200 Subject: [PATCH] Include Forwarded-For IP address in http.request-url event (closes #682) --- crates/common/src/config/server/listener.rs | 6 +++++- crates/jmap/src/api/http.rs | 19 +++++++++++++------ .../src/backend/composite/distributed_blob.rs | 4 ++-- crates/store/src/config.rs | 6 +++--- crates/store/src/lib.rs | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/crates/common/src/config/server/listener.rs b/crates/common/src/config/server/listener.rs index ca4c5ce7..130a6b91 100644 --- a/crates/common/src/config/server/listener.rs +++ b/crates/common/src/config/server/listener.rs @@ -183,7 +183,11 @@ impl Servers { // Parse proxy networks let mut proxy_networks = Vec::new(); - let proxy_keys = if config.has_prefix(("server.listener", id, "proxy.trusted-networks")) { + let proxy_keys = if config + .value(("server.listener", id, "proxy.trusted-networks")) + .is_some() + || config.has_prefix(("server.listener", id, "proxy.trusted-networks")) + { ("server.listener", id, "proxy.trusted-networks").as_key() } else { "server.proxy.trusted-networks".as_key() diff --git a/crates/jmap/src/api/http.rs b/crates/jmap/src/api/http.rs index 0edafa46..92d2cb9a 100644 --- a/crates/jmap/src/api/http.rs +++ b/crates/jmap/src/api/http.rs @@ -387,16 +387,16 @@ impl JmapInstance { let instance = session.instance.clone(); async move { - trc::event!( - Http(trc::HttpEvent::RequestUrl), - SpanId = session.session_id, - Url = req.uri().to_string(), - ); - let jmap = JMAP::from(jmap_instance); // Obtain remote IP let remote_ip = if !jmap.core.jmap.http_use_forwarded { + trc::event!( + Http(trc::HttpEvent::RequestUrl), + SpanId = session.session_id, + Url = req.uri().to_string(), + ); + session.remote_ip } else if let Some(forwarded_for) = req .headers() @@ -435,6 +435,13 @@ impl JmapInstance { .and_then(|h| h.parse::().ok()) }) { + trc::event!( + Http(trc::HttpEvent::RequestUrl), + SpanId = session.session_id, + RemoteIp = forwarded_for, + Url = req.uri().to_string(), + ); + forwarded_for } else { trc::event!( diff --git a/crates/store/src/backend/composite/distributed_blob.rs b/crates/store/src/backend/composite/distributed_blob.rs index 62e29ee8..04230bce 100644 --- a/crates/store/src/backend/composite/distributed_blob.rs +++ b/crates/store/src/backend/composite/distributed_blob.rs @@ -14,11 +14,11 @@ use utils::config::{utils::AsKey, Config}; use crate::{BlobBackend, Store, Stores}; -pub struct CompositeBlob { +pub struct DistributedBlob { pub stores: Vec, } -impl CompositeBlob { +impl DistributedBlob { pub fn open(config: &mut Config, prefix: impl AsKey, stores: &Stores) -> Option { let prefix = prefix.as_key(); let store_ids = config diff --git a/crates/store/src/config.rs b/crates/store/src/config.rs index d660f1e5..4d0d37af 100644 --- a/crates/store/src/config.rs +++ b/crates/store/src/config.rs @@ -213,7 +213,7 @@ impl Stores { } } #[cfg(feature = "enterprise")] - "sql-read-replica" | "composite-blob" => { + "sql-read-replica" | "distributed-blob" => { composite_stores.push((store_id, protocol)); } unknown => { @@ -254,9 +254,9 @@ impl Stores { self.lookup_stores.insert(id.to_string(), db.into()); } } - "composite-blob" => { + "distributed-blob" => { if let Some(db) = - crate::backend::composite::distributed_blob::CompositeBlob::open( + crate::backend::composite::distributed_blob::DistributedBlob::open( config, prefix, self, ) { diff --git a/crates/store/src/lib.rs b/crates/store/src/lib.rs index 914080cb..e7890cc0 100644 --- a/crates/store/src/lib.rs +++ b/crates/store/src/lib.rs @@ -209,7 +209,7 @@ pub enum BlobBackend { #[cfg(feature = "s3")] S3(Arc), #[cfg(feature = "enterprise")] - Composite(Arc), + Composite(Arc), } #[derive(Clone)]