Deliverability: leave out addresses no receiver sees, and skip /etc/hosts #409

Merged
jcoffey-dev merged 1 commits from fix/408-deliverability-public-addresses into main 2026-11-16 19:41:36 +00:00
3 changed files with 92 additions and 2 deletions

No files matched your search

+9 -1
View File
@@ -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
+18 -1
View File
@@ -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(),
}
}
}
@@ -237,9 +237,47 @@ async fn resolve_name(server: &Server, name: &str, mode: CheckMode) -> Vec<IpAdd
if let Some(Ok(v6)) = timed(dns.ipv6_lookup(fqdn.as_str(), mode.cache(&cache.dns_ipv6))).await {
ips.extend(v6.rrset.iter().copied().map(IpAddr::V6));
}
// #408: an address no receiver can see isn't one mail is sent from. In a
// container /etc/hosts maps the server's own name to the container's
// private addresses, so when that's all there is, ask DNS itself.
if !ips.is_empty() && !ips.iter().any(|ip| seen_by_receivers(*ip)) {
ips.clear();
if let Some(Ok(found)) =
timed(server.core.smtp.resolvers.public.lookup_ip(fqdn.as_str())).await
{
ips.extend(found.iter());
}
}
ips.retain(|ip| seen_by_receivers(*ip));
ips.dedup();
ips
}
/// Whether a receiving server could see mail come from `ip`: not a private,
/// shared (CGNAT), loopback, link-local, unique-local or unspecified address.
fn seen_by_receivers(ip: IpAddr) -> 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}");
}
}
}