Commit Graph
151 Commits
Author SHA1 Message Date
Wez Furlong 44c0c029e4 throttle: introduce LimitSpec and force_local mode
This brings parity with ThrottleSpec in allowing for explicitly
local limits, even when redis sharing is enabled.
2025-01-06 06:53:12 -07:00
Wez Furlong 39bbc0953e switch to DeferredInjectionRebind for deferred->fully realized
It's confusing to have 2 Delivery records, even if there are other
fields that distinguish between the events.
2024-12-19 10:14:26 -07:00
Wez Furlong 8be4ad82a1 add basic outbound LMTP support
This enables LMTP over TCP by setting `use_lmtp = true` in the
egress path configuration.

refs: https://github.com/KumoCorp/kumomta/issues/267
2024-12-17 06:48:52 -07:00
Wez Furlong 05295e415a add opportunistic_tls_reconnect_on_failed_handshake option
When used together with an Opportunistic TLS mode, if the handshake
or subsequent EHLO fails, we will re-connect to the current host
and disable TLS.

This is implemented as a recursive solution, which I'm not totally
keen on, but the recursion is limited to a single level so it's
not so bad.
2024-12-16 15:20:13 -07:00
Wez Furlong 5f19f7ce04 add deferred_queue option to the smtp listener
This option should be used with caution, and ideally only
for trusted networks.

The purpose is to absorb the latency of post-DATA processing
and hide it from the trust injector.

It defers processing that would normally happen in smtp_server_message_received
and instead will, at some (ideally) near-future time trigger an
smtp_server_message_deferred_inject event instead.

This will marginally increase your average injection latency but should
clamp your worst case injection latency much lower because the outliers
will not happen inline with the injecting client.
2024-12-16 11:27:40 -07:00
Wez Furlong c92cff2a60 maildir: support template expansion of maildir_path
closes: https://github.com/KumoCorp/kumomta/issues/109
2024-12-08 10:15:53 -07:00
Wez Furlong 1a83f72b6d maildir: expose dir_mode and file_mode to protocol config
You can now specify the dir and file modes in your maildir
protocol configuration.

refs: https://github.com/KumoCorp/kumomta/issues/109
2024-12-08 09:41:55 -07:00
Wez Furlong 38fd692e94 docs: show how to skip IPv6
I was halfway through adding special purpose options for this,
but I realized that skip_hosts already exists for this function
and is much more flexible.

Add an example to the docs to show how it can be done.
The same technique can be used to skip using IPv4 if that is
desired (despite being impractical with the current state
of SMTP on ipv6), but using `0.0.0.0/0` as an entry in the
skip_hosts list.

closes: https://github.com/KumoCorp/kumomta/issues/317
2024-12-04 07:33:50 -07:00
Wez Furlong cf911c4067 docs: update dev -> 2024.11.08-d383b033 2024-11-12 12:25:53 -07:00
Wez Furlong d383b033cf docs: add a refman section for template syntax 2024-11-08 10:37:08 -07:00
Wez Furlong d3e399cfda docs: describe the configuration monitoring and epoch system 2024-11-08 07:14:03 -07:00
Mike Hillyer 8bdfa734e9 Should not have made a page in the refman. 2024-11-05 17:39:16 -05:00
Mike Hillyer 1c8e3e413e Add a page for overall_max_message_rate to the reference manual. 2024-11-05 17:26:48 -05:00
Wez Furlong fbed08567f add remember_broken_tls option
This provides a simpler and easier to use option for dealing with broken
TLS.

The back story here is that sites with broken TLS ideally should result
in a TLS failure and return us to a clear text SMTP session that we
could use for the remainder if we are in opportunistic mode.

In practice, it's not that simple:

* The rustls implementation provides into_fallible() to enable this mode
  of operation, but certain handshake errors result in the session being
  unusable once the failed handshake has been communicated
* Openssl is perfectly capable of operating this way, but the Rust
  ecosystem bindings do not expose the handshake failure in a way that
  allows the clear text session to continue

If we wanted to allow the session to communicate with the failed host in
clear text we will need to make a new separate connection for this case.

There is a concern that this will bump a connection counter in a
reputation system implemented on the destination host, but it is
reasonable to wonder if a site that has broken TLS would be sufficiently
sophisticated to employ such a system.

If we did want to allow making a new connection to the same host, it is
a bit awkward to fit into our current mx host connection plan system.

