Commit Graph
2990 Commits
Author SHA1 Message Date
Wez Furlong 71c858457f cidr-map: impl Serialize for CidrMap 2025-03-23 07:48:31 -07:00
Wez Furlong 6c49d51ee7 smtp_server: add smtp_server_connection_accepted event 2025-03-23 07:15:45 -07:00
Wez Furlong d37432a644 docs: changelog for new via, meta, peer options 2025-03-23 07:11:24 -07:00
Wez Furlong 0fe50ed0e1 cidrmap: impl Deserialize
This allows us to deserialize the peer and via listener maps directly
into Arc making the use of those features more efficient.
2025-03-22 15:50:00 -07:00
Wez Furlong 8253417576 smtp_server: add meta parameter to start_esmtp_listener
This allows pre-defining connection metadata values.  When coupled with
`peer` and/or `via`, these can be done based on the corresponding
addresses associated with the session.

closes: https://github.com/KumoCorp/kumomta/issues/355
2025-03-22 11:13:22 -07:00
Wez Furlong a7c98a7d0f smtp_server: add via matching parameter to start_esmtp_listener
Similar to the peer option, but this one matches based on the
local address, giving a bit more flexibility for virtual hosting.
2025-03-22 11:07:19 -07:00
Wez Furlong 3e9bc5a946 smtp_server: introduce new peer matching option to start_esmtp_listener
This allows crafting peer-address-specific values for a listener.
2025-03-22 10:35:42 -07:00
Wez Furlong 97a37cdc5e smtp_server: introduce GenericEsmtpListenerParams type
This type is similar to the prior EsmtpListenerParams type,
except that every field is optional with no specified default.

This allows us to create an initial concrete set of parameters
(that hold the defaults), then progressively layer user specified
values from different context over the top of it.

In this commit we just have a single "base" context, which is
the set of parameters defined by start_esmtp_listener.

In the future, more contexts will be factored in.
2025-03-22 09:57:51 -07:00
Wez Furlong 57a86ff936 smtp_server: introduce ConcreteEsmtpListenerParams
The intent is that this will hold the merged, effective set
of configuration for a listener.

Right now this is a simple subset of the existing EsmtpListenerParams,
but in a future commit the latter will be extended and allow for
contextual parameters which will need to be compiled/merged
into the ConcreteEsmtpListenerParams struct.
2025-03-22 09:40:05 -07:00
Wez Furlong 9de685aa54 smtp_server: refactor tls_config
The motivation here is to remove tls_config from EsmtpListenerParams
to make some future configuration changes easier, so this commit
moves that simple cache out to an explicit lru ttl cache.

This has the welcome side effect of enabling periodic reloading
of the tls parameters, which in turn makes it a hands-off process
for updating certificates: we no longer require the service to
be restarted for that.
2025-03-22 09:18:38 -07:00
Wez Furlong 57659f4b07 smtp_server: slim down EsmtpListenerParams
This commit removes the local cached copy of connection_gauge and
connection_denied_counter from EsmtpListenerParams.  There's not
a huge benefit from caching these in the listener params, and
I'd like to make the listener configuration more flexible, so even
if the cache was useful, this spot isn't the best spot for it.
2025-03-22 08:56:54 -07:00
Wez Furlong 79feda679f smtp_server: refactor rename SmtpServer -> SmtpServerSession 2025-03-22 08:50:52 -07:00
Wez Furlong c9ab140ac1 shaping.lua: expose memoize populate retry/timeout params
undocumented for the moment
2025-03-21 16:59:13 -07:00
Wez Furlong 19341dc710 lruttl: add params to control timeout and retry on sema timeout
These are hooked up only for memoize at this time.  No default
behavior is changed by this commit, but you can optionally
specify these parameters in order to change the behavior.
2025-03-21 16:56:12 -07:00
Wez Furlong d21b98ab45 docs: format logging.md 2025-03-21 16:56:12 -07:00
Wez Furlong 9aff3ee9d8 rfc5321: improve error message for bad IDNA domains
Previously, we'd use the default presentation for the Error type
reported by the idna crate.  Unfortunately, that type holds no
context: it is a zero-sized empty struct type, and it chooses
to render itself as `Errors`, which isn't super helpful, but
it is hard to convey every possible error clause from the underlying
spec, so I understand why this is this way.

