Per-replica EHLO name: KARTA_OUTBOUND_HOSTNAME=auto #102

Merged
calvin merged 1 commit from outbound-hostname-auto into master 2026-11-16 03:56:41 +00:00
Owner

What

KARTA_OUTBOUND_HOSTNAME=auto learns each replica's outbound name: the PTR record of the address the node sends from, forward-confirmed (the PTR name's A/AAAA record must lead back). It keeps the name for an hour and learns it again on the next delivery after that. A fixed value is used exactly as before. On failure it logs the reason and uses KARTA_OUTBOUND_HOSTNAME_FALLBACK (default KARTA_SMTP_HOSTNAME, else the system host name); a name already learned is kept rather than replaced.

The learned name is used wherever Karta names itself:

  • EHLO/HELO of outbound delivery (Karta.Outbound.Deliverer), the inbound relay (Karta.Inbound.Dispatcher) and the MTA-STS probe
  • Message-ID/Received fields Karta writes (Karta.Sending)
  • DSN Reporting-MTA and Message-ID
  • the domain health checks' sending-address list

Why

Two replicas of Karta that send from different addresses (two nodes, each source-NAT'd to its own public IP) must greet with their own address's name. One fleet-wide value cannot do that, and an IP pool cannot be used in a Swarm overlay because the pool address is not on the replica's interface. This is slice K1 of docs/suite/plans/karta-two-replicas-plan.md.

The limitation, stated plainly

The egress address is read as the local address of a connection, so it is the address receiving servers see only when the public address is on Karta's own interface (host networking, macvlan, bare metal). In a container whose packets the host source-NATs (Docker bridge or Swarm overlay), that address is private, its PTR record does not lead back, and auto logs the reason and uses the fallback every hour. The operations guide says so in Replicas § The name in EHLO. Making this work in a Swarm overlay needs a public-address echo or host networking — a separate decision.

auto learns one name, so it wants one IP family (ipv4_only/ipv6_only); with prefer_ipv4/prefer_ipv6 both families may be used and one name cannot match both PTRs. Documented.

Tests

  • test/karta/outbound/hostname_test.exs (new): PTR + forward-confirmed choice, a PTR name that does not lead back, no PTR, IPv6, family fall-through, fixed value untouched, caching for an hour, fallback with the reason logged, keeping a previously learned name when a re-check fails — all with a fake DNS zone and a fake egress address.
  • test/karta/outbound/deliverer_test.exs: an auto delivery greets with EHLO mta1.example.com on the wire (test SMTP peer).
  • test/karta/runtime_config_test.exs: the fallback comes from KARTA_OUTBOUND_HOSTNAME_FALLBACK, else KARTA_SMTP_HOSTNAME; a fallback of auto stops the start.

Docs and changelog

Configuration reference (the two variables), Replicas (new The name in EHLO section and audit row), installation, domains-and-DNS, delivery, IP pools, sending rules, API guide, the example .env, and a CHANGELOG entry.

mix precommit (format, compile with warnings as errors, credo strict, sobelow, deps audit, full test suite) passes: 3846 tests. mix docs --warnings-as-errors passes.

🤖 Generated with Claude Code

## What `KARTA_OUTBOUND_HOSTNAME=auto` learns each replica's outbound name: the PTR record of the address the node sends from, forward-confirmed (the PTR name's A/AAAA record must lead back). It keeps the name for an hour and learns it again on the next delivery after that. A fixed value is used exactly as before. On failure it logs the reason and uses `KARTA_OUTBOUND_HOSTNAME_FALLBACK` (default `KARTA_SMTP_HOSTNAME`, else the system host name); a name already learned is kept rather than replaced. The learned name is used wherever Karta names itself: - `EHLO`/`HELO` of outbound delivery (`Karta.Outbound.Deliverer`), the inbound relay (`Karta.Inbound.Dispatcher`) and the MTA-STS probe - `Message-ID`/`Received` fields Karta writes (`Karta.Sending`) - DSN `Reporting-MTA` and `Message-ID` - the domain health checks' sending-address list ## Why Two replicas of Karta that send from different addresses (two nodes, each source-NAT'd to its own public IP) must greet with their own address's name. One fleet-wide value cannot do that, and an IP pool cannot be used in a Swarm overlay because the pool address is not on the replica's interface. This is slice K1 of `docs/suite/plans/karta-two-replicas-plan.md`. ## The limitation, stated plainly The egress address is read as the local address of a connection, so it is the address receiving servers see only when the public address is on Karta's **own interface** (host networking, macvlan, bare metal). In a container whose packets the host source-NATs (Docker bridge or Swarm overlay), that address is private, its PTR record does not lead back, and `auto` logs the reason and uses the fallback every hour. The operations guide says so in *Replicas § The name in EHLO*. Making this work in a Swarm overlay needs a public-address echo or host networking — a separate decision. `auto` learns one name, so it wants one IP family (`ipv4_only`/`ipv6_only`); with `prefer_ipv4`/`prefer_ipv6` both families may be used and one name cannot match both PTRs. Documented. ## Tests - `test/karta/outbound/hostname_test.exs` (new): PTR + forward-confirmed choice, a PTR name that does not lead back, no PTR, IPv6, family fall-through, fixed value untouched, caching for an hour, fallback with the reason logged, keeping a previously learned name when a re-check fails — all with a fake DNS zone and a fake egress address. - `test/karta/outbound/deliverer_test.exs`: an `auto` delivery greets with `EHLO mta1.example.com` on the wire (test SMTP peer). - `test/karta/runtime_config_test.exs`: the fallback comes from `KARTA_OUTBOUND_HOSTNAME_FALLBACK`, else `KARTA_SMTP_HOSTNAME`; a fallback of `auto` stops the start. ## Docs and changelog Configuration reference (the two variables), Replicas (new *The name in EHLO* section and audit row), installation, domains-and-DNS, delivery, IP pools, sending rules, API guide, the example `.env`, and a CHANGELOG entry. `mix precommit` (format, compile with warnings as errors, credo strict, sobelow, deps audit, full test suite) passes: 3846 tests. `mix docs --warnings-as-errors` passes. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Per-replica EHLO name: KARTA_OUTBOUND_HOSTNAME=auto
All checks were successful
ci/woodpecker/pr/woodpecker Pipeline was successful
f0e38811b0
Karta greets with KARTA_OUTBOUND_HOSTNAME, one value for every replica.
Two replicas sending from two addresses must each greet with their own
address's name, so `auto` learns it: it finds the egress address of the
IP family in use, looks up its PTR record, uses the first PTR name whose
A/AAAA record leads back (forward-confirmed reverse DNS), and keeps it
for an hour. A fixed value behaves exactly as before. On failure it logs
why and uses KARTA_OUTBOUND_HOSTNAME_FALLBACK (default: the SMTP host
name, else the system host name).

The learned name is used in EHLO/HELO (delivery, inbound relay, MTA-STS
probe), in the Message-ID and Received fields Karta writes, in DSN
Reporting-MTA, and by the domain health checks' sending-address list. In
a NAT container the egress address is private and auto falls back; the
guides say so.

Co-Authored-By: Claude Code <noreply@anthropic.com>
calvin merged commit 9df1cc9ced into master 2026-11-16 03:56:41 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
external/karta!102
No description provided.