Repository navigation
Enforce mailroom access control on TLS serve paths - #1941
Conversation
Coverage Report for CI Build 36992725278Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage increased (+0.2%) to 87.494%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
0b1bce8 to
ac86b7f
Compare
`check_geoip` read the client address only from `ConnectInfo<MaybePeerIp>`, which only the plain `serve` path installs. `serve_acme` and both branches of `serve_manual_tls` install `ConnectInfo<SocketAddr>`, so on those paths the lookup found nothing, the middleware fell through, and every request was admitted. An operator who configured `blocked_regions` or `blocked_ips` alongside ACME got a policy that never rejected anything, with no error and no log line, and ACME is the default deployment. Fall back to `ConnectInfo<SocketAddr>` when `MaybePeerIp` is absent. This keeps the change to the middleware. Installing one type on every path would mean new `Connected` impls and ungating `MaybePeerIp`, all of which goes away once the plain path no longer accepts non-IP listeners and every path can install `SocketAddr`. The regression test drives both branches of `serve_manual_tls`. The TLS branch reports its peer the same way as `serve_acme`, which cannot run in a test. Each branch must refuse a client when every source address is blocked and serve it when an unrelated range is blocked, so a path whose address never reaches the middleware fails one of the two checks whichever way a missing address is treated. Without the fix the blocked instance answers 200 where 403 is required.
ac86b7f to
da33408
Compare
|
My plan after this lands is to drop
It removes about a dozen crates from the lockfile, It's a breaking change. The Separately, This is issue territory because it doesn't block anyone but it is simplification and therefore better hygiene. |
Opens the Unreleased section that release crates keep from now on, with this change's line in it. The next mailroom bump renames the heading to its version.
| async fn health_status(tls: bool, blocked_ips: &[&str]) -> axum::http::StatusCode { | ||
| let tempdir = tempdir().unwrap(); | ||
| let mut config = test_config(tempdir.path()); | ||
| config.access_control = Some(crate::config::AccessControlConfig { | ||
| blocked_ips: blocked_ips.iter().map(|ip| ip.to_string()).collect(), | ||
| ..Default::default() | ||
| }); | ||
|
|
||
| let cert = local_cert_key(); | ||
| let cert_der = cert.cert.der().to_vec(); | ||
| let key_der = cert.signing_key.serialize_der(); | ||
| let tls_config = match tls { | ||
| true => Some(RustlsConfig::from_der(vec![cert_der.clone()], key_der).await.unwrap()), | ||
| false => None, | ||
| }; | ||
| let mut root_store = RootCertStore::empty(); | ||
| root_store.add(CertificateDer::from(cert_der.clone())).unwrap(); | ||
|
|
||
| let (port, _handle) = serve_manual_tls(config, tls_config, root_store, None).await.unwrap(); |
There was a problem hiding this comment.
This helper seems kinda selective for just the newly added test, when there are already existing tests with shared code that could be refactored as well.
payjoin-mailroom's access-control middleware never rejected a request when the mailroom served over TLS.
check_geoipread the client address only from aConnectInfo<MaybePeerIp>request extension, and only the plainservepath installs that type.serve_acmeandserve_manual_tlsinstallConnectInfo<SocketAddr>. The lookup found nothing and the middleware let the request through. An operator who setsblocked_regionsorblocked_ipstogether withacmegets a policy that admits every client, and nothing in the logs says so. ACME is the default deployment, so this affects the usual setup.Fix
check_geoipnow falls back toConnectInfo<SocketAddr>whenMaybePeerIpis absent. The serve paths are unchanged.The alternative was to install
MaybePeerIpon every serve path. That needs two newConnectedimpls and movesMaybePeerIpout from behind theaccess-controlfeature, and all of it would be deleted again if the plain path stops accepting Unix socket listeners.MaybePeerIpcarries anOptiononly because of those listeners. Without them every serve path can installSocketAddr, and the middleware needs a single lookup. This PR keeps the change to the middleware so it can ship in a patch release.Testing
geoip_policy_is_enforced_on_the_manual_serve_pathsdrives both branches ofserve_manual_tls. The TLS branch reports its peer the same wayserve_acmedoes, since ACME can't run in a test. Each branch is checked twice. An instance blocking every source address must answer 403, and one blocking an unrelated range must answer 200. Removing the fallback makes the test fail with 200 where 403 is expected.self-reviewed over multiple iterations concerning who actually uses the unix feature, how this bug was introduced in the first place, and whether it can be done with a more minimal design.
Found by a self-hosted run of
project-loupe/loupeover the tree.Disclosure: co-authored by Claude Code