Repository navigation
Accept configured gateway purposes in the relay - #2026
Conversation
The prober's policy records whether a gateway opted in to being reached through this relay. Today that means declaring the BIP77 purpose, but the next commit lets operators accept other purposes too, so name the field for what it means rather than for BIP77. No behavior change.
The relay forwards only to gateways that opt in by listing the BIP77 purpose in their allowed_purposes response. That keeps operators from relaying traffic they didn't agree to, but it also means an operator who is happy to relay another protocol's traffic has no way to do so. Add an [ohttp_relay] extra_allowed_purposes setting. The prober now treats a gateway as opted in if it lists BIP77 or any configured purpose. BIP77 is always accepted and the list is empty by default, so existing relays behave exactly as before. Each purpose must fit an allowed_purposes entry (1 to 255 bytes); anything else is refused at startup. Service::new is unchanged. Service::new_with_purposes takes the set, and all three serve paths (plain, ACME, and manual TLS) read it from the config, so the setting can't be silently ignored on one of them. Closes payjoin#2024.
caarloshenriq
left a comment
There was a problem hiding this comment.
No strong opinion on the concept, deferring to @DanGould on whether mailroom should relay for other protocols, since that’s a scope decision for the project. Code-wise this looks solid: defaults are unchanged, purposes are validated before startup on all three serve paths, and the new prober test fails if the check reverts to BIP77-only. Mailroom lib tests pass locally (the 3 failures are IPv6 binds in my environment, same on master).
One open question from #2024 that I don’t think got answered: the bootstrap CONNECT path goes through the same opt-in check, so extra purposes apply there too. Is that intended?
Left two small comments inline.
| .with_list_parse_key("acme.contact") | ||
| .with_list_parse_key("access_control.blocked_regions") | ||
| .with_list_parse_key("access_control.blocked_ips") | ||
| .with_list_parse_key("ohttp_relay.extra_allowed_purposes") |
There was a problem hiding this comment.
nit: with comma-separated env parsing, a purpose containing a comma can only be set through the TOML file. Maybe worth a note in config.example.toml.
There was a problem hiding this comment.
Added a note to config.example.toml in eab8c4c.
| /// Resolves on SIGINT or SIGTERM, the signals a terminal and systemd use to | ||
| /// stop the service. Returning from the serve loop instead of dying in the | ||
| /// default handler gives the weekly buckets a chance to reach disk. | ||
| /// The gateway purposes the relay forwards to: BIP77 plus any configured. |
There was a problem hiding this comment.
This landed between lshutdown_signal’s doc comment and the function, so relay_purposes now carries the “Resolves on SIGINT or SIGTERM…” docs and shutdown_signal has none. Could you move it above that block?
There was a problem hiding this comment.
Good catch, moved it above the doc comment in eab8c4c.
|
Thanks for the review, @caarloshenriq. On Both inline comments are fixed in eab8c4c. |
|
Thanks for the changes @gf5901! Small thing: your last commit (8ab03e2) has a |
Move relay_purposes above shutdown_signal's doc comment, which it had taken over. Note in config.example.toml that a purpose containing a comma can only be set in the TOML file, since the environment variable is split on commas.
eab8c4c to
9a36272
Compare
|
Thanks, @caarloshenriq. Done: I dropped the trailer and force-pushed. The commit is now 9a36272, with the same changes (the trailer was on eab8c4c, the commit before that). The AI disclosure stays in the PR body only. |
codaMW
left a comment
There was a problem hiding this comment.
Ran the full mailroom suite on 9a36272 (--all-features, all green) plus mutations. Logic checks out, and the opt-in gate is load-bearing (forcing any_of to true fails test_other_purposes_need_the_operator_to_opt_in).
One gap before a full ACK: nothing covers the config-to-relay path. I made relay_purposes return AllowedPurposes::default(), dropping the operator's configured purposes, and the whole suite still passed. A test that sets extra_allowed_purposes and checks a gateway declaring only that purpose is reached would close it.
Otherwise looks good. AI-assisted review, I ran the suite and mutations myself.
Coverage Report for CI Build 42300982630Warning 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.3%) to 87.844%Details
Uncovered Changes
Coverage Regressions341 previously-covered lines in 6 files lost coverage.
Coverage Stats
💛 - Coveralls |
Serves mailroom with extra_allowed_purposes set and relays a request to a mock gateway that declares only that purpose; without the setting the gateway is not reached. Covers the config-to-relay path, which no test exercised before.
|
Thanks for the review and the mutation run, @codaMW. Good catch on the gap. Added in 7009cb4: (AI-assisted: the test and this comment were written with Claude Code; I ran the mutation and the suite.) |
DanGould
left a comment
There was a problem hiding this comment.
ACK 9a36272
Very happy to see this as it will let us experiment with some esplora proxying as well.
I ran some extra validation with bots:
I ran the PR and its base through the real mailroom relay and checked configured allowed purposes from both TOML and environment configuration. I verified exact gateway response forwarding; multiple, unrelated, and unconfigured purposes; invalid-purpose handling; and purpose length limits.
Default denial and BIP77 compatibility match the base, including 25-second delayed responses. I also checked CONNECT bootstrap over local HTTPS, with the configured purpose accepted and the default unconfigured case rejected.
And have some follow ups to share after
I added a separate generic config-to-relay regression test using a synthetic purpose. It passes end to end and returns 404 when I mutate the relay to discard the configured purposes. I’ll point to the test-timing hardening issue separately
|
Thanks for merging this, @DanGould, and to @caarloshenriq and @codaMW for the reviews. I tested master (0065ad2) in front of a Lantern Zero server. With the purpose configured, the whole wallet flow works, including 25 s long-polls. The key configuration comes through the CONNECT bootstrap tunnel, and it matches a direct fetch byte for byte. Without the setting, every request is refused, as before. Once it's in a mailroom release: would you consider adding Lantern Zero's purpose to the payjo.in relay? [ohttp_relay]
extra_allowed_purposes = ["LanternZero v0 4bca76ac-1094-4330-97df-03d5c81b576d"]Lantern Zero is a notification service for Zcash wallets. Wallets reach their server through two independent OHTTP relays, so neither the relay nor the server sees both who's asking and what. Right now servers under lanternzero.com have only one relay that isn't ours, and payjo.in would be a good second. The traffic is small: every request and response is padded to 4 KiB, and wallets hold long-polls of 25–30 s. If you're open to it, we'd list the relay in our spec's relay list (https://github.com/principlezerolabs/lanternzero/blob/main/spec/relays.md) with your contact and log retention, through a PR you can review. Wallet vendors choose which listed relays they use; we don't assign them. |
Glad this can be useful to you and your users. Our relay is winding down before 12/31 because we've moved to a model where we list mailrooms that adhere to a certain staindard at https://payjoin.org/mailroom rather than one one ourselves, so we're not a good fit for a host. |
Closes #2024.
Adds an
[ohttp_relay] extra_allowed_purposessetting to payjoin-mailroom. The relay still forwards only to gateways that opt in throughallowed_purposes. BIP77 is always accepted and the list is empty by default, so existing relays behave exactly as before. Operators who also want to relay another protocol's traffic can list its purposes.Commits
Policy::bip77_allowedtoopted_in. No behavior change.AllowedPurposesin the prober: BIP77 plus the configured purposes, each 1 to 255 bytes;Service::new_with_purposes, used by all three serve paths (plain, ACME, and manual TLS);config.example.toml, and a CHANGELOG line.API notes
Service::newis unchanged.ohttp_relay::{AllowedPurposes, InvalidPurpose},Service::new_with_purposes,config::OhttpRelayConfig, and aConfig::ohttp_relayfield. Code that buildsConfigwith a struct literal would need the new field; in-tree code usesConfig::newandDefault.Service::new_with_roots, behind_manual-tls, now takes the purposes too, so the manual-TLS path honors the setting.Testing
serve_manual_tls, withextra_allowed_purposesset, a gateway that declares only that purpose receives the relayed request; without the setting, the relay returns 404.cargo fmt --check;cargo clippy --all-targets --all-features -- -D warnings;--all-features(93 pass);cargo docwith-D warnings;--test integration),nix fmt, and the full./contrib/test_local.sh, because I don't have nginx or nix set up. There are no dependency changes, so both lockfiles are untouched.Reviewer: @DanGould, who discussed the approach on #2024.
AI disclosure: this change, its commit messages, and this description were written with an AI coding assistant (Claude Code). I completed the local AI review described in CONTRIBUTING.md. It found one issue, purposes being validated only after the directory had started, which is fixed. The text of #2024 and my comment there were also AI-drafted, and I should have said so then.