This commit handles that error case to present a slightly more
informative error message.

It doesn't provide context on what specifically is bad about
the input, but it at least helps to characterize that the domain
is bad, rather than imply that we don't know how to deal with
punycode at all.

The specific problem with the domain in the included test
case is most likely BIDI related per discussion in
https://github.com/servo/rust-url/issues/489
2025-03-21 16:56:11 -07:00
Ryan Bonnell 2513070837 Fix incorrect URL in changelog for new logging functions 2025-03-21 13:22:58 -07:00
Ryan Bonnell 259f24604c Decorate fenced code blocks with console syntax highlighting 2025-03-20 11:33:40 -07:00
Ryan Bonnell 19d7506924 Include example to show TSA rules applied to a domain 2025-03-20 11:33:40 -07:00
Ryan Bonnell bfbd9f4383 Add healthcheck for a more robust replacement of ‘depends_on’ attribute 2025-03-20 11:33:40 -07:00
Wez Furlong 3344d84283 shaping: fix missing field http_timeout error in validation mode
The workaround is to explicitly add `http_timeout` to your
validation_options for the shaping helper.
2025-03-20 10:14:30 -07:00
Ryan Bonnell 0d7a0b4bd6 Clarify example of log format template usage for customization 2025-03-20 08:26:31 -07:00
Wez Furlong 337b4e33a8 docs: update for stable 2025.03.19-1d3f1f67 release 2025-03-20 07:28:32 -07:00
Wez Furlong 1d3f1f67f6 deps: unpin ring, bump some deps
https://github.com/briansmith/ring/issues/2462 has been resolved,
so we should be buildable on amazonlinux:2 with the latest released
package.

cargo update, but also a couple of intentional bumpds to some
packages in Cargo.toml to keep things updated.
2025-03-19 05:38:57 -07:00
Wez Furlong 360850dc67 smtp_dispatcher: fix incorrect retry of broken tls when policy=required
The introduction of the
`opportunistic_tls_reconnect_on_failed_handshake` option resulted in
this regression, which is because I misread the `match` statement
for this case as being only for the opportunistic case, but it
also encompasses the required case.

The issue is:

* A site has an MTA-STS policy enforcing Required tls
* The handshake with that site fails (for reasons unknown and
  irrelevant)
* We would unconditionally (wrt. Required vs. Opportunistic) respect
  opportunistic_tls_reconnect_on_failed_handshake and re-queue the
  current address for the next connection attempt
* Ordinarily, opportunistic_tls_reconnect_on_failed_handshake +
  the remembered broken state would cause that next attempt to
  downgrade to clear text, but MTA-STS forces the policy to
  Require
* Goto step 2 (modulated by connection rate throttling)

The fix is simply to only apply
opportunistic_tls_reconnect_on_failed_handshake when the policy
is actually opportunistic.
2025-03-19 05:14:22 -07:00
Ryan Bonnell f886831598 Remove Docker compose top-level version property
A warning message is displayed that the version element is obsolete and should be removed.
2025-03-18 20:08:03 -07:00
Wez Furlong f7b5395249 tsa-daemon: increase broadcast buffer to resolve channel lag error
We were using a fairly tight limit of 16 messages in the channel
that buffers the effects of changing bounces/suspensions from
any websocket-connected-clients.

A busy server could hit that limit fairly easily, resulting
in a `channel lagged by NUMBER` error that drops the websocket,
causing the client to need to reconnect and resync.

This commit resolves that by making the buffer a much more healthy size.
2025-03-18 14:05:54 -07:00
Wez Furlong 1f633847d3 tsa-daemon: fix over zealous dedup of bounce/suspension data on websocket
We were deduping just by rule_hash, but each of these tables has
additional required fields as part of the primary key.

