Commit Graph
26 Commits
Author SHA1 Message Date
Wez Furlong 0a8515194e listener: make listen backlog configurable
Avoid client connection stalls and timeouts during connection bursts by
allowing configuration of the listen backlog, replacing the
rust-internal hardcoded 128 entry limit.
2026-11-09 16:35:07 +00:00
Wez Furlong 8faf16a8a7 listeners: don't die on transient accept errors
Prevent transient accept() errors from permanently stopping listeners
while the process stays alive and appears healthy. Trivial peer resets
that happen between kernel queue and accept are logged only at debug
level to close remote log spam vectors.
2026-10-06 15:24:59 +01:00
Wez Furlong 7f21784537 xfer: fix far-future timestamps on transferred messages
A message received via inter-node transfer, on systems hosted on AWS, could
end up with a wildly incorrect far-future timestamp. The underlying mac_address
crate would pick a NIC with the same MAC address as other AWS instances in the
cluster, and that triggered a code path where the collision resolving logic
misinterpreted the timestamp portion of the incoming spool id.

The thing that made this painful was the logic in spool_id.rs: it
misinterpreted the subsecond portion of the timestamp extracted from
the uuid, and due to the way that that field wraps, could produce wildly
inaccurate deltas with a huge multiplier.

As a belt and suspenders treatment, allow the user to influence which
MAC address is selected via the new KUMO_MAC_INTERFACE and
KUMO_MAC_ADDRESS environment variables.
2026-08-25 07:48:50 +01:00
Wez Furlong 421b8a289e proxy: keepalive will work on macos and other unix too
So remove the linux only gate
2026-05-06 22:38:50 +01:00
JackandWez Furlong c4dbaa743b proxy-server: add tcp_keepalive option
Some upstream peers (e.g. QQ Mail's rate-limiter) silently hold a
proxied TCP connection open indefinitely — sending no data, FIN, or RST
— rather than cleanly refusing.  Without some kind of timeout
management, the two file descriptors for such a session remain open for
the lifetime of the process, slowly exhausting the kernel's
file-descriptor table and occupying proxy-server worker slots.

This commit configures kernel level keepalive options with reasonable
defaults to detect and close out this class of connection.

Co-authored-by: Wez Furlong <wez@wezfurlong.org>

Closes: https://github.com/KumoCorp/kumomta/pull/509
2026-05-06 21:09:10 +01:00
Wez Furlong 1690e6526a refactor: move start_proxy_listener to proxy module
We're keeping a reference to it via kumo.start_proxy_listener briefly,
just in case someone is using that live somewhere.

We don't need to changelog this, as this whole feature hasn't
been in a stable tag yet.

refs: https://github.com/KumoCorp/kumomta/pull/472
2026-02-06 07:31:30 +00:00
Wez Furlong 37111c8036 add auto-gen docs for proxy-server http api and metrics
refs: https://github.com/KumoCorp/kumomta/pull/472
2026-02-06 07:11:56 +00:00
Wez Furlong 18f6f19f10 refactor: fold connections_accepted_for_listener into ProxySessionMetrics
refs: https://github.com/KumoCorp/kumomta/pull/472
2026-02-06 07:11:55 +00:00
Aditya GantiandWez Furlong f898e2a7e6 Add Prometheus metrics to proxy-server
Co-authored-by: Wez Furlong <wez@wezfurlong.org>

closes: https://github.com/KumoCorp/kumomta/pull/472
2026-02-06 07:11:27 +00:00
Wez Furlong 2369162e75 proxy: flip no_splice to use_splice in proxy policy file
This option was named `--no-splice` on the command line because that
was the easiest UX there.  The negative logic makes it harder to
understand how to enable/disable, so let's flip it and default
use_splice=true.

refs: #459
2026-01-19 07:45:09 +00:00
Wez Furlong e18d2b25c1 proxy: refine TcpStream conversion 2026-01-19 07:45:09 +00:00
Wez Furlong d62ec9ed76 proxy: fixup config.put in lua callback error case
We must only config.put in the success case, otherwise we might
leave a broken lua context in the cache

refs: #459
2026-01-19 07:45:08 +00:00
Wez Furlong baa6326dd6 proxy: restore no-splice functionality 2026-01-19 07:45:08 +00:00
Kevin Vu c3ed6279d5 feat: add TLS and RFC 1929 auth to KumoProxy
Add TLS encryption and username/password authentication support for
the KumoProxy SOCKS5 server, with full Lua configuration capabilities.

Proxy Server Changes:
- Add kumo.start_proxy_listener() Lua function with TLS support
- Add proxy_server_auth_rfc1929 event for Lua-based auth validation
- Return AuthInfo from auth for ACL system integration
- Support optional and required authentication modes
- Maintain backwards-compatible legacy CLI mode (--listen, --timeout-seconds)

Breaking Changes:
- Cache renamed from rfc5321_rustls_config to rustls_client_config

Refs: #451
Closes: 459
2026-01-19 07:45:02 +00:00
Wez Furlong 5a1efc0c8c rustfmt 2025-09-18 20:09:48 +01:00
Wez Furlong eb54cc74d9 proxy-server: raise NOFILE soft limit to match hard limit
This makes the startup behavior consistent with kumod and tsa-daemon,
which can help with "Too many open files" errors in systems without
any explicit tunings for the proxy server.

It is still a good idea to explicitly tune that value up, and it is
something we should put into a systemd unit when we get around to
shipping one of those for the proxy server (#188)
2025-09-18 15:54:18 +01:00
Wez Furlong e3fdcaa628 cargo clippy --fix 2025-04-09 10:26:07 -07:00
Wez Furlong 3975afc446 proxy_handler: rustfmt
I'm not in-love with how it renders this all on one line,
but it prevents the "broken" fmt from being noisy and in the way.
2024-09-16 18:20:03 -07:00
Dirkjan Ochtman cb3fd8a5d4 proxy-server: enable compilation on non-Linux platforms
tokio-splice does not compile on macOS due to missing libc calls.
2024-09-16 06:32:33 -07:00
Wez Furlong b5596183be proxy-server: simplify passthru implementation
We've been trying to run down an issue where a user has reported that
some sessions that are running via the proxy seem to hang waiting for a
response from the peer.  The common theme is that the size of the
payload is approximately 1MB in size, and that the proxy is in use.

I haven't been able to get it to reproduce at all, but in looking
carefully at the code here, my splice(2) implementation used a pipe
buffer that was 1MB in size, and doing non-blocking IO outside of
tokio's internals is a bit of a black art, so I'd buy the theory
that we might be getting stuck somewhere if we did fill up that
pipe buffer.

Since I couldn't catch it in the act, I've opted to go for the simple
and safer route here, as a speculative remediation:

* Added a `--no-splice` command line parameter to opt out of using
  `splice(2)` completely on Linux so that we can rule out weirdness
  with splice completely. The result will have lower theoretical
  max throughput, but a simpler internal implementation.
* There now exists a `tokio-splice` crate that has the same
  functionality as my own splice_copy code does, but a different
  implementation. Adopt that for the `splice(2)` mode.
* Switch away from splitting the stream into read/write halves: there
  are now utility functions available in tokio and tokio_splice that
  don't require splitting the streams, which further simplifies
  the implementation.
2024-07-30 16:32:39 -07:00
Wez Furlong 8f87f66ea6 proxy: refine error reporting a little bit more 2024-07-15 16:04:59 -07:00
Wez Furlong b13ab592e5 kumoproxy: improve diagnostics around connectivity issues
Previously we were very tight-lipped. We now will log some
context to the journal for the proxy service for issues that
we couldn't propagate back to the client.
2024-07-15 11:55:00 -07:00
Wez Furlong a8b61ce59e proxy-server: fix missing bind(2) call
Somewhat embarrasing really
2024-03-14 17:51:58 -07:00
Wez Furlong 37e3401584 proxy: now compiles on macos 2023-10-09 10:04:24 -07:00
Wez Furlong acef2ecab9 Add timeouts to socks server handshake/connection initiation
Let's avoid things hanging forever while setting up a connection.

refs: https://github.com/KumoCorp/kumomta/issues/45
2023-05-15 17:55:28 -07:00
Wez Furlong beb120fda5 Add a SOCKS5 proxy server implementation
This is a pretty tight, lightweight implementation of SOCKS5
intended to be used to facilitate an MTA asking it to bind and
connect.

It uses the splice(2) syscall to avoid kernel/userspace copies
when passing data through, so it should be quite efficient.

refs: https://github.com/KumoCorp/kumomta/issues/45
2023-05-15 17:38:17 -07:00