So, with all that in mind, this commit tries a slightly different
approach:

* A new `remember_broken_tls = "3 days"` field in the egress path config
  will enable an in-process cache to keep track of the site_names that
  advertise STARTTLS and for which we failed to handshake, or failed to
  re-EHLO after a handshake.

* That will cause the connection plan to move on to subsequent hosts, if
  any.  It won't cause us to re-attempt the current host.

* Subsequent connection attempts (which may be immediate if there are
  additional hosts in the current session plan) will consult the
  broken tls cache for the site, and use that to decide on the
  availability of TLS

* If we previously encountered broken TLS, we will effectively treat
  the site as not advertising TLS in EHLO, but will generate an
  appropriate error message if TLS is Required.

Since we track the breakage in a cache with per-item TTLs, you
can set the duration as appropriate to your situation.

The cache will be cleared when the process is restarted.

There is no sharing of the cache between nodes.

This is a much lower complexity solution than the existing workaround
using TSA automation rules to override the site with Disabled TLS, and
will help to minimize the number of rules for that purpose in the TSA
daemon.

Note that this commit doesn't change any behavior; we can do a followup
commit to replace those TSA rules with this mechanism.
2024-10-31 13:11:49 -07:00
Wez Furlong 207bf44f18 docs: format enable_dane.md 2024-10-28 20:46:03 -07:00
Wez Furlong 18cbdeae1a fixup enable_dane page
it was still formatted as if it were part of its former home
in the big page for make_egress_path.

Tidy it up.
2024-10-25 09:09:11 -07:00
Laurent Marchaud 6142808730 fix a few typos in the docs
Signed-off-by: Laurent Marchaud <laurent@marchaud.com>
2024-10-24 12:10:53 -04:00
Wez Furlong bee7153872 docs: update configure_redis_throttles redis-cell info 2024-10-08 13:39:07 -07:00
Wez Furlong 1cc1c703a4 docs: add thread pool tuning functions
These could do with some more exposition and explanation,
but just getting them into the docs is good enough for now
2024-09-24 18:43:53 -07:00
Wez Furlong 667d1a91cb docs: fix check-liveness links 2024-09-09 09:50:46 -07:00
Wez Furlong 4fa23e9a7d http injector: add deferred generation
There's big explanation about this in the included docs change.

The TL;DR is: we can now optionally queue the request and generate it
asynchronously wrt. the incoming injection request.

There's also a throttle that can be used to constrain this, because
the asynchronous submission disconnects the injection request from
any kind of back pressure that we'd otherwise have to indicate to
the injector that there might be load related issues.
2024-09-06 10:12:33 -07:00
Wez Furlong 7fe88f34a6 queue: make the default strategy SingletonTimerWheel 2024-09-02 14:08:48 -07:00
Wez Furlong 541b8f28e4 shaping: add provider concept to shaping helper
This enables shaping based on MX hostname and domain name matching
rules.

At a lower level, this is supported via two new options:
additional_connection_limits and additional_message_rate_throttles that
allow specifying arbitrarily scoped named limits and throttles, which
in addition to allowing provider-based rules in the shaping helper,
allow things like global or other more esoteric scoping of constraints.

closes: https://github.com/KumoCorp/kumomta/pull/260
2024-09-02 10:42:15 -07:00
Wez Furlong a42871cb11 docs: update since dev -> 2024.09.02-c5476b89 2024-09-02 07:27:50 -07:00
Wez Furlong a18308a3b2 docs: mention SingletonTimerWheel 2024-09-01 15:38:12 -07:00
Wez Furlong 7961bff955 docs: split configure_local_logs into multiple pages 2024-08-18 22:28:41 -07:00
Wez Furlong 75e8a32b59 docs: split start_http_listener into multiple pages 2024-08-18 22:18:59 -07:00
Wez Furlong 1b32aa1b4b docs: split start_esmtp_listener into multiple pages 2024-08-18 20:02:35 -07:00
Wez Furlong 34df28bbb1 docs: fixup a few links from page splitting 2024-08-18 19:52:19 -07:00
Wez Furlong dbdd69a8c7 docs: split make_egress_source into separate files 2024-08-18 19:47:35 -07:00
Wez Furlong 632357ac70 docs: split make_egress_pool into separate pages 2024-08-18 19:40:47 -07:00
Wez Furlong b775816885 docs: split make_egress_path into separate pages 2024-08-18 19:33:31 -07:00
Wez Furlong 1bd2b00b4e docs: move make_listener_domain options to their own pages 2024-08-18 19:19:30 -07:00
Wez Furlong 4af9c7035f docs: move make_queue_config fields to their own pages
This makes them easier to search for, and find.
2024-08-18 19:14:34 -07:00
Wez Furlong 84056ffb44 add disk space monitoring
This commit adds disk space monitors for the configured spool
and local log file locations.

