From 9c8101a3ee4f76d8dcb140ea65ef501a3ef2c8ba Mon Sep 17 00:00:00 2001 From: Thomas Eizinger Date: Sat, 20 Sep 2025 02:08:03 +0000 Subject: [PATCH] chore: render contextual information more Sentry-friendly (#10386) Sentry can group issues together that have unique identifiers in their message. Unfortunately, it does that only well for integers and UUIDs and not so much for hex-values. To avoid alert fatigue, we render the public key as a u256 which hopefully allows Sentry to group these together. --- rust/Cargo.lock | 7 +++++++ rust/Cargo.toml | 1 + rust/connlib/snownet/Cargo.toml | 1 + rust/connlib/snownet/src/node.rs | 26 ++++++++++++++++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index d932bca64..543782994 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -943,6 +943,12 @@ dependencies = [ "piper", ] +[[package]] +name = "bnum" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "119771309b95163ec7aaf79810da82f7cd0599c19722d48b9c03894dca833966" + [[package]] name = "boringtun" version = "0.6.1" @@ -6907,6 +6913,7 @@ name = "snownet" version = "0.1.0" dependencies = [ "anyhow", + "bnum", "boringtun", "bufferpool", "bytecodec", diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 7b64636b5..bbe02c344 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -56,6 +56,7 @@ aya-log-ebpf = { git = "https://github.com/aya-rs/aya" } backoff = { version = "0.4", features = ["tokio"] } base64 = { version = "0.22.1", default-features = false } bimap = "0.6" +bnum = "0.13.0" boringtun = { version = "0.6", default-features = false } bufferpool = { path = "connlib/bufferpool" } bytecodec = "0.5.0" diff --git a/rust/connlib/snownet/Cargo.toml b/rust/connlib/snownet/Cargo.toml index f358888f0..d34f9ade5 100644 --- a/rust/connlib/snownet/Cargo.toml +++ b/rust/connlib/snownet/Cargo.toml @@ -6,6 +6,7 @@ license = { workspace = true } [dependencies] anyhow = { workspace = true } +bnum = { workspace = true } boringtun = { workspace = true } bufferpool = { workspace = true } bytecodec = { workspace = true } diff --git a/rust/connlib/snownet/src/node.rs b/rust/connlib/snownet/src/node.rs index fa46cea40..beef650a6 100644 --- a/rust/connlib/snownet/src/node.rs +++ b/rust/connlib/snownet/src/node.rs @@ -1465,7 +1465,7 @@ where let id = self .established_by_wireguard_session_index .get(&index.global()) - .with_context(|| format!("No connection for with index {index}"))?; + .with_context(|| format!("No connection for index {}", index.global()))?; let connection = self .established .get_mut(id) @@ -1482,7 +1482,7 @@ where .established .iter_mut() .find(|(_, c)| c.tunnel.remote_static_public().as_bytes() == &key) - .with_context(|| format!("No connection with public key {}", hex::encode(key)))?; + .with_context(|| format!("No connection for public key {}", into_u256(key)))?; Ok((*id, conn)) } @@ -1529,6 +1529,12 @@ where } } +fn into_u256(key: [u8; 32]) -> bnum::BUint<4> { + // Note: `parse_str_radix` panics when the number is too big. + // We are passing 32 u8's though which fits exactly into a u256. + bnum::types::U256::parse_str_radix(&hex::encode(key), 16) +} + fn add_local_candidate( id: TId, agent: &mut IceAgent, @@ -2753,4 +2759,20 @@ mod tests { assert!(agent.remote_candidates().contains(&expected_candidate2)); assert!(!agent.remote_candidates().contains(&unexpected_candidate3)); } + + #[test] + fn can_make_u256_out_of_byte_array() { + let bytes = random(); + let _num = into_u256(bytes); + } + + #[test] + fn u256_renders_as_int() { + let num = into_u256([1; 32]); + + assert_eq!( + num.to_string(), + "454086624460063511464984254936031011189294057512315937409637584344757371137" + ); + } }