From 9dbcaee689bf4dc3f24ffd011a8d9ee8175ae88a Mon Sep 17 00:00:00 2001 From: John Coffey Date: Mon, 16 Nov 2026 12:32:19 -0700 Subject: [PATCH] Deliverability: leave out addresses no receiver sees, and skip /etc/hosts With no source addresses set, the check tests what the server's name resolves to. In a container /etc/hosts maps that name to the container's own addresses, so on an installer's container install Deliverability failed SPF (and asked blocklists) for 172.31.253.10 and fd69:6e62:7578::2. Private, shared, loopback, link-local and unique-local addresses are left out now. When those are all the name gave, a resolver on the same servers that never reads /etc/hosts is asked instead (Resolvers::public). Fixes #408 --- CHANGELOG.md | 10 ++- crates/common/src/config/smtp/resolver.rs | 19 +++++- crates/services/src/inbuxa_deliverability.rs | 65 ++++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6257028d..f29df83a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,7 +17,8 @@ file has no entry for (`tools/release/version.py --changelog`). ## [27.1-rc.25] - 2026-11-16 -A TLS report counts once on the dashboard, however many policies it covers. +A TLS report counts once on the dashboard, however many policies it covers, +and Deliverability stops failing SPF for a container's own addresses. ### Fixed - TLS reports: a report logged one incoming-report event per policy, so a @@ -26,6 +27,13 @@ A TLS report counts once on the dashboard, however many policies it covers. logs one event per report, with the totals summed over its policies and each policy's figures kept in the event. Thanks to khashmeshab. (#406, fixes #402) +- Deliverability: with no source addresses set, the check tested what the + server's name resolves to, and in a container /etc/hosts maps that name + to the container's own addresses. On an installer's container install it + failed SPF for 172.31.253.10 and fd69:6e62:7578::2, which no receiver ever + sees. Private, shared, loopback, link-local and unique-local addresses + are left out now, and when those are all the name gave, DNS itself is + asked. Thanks to faisal. (fixes #408) ## [27.1-rc.24] - 2026-11-16 diff --git a/crates/common/src/config/smtp/resolver.rs b/crates/common/src/config/smtp/resolver.rs index f5fbf439..1d0c9dd7 100644 --- a/crates/common/src/config/smtp/resolver.rs +++ b/crates/common/src/config/smtp/resolver.rs @@ -13,7 +13,7 @@ use mail_auth::{ TokioResolver, config::{ CLOUDFLARE, ConnectionConfig, GOOGLE, NameServerConfig, ProtocolConfig, QUAD9, - ResolverConfig, ResolverOpts, + ResolveHosts, ResolverConfig, ResolverOpts, }, net::runtime::TokioRuntimeProvider, system_conf::read_system_conf, @@ -35,6 +35,20 @@ pub struct Resolvers { pub dns: MessageAuthenticator, pub dnssec: DnssecResolver, pub dnssec_available: bool, + /// The same servers, asked without /etc/hosts, for what the world sees + /// of a name. In a container /etc/hosts maps the container's own name to + /// its private addresses (inbuxa-server#408). + pub public: TokioResolver, +} + +/// A resolver on `config` that always asks DNS and never reads /etc/hosts. +fn public_resolver(config: ResolverConfig, opts: &ResolverOpts) -> TokioResolver { + let mut opts = opts.clone(); + opts.use_hosts_file = ResolveHosts::Never; + TokioResolver::builder_with_config(config, TokioRuntimeProvider::default()) + .with_options(opts) + .build() + .expect("Failed to build DNS resolver") } #[derive(Clone)] @@ -161,6 +175,7 @@ impl Resolvers { dnssec_available: ensure_dnssec(&resolver_config, &dnssec.resolver).await, #[cfg(feature = "test_mode")] dnssec_available: true, + public: public_resolver(resolver_config.clone(), &opts), dns: MessageAuthenticator::new(resolver_config, opts).unwrap(), dnssec, } @@ -263,6 +278,7 @@ impl Default for Resolvers { opts_dnssec.validate = true; Self { + public: public_resolver(config.clone(), &opts), dns: MessageAuthenticator::new(config, opts).expect("Failed to build DNS resolver"), dnssec: DnssecResolver { resolver: TokioResolver::builder_with_config( @@ -284,6 +300,7 @@ impl Clone for Resolvers { dns: self.dns.clone(), dnssec: self.dnssec.clone(), dnssec_available: self.dnssec_available, + public: self.public.clone(), } } } diff --git a/crates/services/src/inbuxa_deliverability.rs b/crates/services/src/inbuxa_deliverability.rs index 74c856dc..499bc479 100644 --- a/crates/services/src/inbuxa_deliverability.rs +++ b/crates/services/src/inbuxa_deliverability.rs @@ -237,9 +237,47 @@ async fn resolve_name(server: &Server, name: &str, mode: CheckMode) -> Vec bool { + match ip { + IpAddr::V4(ip) => { + let [a, b, ..] = ip.octets(); + !(ip.is_private() + || ip.is_loopback() + || ip.is_link_local() + || ip.is_unspecified() + || ip.is_broadcast() + || (a == 100 && (64..128).contains(&b))) + } + IpAddr::V6(ip) => { + if let Some(v4) = ip.to_ipv4_mapped() { + return seen_by_receivers(IpAddr::V4(v4)); + } + !(ip.is_loopback() + || ip.is_unspecified() + || ip.is_unique_local() + || ip.is_unicast_link_local()) + } + } +} + /// DL-5: the PTR names, whether one resolves back, and whether that one is /// the EHLO name. async fn reverse_dns( @@ -646,4 +684,31 @@ mod tests { assert!(a < 3600 && b < 3600); assert_ne!(a, b); } + + #[test] + fn a_container_s_own_addresses_are_not_sending_addresses() { + // #408: the installer's network, as /etc/hosts gives it in the container + for ip in [ + "172.31.253.10", + "fd69:6e62:7578::2", + "10.0.0.5", + "192.168.1.20", + "100.64.0.1", + "127.0.0.1", + "169.254.1.1", + "::1", + "fe80::1", + "::ffff:172.31.253.10", + ] { + assert!(!seen_by_receivers(ip.parse().unwrap()), "{ip}"); + } + for ip in [ + "65.21.8.43", + "2a01:4f9:c010:1::1", + "192.0.2.10", + "100.128.0.1", + ] { + assert!(seen_by_receivers(ip.parse().unwrap()), "{ip}"); + } + } } -- 2.54.0