Incoming messages will be rejected when the available space is below
the configured amount.

The default minimum is 10%.
2024-08-18 09:17:42 -07:00
Wez Furlong 12d1569973 improve bounce classification performance
For large classifier rulesets (more than 3,000 rules), the cost
of classifying any single response can be as high as 2ms.

This is significant; given that the loggers are each single threaded a
2ms overhead limits the maximum throughput to 500 messages per second.

This commit improves the structure of the code in order to mitigate
the potential for a bottleneck:

* Don't bother categorizing Reception records. They are not bounces
  and are generated by the local machine.  It's a waste of CPU and
  introduces the potential to put back pressure on the injector.
* Introduce a cache for classification results. The cache is split
  into two parts so that unclassified results don't churn out the
  successfully classified results.
* Introduce a bounce-classification thread pool. If we are unlucky
  and encounter a long series of "random" responses with no cache
  hits, and have up to 2ms per classification constraining us to
  around 500 msgs/s, then we need to apply more CPU cores to the
  classifier to achieve multiples of that throughput, and that is
  what we have here. We spawn 1/4 the number of cores threads
  into this thread pool.
2024-08-16 21:16:49 -07:00
Wez Furlong e8e0f208ee queue: add strategy option choose between skiplist and timerwheel
Previously we were using only our timeq module, which is built on top of
hashed hierarchical timer wheels.

Timer wheels have O(1) insertion and removal which are excellent
properties for larger delayed queues.

However, they do not know how to answer the question "when is the
next item due", but only "what is due in the next tick".

The underlying timer wheel implementation assumes a 1ms granularity
which is a little bit at-odds with our pragmatic view of the scheduled
queue, which is "if it's in there, precision timing isn't important, and
it's generally fine to consider once per minute", requiring that we
either aggressively scheduled a maintainer task to wake up every 1ms per
scheduled queue (untenable!) or have it wake up no more than once per
second but ideally closer to once per minute to then tick however
milliseconds are necessary to advance the wheel to the current slot.

For small numbers of scheduled queues with sufficiently large retry
intervals this hasn't bubbled up as an issue so far, but it bothers
me that it isn't as efficient as it could be because we have to wake up
reasonably frequently to keep things ticking over, and that introduces
higher continual CPU utilization. It's small, but I worry about
the aggregate cost spread over very large numbers of scheduled queues.

What I really want here is a a timer wheel that I can tick with
arbitrary granularity and with that in mind I took a look at adapting
the handful of existing implementations and found that we're already
using the cleanest implementation, and it would take some effort that I
didn't really want to spend right now.

I opted for a reasonably simple alternative option, which is to adopt a
skiplist for the queue. This has O(log n) insertion to maintain ordering
with O(1) removal and can answer "when is the next item due".  What this
means is that we pay a slightly higher insertion cost one-time in
exchange for being able to put the maintainer for the queue asleep until
we need it, and not have to keep waking up between times, which should
scale better.

What this means in practice is that we now wake up the maintainer either
when the next message is due, or once per minute to re-evaluate the
queue configuration hook, so we're slightly better off, but totally
where I'd like to be.

I've introduced a reap_interval (default 10 minutes) and a
refresh_interval (default 1 minute) as parameters in get_queue_config so
that you can increase that 1m interval for reloading.

What I'd like to do in a follow up commit is introduce a way to define
the refresh policy. For example, it would be neat to say "watch my
policy directory and refresh when it changes", which would make things
the most efficient for many users.  For those that are loading their
config from a remote datasource, we'd need to consider some other
mechanism for this; maybe some kind of long-poll or pubsub, but will
obviously still be able to support the current interval based polling.

Now, with all of that said: I didn't want to switch the product
default over and hope for best, so what I did was add a strategy
option to allow this to be adopted on a per-queue basis.