The result was that, for sites with a lot of bounces/suspensions
triggered by the same rules across a related set of sources,
the full set of bounces and suspensions would not be correctly
reported as part of a websocket push.
2025-03-18 14:05:54 -07:00
Wez Furlong 9b065fb133 shaping.lua: revise update strategy for tsa pushed data
Previously, we'd build a little map of existing rules and check
things off against it, but that doesn't have the best scaling
properties, because we need to copy the full set of bounces/suspensions
into lua and check against that.

Since the underlying bounce/suspension tracking stuff already
guarantees that inserting a record with the same criteria will
replace another, this checking in lua-space was redundant and
wasteful, so we can just remove it.

This commit also adds some debug logging to show how many
records are being processed.
2025-03-18 14:05:53 -07:00
Wez Furlong d5decd1361 bounce/suspend schedq: improve data structures
While doing a torture test with a very large combination of
the number of domains, campaigns and tenants (effectively
unbounded in any meaningful time period), using the smart sink
to generate bounces and suspensions, I found that the overhead
of tracking the set of bounces and suspensions by scheduled
queue was too high: each bounce lookup was O(number-of-bounces),
and when you can have 100k admin bounces configured, that is
not good for the miss case, which, despite the volume of admin
bounce records, is still the dominant case.

This commit introduces a helper map/multi-index type that
maintains indices for the common tuples:

* (domain, campaign, tenant),
* (domain, tenant)
* (domain)
* other

then uses an appropriate index based on the current context.

That reduces the the lookup cost to effectively constant time (3 x O(1)
lookups), unless there are admin bounces registered in the "other"
bucket, in which case there is an additional O(number-of-other) lookups.
2025-03-18 14:05:53 -07:00
Wez Furlong dd63267db7 tsa-daemon: fix sqlite locking blocking tokio scheduler
sqlite doesn't have a native async interface, and instead will
use traditional OS-level mutexes to ensure thread safety.

Using those when under contention in a tokio scheduler thread
can lead to blocking of the tokio scheduler threads, which can
prevent timely delivery of data via websockets, or timely
processing of incoming log records.

This commit fixes up the sqlite access points to use tokio's
spawn_blocking function to move that style of mutex acquisition to a
more suitable context.
2025-03-18 14:05:51 -07:00
Wez Furlong 98e99594d9 shaping: process tsa websocket pushes in batches
We'll wait up to 3s at a time for however many mesages are available
to extract from the tsa daemon websocket, then process the results
in batches.

This avoids the potential for geometric complexity if there is a run of
subscription updates happening around the same time.
2025-03-18 14:05:30 -07:00
Wez Furlong 9e6321ecb6 shaping: add timeout for tsa shaping data fetches 2025-03-18 14:05:30 -07:00
Wez Furlong 54386ca308 rfc5321 client: fix openssl verify issue when hostname has trailing dot
I'm not totally sure why this isn't universally broken when using
openssl (instead of rustls), but in the specific case we were
investigating, the destination was configured via a routing_domain
and the resulting mx_host name had the trailing FQDN dot on it.

Removing that dot allows the certificate to verify, so let's
ensure that we strip it here in the client.
2025-03-18 06:10:23 -07:00
Wez Furlong d4d8dec8da mailparsing: avoid flagging as LINE_TOO_LONG when rfc2047 header encoding
Despite taking care to wrap the header values that we produce, we're
still 2 characters over the limit of 78 that we consider to be
ideally conformant.

That will cause check_fix_conformance to rebuild the message content
to bring it within spec, but because the encoder is the same, it
won't actually satisfy the line length if you check-fix the fixed
message.

Let's just adjust the limit so that we can avoid that.
2025-03-17 10:56:40 -07:00
Wez Furlong 6a5e6df5f0 mailparsing: fix whitespace precedence issue with long mailbox headers
The issue here is that when an rfc2047 encoded display name is split
across multiple lines, the whitespace between them is not recognized
at the right time, which results in the second encoded word being
passed through as-is, without being decoded.

This commit fixes the precedence of whitespace parsing in that
case.
2025-03-17 10:51:07 -07:00
Wez Furlong c1f950f52e docker: install ca-certificates in the image
refs: https://github.com/KumoCorp/kumomta/issues/356
2025-03-17 08:59:59 -07:00
Wez Furlong 6d17a0a453 docs: mention mta-sts and dane on the enable_tls page 2025-03-17 08:52:10 -07:00
Wez Furlong 5b3d94ef98 lruttl: potentially squash sema/eviction errors from logs
A couple of users have reported seeing:

  sema was closed but state is still pending