Since I was in here adding some options, I also added an option
that allows explicitly setting the interval used for timerwheel
ticks, so you now have a lot more opportunities for tuning this
stuff.
2024-08-13 16:46:34 -07:00
Wez Furlong 9e757c36d3 add max_connections limit to esmtp_listener
Previously we'd go as far as the OS would let us.

This introduces the ability to set an upper bound, and our default for
this is 32k connections, or half of the possible u16 port space.  I
picked half because the ideal for an MTA is using half of its resources
to receive and the other half to send.  The math for that is more
complex for multi-homed machines or systems using proxies, but it feels
like a reasonable default; not too low that it will be painfully
surprising for existing users to discover on upgrade, and not so high
that new installations are as easily overwhelmed in the face of high
incoming traffic.

A new total_connections_denied counter is added that is bumped
whenever this or the over-memory limit are reached and we turn
away a session with a 421. The idea is that the operator may
want to investigate these events, and we don't otherwise have
a stream of information about them because they are deliberately
not logged to the normal delivery logs.
2024-08-10 08:28:04 -07:00
Wez Furlong d014237eb7 docs: more tweaks to sources
try to nudge folks away from adopting copypasta of the advanced
section; we've seen more than few people using this when they
should just use the sources policy helper.

Add the note about the weighted robin implementation to make_egress_pool
as well.
2024-07-27 07:08:31 -07:00
Wez Furlong d62781e7fa rfc5321 client: add openssl and rustls cipher/options 2024-07-20 16:16:47 -07:00
Wez Furlong b003e49c9c rfc5321: split out banner_timeout from connect_timeout
The motivation for this is:

My test environment is not permitted to reach outbound port 25.
If I run an ad-hoc test without setting up an explicit sink,
I end up with messages that try to reach the public internet.
Since they are blocked at a firewall, each of the MX hosts in
the connection plan is subject to a 60s wait before trying the next
thing.

In addition, this can cause the shutdown to take longer while
we wait for the in-flight delivery attempts to complete.

Making a separate configuration option allows the local administrator
to decide how to split the time waiting for a connection from
the time waiting for the banner.

refs: https://github.com/KumoCorp/kumomta/issues/196
2024-07-12 07:54:43 -07:00
Tom Mairs 53b16cefb4 fix typo 2024-07-08 20:40:32 +00:00
Wez Furlong f7604a3f7f docs: cut over toml examples to toml_data data macro
refs: https://github.com/KumoCorp/kumomta/issues/212
2024-07-03 16:09:52 -07:00
Wez Furlong e683fed556 docs: move Log Record to its own reference page
This makes it a bit easier to find and link to.
2024-06-27 08:28:45 -07:00
Wez Furlong f8c3429738 serde: move json/toml to new kumo.serde module. Added YAML.
This helps to avoid bloating kumo-server-common, and makes it
easier to group related functions together in the docs.

The original names are still usable; we'll remove them in a
future release.
2024-06-26 11:08:15 -07:00
Wez Furlong 8673045fff docs: update for latest release 2024-06-10 09:30:17 -07:00
Wez Furlong 4dad617d14 remove EgressPathConfig::suspended logic
When this was added, it was to enable TSA daemon to express
and convey that a given path should be suspended.

The implementation was objectively unpleasant, turning the
fast path of egress source assignment from a simple single
iteration of the weighted round robin logic to N (where N
is the number of sources in a pool) iterations to try
and figure out if a suspension is active.

Now that we have TSA subscriptions that update the admin
suspension information in realtime, we can now simply
rely on that source of information.

This commit removes the logic associated with the deprecated
suspended flag and tidies up the code, making that fast
path a little more fast, and making the code a bit easier
to reason about.
2024-05-02 06:18:14 -07:00
Wez Furlong 9e95303e6b add kumo.available_parallelism()
This can be helpful for writing configuration files for systems
that scale to the available compute resources.
2024-04-29 08:23:27 -07:00
Wez Furlong e94506fd96 Add new Rejection log event
We skip logging the 421 we generate while shutting down because
it feels a bit redundant; you'll see the server shutting down
in the journal anyway.

refs: https://github.com/KumoCorp/kumomta/issues/88
2024-03-29 16:37:37 -07:00
Wez Furlong 755eb848e2 add glob, read_dir
closes: https://github.com/KumoCorp/kumomta/issues/161
2024-03-29 08:25:51 -07:00