and/or

  lruttl: shaping_data did not find anything to evict, target was 1

messages in the diagnostic logs.

These arise due to the capacity of 1 that was configured
for the shaping data cache in the shaping helper and a race
condition where lookups are interleaved around a config epoch
bump triggered either by the initial epoch bump on startup,
or a bump produced by the TSA daemon.

This commit adjust the strategy for handling those errors if/when
they arise by attempting to restart the cache lookup process.

In addition, this commit raises the capacity of the shaping data
cache to avoid this point of contention.
2025-03-15 09:58:53 -07:00
Wez Furlong cc58befdc6 install.sh: fix typo 2025-03-15 07:34:00 -07:00
Wez Furlong 38294c1970 smtp-server: suppress histogram timer from Debug
The various inner fields in the histogram timer that is owned by
the TransactionState are not useful to see in debug output and
are very verbose, so let's omit them.
2025-03-15 07:33:59 -07:00
Wez Furlong c2444b6266 add expiry to per-msg scheduling overrides
This commit allows setting a per-message `expires` timestamp
via msg:set_scheduling (and thus msg:import_scheduling_header).

The expiration takes precedence over max_age; max_age will be
ignored for messages that have configured and expiration time.

The expiration time is independent of the other scheduling
restrictions.
2025-03-15 07:18:13 -07:00
Wez Furlong b138235aa1 set_scheduling: raise error if start > end 2025-03-15 07:18:12 -07:00
Wez Furlong e655236fe0 message: manually deserialize scheduling restrictions
This resolves an issue where the default behavior for serde is to
silently swallow issues with this struct, because we use a flattened
optional structure for those restrictions.
2025-03-15 07:18:12 -07:00
Wez Furlong 1fac830f94 integration-tests: asyncify disposition log gathering
Prior to this commit, disposition log gathering used blocking code to
consume the logs.

This was a surprising source of issues for the kumod under test: because
the disposition log reading code was blocking, and our higher level
logic to wait for a condition to become true was built on top of that,
the disposition log collection would block the stderr/stderr reader
tasks that take the kumod process output and emit it to our own stderr.

Given sufficient diagnostic (rather than disposition) log volume, pipe
buffers could fill up and cause the kumod process under test to block.

This could in turn lead to a surprising soft deadlock between the kumod
process trying to make forward progress and being blocked by its full
stderr pipe, and the integration test process that is waiting to
read disposition logs until it can get back to process the pipe reads
from the kumod process.

This commit uses spawn_blocking to put the blocking parts of the
integration test harness into a suitable background context so that
the kumod log output can continue unhindered and resolve this
issue.
2025-03-15 07:18:12 -07:00
Wez Furlong 714456db17 kumo-address: introduce HostOrSocketAddress type
This is a unix or ip address, where the ip address can optionally
include a port number.
2025-03-15 07:18:11 -07:00
Mike Hillyer 1754209db9 Fix a couple of docs build warnings. 2025-03-13 13:27:21 -04:00
Wez Furlong 1083539d0d inject api: add a lua build_v1 function
This is intentionally undocumented at this time; its a debugging
aid and not a formal part of the API.

The input is an inject_v1 compatible request. The return value
is an array style table holding each of the generated messages.

You can dump out the generated content like this

```
local kumo = require 'kumo'

local request = kumo.serde.json_load '/home/wez/Downloads/payload-bad.json'

for _, msg in ipairs(kumo.api.inject.build_v1(request)) do
  print(msg:get_data())
  -- and optionally print the From header, and so on.
  -- print(msg:get_first_named_header_value('from'))
end
```
2025-03-12 14:01:53 -07:00
Wez Furlong bb2e671f4e add explain-throttle script 2025-03-12 11:07:52 -07:00
Blake Patton 0befdaf665 Complete the missing part of the command 2025-03-11 10:00:13 -07:00