Commit Graph
354 Commits
Author SHA1 Message Date
Wez Furlong 4055c50522 authz: introduce an ACL facility
This commit is a step towards some general improvements around
our handling of authentication and authorization.

This commit is focused primarily on authorization, but there are
some adjustments to how we track authentication as part of enabling
that.

We now have a separate AuthInfo type that holds the overall
authentication information/context associated with an inbound
SMTP or HTTP session.

It is populated with the peer_address as a fact rather than a statement
of trust.

If authentication via the appropriate lua auth callback is successful,
then the AuthInfo has additional identities added.

There are some types and events for loading access control lists and
matching their rules against an AuthInfo.

There is now a system default ACL that is equivalent to the prior
hard-coded access policy that was encoded into each HTTP endpoint.

This change makes it possible to replace the ACL with a
user-defined ACL.

Later will be some work on authentication to allow more options
for HTTP auth.
2025-12-18 06:30:06 +00:00
Daniel Smith 9738d2913b add some rules and divide other rules into appropriate labels 2025-12-04 14:56:34 -05:00
Wez Furlong d47e280b9a ci: pruning in the builder images 2025-11-25 13:14:56 +00:00
Wez Furlong a76857cffb ci: try alternative way to install the rust-toolchain version
This should avoid having two different versions of the toolchain in the
common case, and reduces the size of the builder image.
2025-11-23 10:21:00 +00:00
Wez Furlong 7b583047d2 ci: pre-download the rust-toolchain version in the builder image 2025-11-23 10:04:45 +00:00
Wez Furlong 0b2c7871b6 ci: improve deb package compression performance 2025-11-23 09:56:30 +00:00
Wez Furlong cc03878c23 ci: adjust builder sccache build for amazonlinux:2
It doesn't like the full sccache build due to some wonkyness
with openss on this old distro.

Let's just pave over this by not enabling the full build
on that platform.
2025-11-22 21:44:41 +00:00
Wez Furlong 3c75f92d76 ci: re-enable sccache default features
At some point turning off most features used to make things work in our
environments, but looking at things today, I think it basically makes
it do nothing useful any more.

Turning things off just made the image build a hair faster and the
image a hair lighter.

So let's just turn it back on
2025-11-22 21:26:53 +00:00
Wez Furlong 7ac9a5eac0 smtp_dispatcher: handle pathologic all-452 case
Continuing in the same vein as 94628f06ab,
ensure that we have a reasonable outcome when a batch of size > 1
encounters 100% ambiguous 452 responses.

Without special consideration we'd end up in an infinite retry loop for
these, as we'd think that we'd hit the recpient limit on the connection
every time.

This commit introduces a small amount of state into the dispatcher so
that we can remember the set of (spoolid, recipient) from the prior
transaction on the session.

When deciding whether something is eligible for immediate retry
we will gate that choice on the current (spoolid, recipient) being
absent from the prior set of ids.  In this way, we bound the immediate
retry for a recipient to one per connection.

To make things a bit more robust when trying to decide whether a 452
means "too many recipients" or not, if we're not sure, we now call out
to the bounce classifier which can be configured to emit a
`TooManyRecipients` classification.  If the classifier produces either
that or some non-Uncategorized response, then we have a confident
assessment.  Otherwise, we're unsure and will factor that into the
retry strategy.
2025-11-07 08:13:36 +00:00
Sophia Turner 96bdbef106 add a dmarc lua test, fix API 2025-11-07 08:08:29 +00:00
Wez Furlong 4c6d7ca8ea add policy-extras.mail_auth module
This aggregates the various authentication-results producing auth checks
into a more convenient function.

Part of this change improves some plumbing in the dkim checking (we no
longer raise an error for a missing From, but instead indicate a failed
dkim result), and we now support passing down a resolver name to the
various checking functions, to facilitate testing and other more
advanced use cases.

refs: https://github.com/KumoCorp/kumomta/issues/16
refs: https://github.com/KumoCorp/kumomta/issues/84
2025-11-02 11:56:57 +00:00
Wez Furlong b73d81b0fc dns: utilities and plumbing for querying DNSBLs
This commit does some plumbing work to allow defining alternative
resolvers with different names that can be used to query different
upstream DNS servers.

This is most useful when implement DNSBLs where you might have a custom
DNS server configured with one or more RBL zones that is reserved purely
for RBL lookups.

The plumbing introduces a more regular syntax for defining one of the
various implementations of the Resolver trait, as well as a new
Aggregate resolver impl that can query across multiple Resolvers until a
query is satisfied.

This allows some interesting and powerful configurations, such as
loading a static zone file into memory to query it directly, and/or
blending that together with querying either the system or some other
upstream DNS server as a fallback.

The various lookup functions (except for MX!) have been updated to
accept an optional alternate resolver name, so that they work together
with the above.

A new rbl_lookup function is also provided as a convenience for querying
the most common form of RBLS.

ptr_host and reverse_ip are two string utility functions that are likely
not going to be widely used, but are very convenient to have when you
do have a usecase that requires it!

closes: https://github.com/KumoCorp/kumomta/issues/269
2025-10-10 18:45:52 +01:00
Wez Furlong db5ebb88a7 message: expose recipient list to lua api
message:recipient() may now return an array style table
holding the recipient list, if there is more than a single
recipient on the message.

Since this can be somewhat ambiguous/frustrating to work with,
there is now also a message:recipient_list() that will always
return an array style table, even if it holds just a single
element.

The included helpers have been updated to use `message:recipient_list`.

message:set_recipient() will now optionally accept an array
style table holding the recipient list to be set.
2025-10-07 07:52:58 +01:00
Wez Furlong 53a6bc3b7e log_hooks: add helper for creating a disposition hook 2025-09-09 10:39:52 +01:00
Wez Furlong f85094282f migrate run-lua-test to rust
At least one of our supported platforms doesn't have a new enough
python to run the python version, let's just use rust for this.
2025-08-13 07:09:53 +01:00
Wez Furlong c28560b4f5 run-lua-test: fixup when run as root (eg: in CI)
Need to pass `--user` in that case
2025-08-11 14:21:02 +01:00
Wez Furlong 9f316ed689 ci: improve run-lua-test
This commit:

* Adds auto-discovery of both module style and crate style tests
* Runs each test via its own instance of `kumod`, so that one test
  cannot pollute the state of another
* Runs all lua tests concurrently
2025-08-11 13:24:41 +01:00
Wez Furlong 7e6ca34e2d new: kumo.fs lua module
The read_dir and glob functions have been logically moved into that new
namespace, leaving deprecated versions of them in the `kumo` module.

A new `kumo.fs.open` function that works similarly to `io.open` is
provided.  This function cooperates with the kumo async io scheduler
and won't block it if the filesystem is under pressure.

It returns file handles that are simlar to the builtin lua file handle
objects, but do not support formatting or parsing of writes or reads
respectively: the calling code is responsible for that.  The rationale
for this difference is that is that lua's semantics for those functions
are frankly a bit weird and are hard to replicate precisely.
2025-07-23 16:51:06 +01:00
Wez Furlong 7d617bb270 add kumo.mpsc.define
This function allows defining a non-durable, non-persistent, in-memory
queue that is intended to be used as glue when building up more advanced
processing flows within kumomta.

The intent is that the queue is processed from within a task spawned via
`spawn_task`.
2025-07-23 12:44:10 +01:00
kayozakiandWez Furlong a7315633de add kumo.dns.lookup_ptr (#390)
* add lookup_ptr

Co-authored-by: Wez Furlong <wez@wezfurlong.org>
2025-07-22 08:45:27 +01:00
Mike Hillyer 58e9770206 We miss you Mister Rogers. 2025-07-18 12:11:14 -04:00
Mike Hillyer 41d251f20d Update links to Comcast docs 2025-07-14 12:19:40 -04:00
smsvip 76f2e833c2 Update shaping.toml
"gmail.com".automation --> regex = "Our system has detected an unusual rate"   

This item is repeated, although it will be override .
2025-07-01 13:11:09 +01:00
Mike Hillyer c7daa01ef2 Whoops, already required. 2025-06-11 18:34:05 -04:00
Mike Hillyer 748c700c7b Adding TLS required for Comcast as per @AlexB in the Discord. 2025-06-11 18:29:38 -04:00
Mike Hillyer 9dba9c5b5f Update traffic shaping defaults to require TLS for Google as per conversation with Gmail admins. 2025-06-10 09:26:07 -04:00
Wez Furlong fedd2959b6 enhance log_arf, log_oob to support LogThenDrop
It is common to want to express that incoming reports should
be logged, but not relayed.

This commit facilitates that by expanding `log_arf` and `log_oob`
to allow more than just a simple boolean value.

We now support both LogThenRelay and LogThenDrop as dispositions
for an incoming report, as well as Ignore to not care about the
report content.

For the LogThenDrop case we'll log only the incoming OOB or Feedback
record to the logs and then discard the incoming message.

For LogThenRelay we'll log the incoming OOB/Feedback report as well
as enqueue the message and log a Reception and, subsequently, records
for its delivery attempts.

The previously supported boolean values are mapped to `Ignore` (false)
and `LogThenRelay` (true), respectively: their behavior is the same as
in prior releases.

The integration test and smtp server tracing infra has been enhanced a
bit to support extracting these new disposition states from the tracer
during the integration test.
2025-05-05 08:25:40 -07:00
Wez Furlong 16fad7b260 promote docker_utils to policy-extras
It is useful enough and avoids some reptitions between
the single node and docker swarm examples.

closes: https://github.com/KumoCorp/kumomta/issues/359
2025-05-02 10:09:57 -07:00
Wez Furlong f92df0fca0 lruttl: introduce allow_stale_reads option
This is paired with a corresponding field in the memoize options
struct, which is in turn exposed to the shaping helper shaping_data
cache via the `allow_stale_shaping_data` field.

The effect of setting this to true is:

* Undoes the effect of invalidate_with_epoch, as stale reads cannot
  be epoch based
* If a semaphore wait times out, and a stale value was present in
  the cache, that stale value will be returned to the caller

To facilitate this behavior, the lruttl cache introduces a new
state for a cached value: `Refreshing`, which is a combination
of both `Present` and `Pending`.

When stale reads are allowed, we take care to avoid unilaterally
replacing `Present` with `Pending` when an item has expired.

Whenever we satisfy a lookup with a stale value, we will bump a new
lruttl_stale_count counter for that cache.  Previously, we would
classify those as errors.

Something else that changed as part of this commit, is that we now set
an overall deadline for the semaphore wait operation; previously, each
wait would allow for up to the specified semaphore timeout, but now the
total wait time for that lookup will be bounded to the specified
timeout.
2025-04-30 14:01:26 -07:00
Kyle Renfrow 38e52c0bbf Adding shaping rules for Yahoo deferral codes TSS05, IPTS04 and IPTS05 in addition to existing TSS04 rule
Yahoo confirmed these four should all be treated similarly.
2025-04-17 14:27:51 -04:00
Wez Furlong c22e98bcd5 add log-filter.py helper script
This is to help humans grok a diagnostic log file a bit better.
This isn't a supported product surface and isn't deployed with
kumomta.  It is intended primarily as a log debugging aid.
2025-04-16 14:53:25 -07:00
Mike Hillyer b034b1b9df Update bounces.toml
Adding a couple of missed codes.
2025-04-07 22:21:22 -04:00
Wez Furlong 95654c61fd shaping.lua: increase shaping_data cache capacity
I've observed a system where we had more than 4 outstanding
shaping_data lookups from different ConfigEpochs; that system
had slow dns resolution and we ended up looping for these because
the capacity was not high enough and the population of the result
always took too long.

Let's just give ourselves a bit more headroom; this coupled
with the earlier commits that adjust retry behavior should
help to smooth things out in this situation.
2025-04-06 09:55:02 -07:00
Wez Furlong 5eb57e63d5 shaping.toml: disable dane for office365-dane
We cannot default it to enabled because a fully working
dane setup requires additional configuration in the resolver
and we cannot guarantee that that has happened here.
2025-04-06 07:47:00 -07:00
Wez Furlong f8bbacba54 systemd: read optional environment files
It is sometimes necessary to set environment variables
to adjust some early-startup options that need to be
applied before enough of the system is ready to read
lua policy files.

While it is possible to use `systemctl edit SERVICE`
and enter systemd-specific directives to configure that,
it is not the most convenient thing.

What this commit does is introduce 3 new optional files:

* /opt/kumomta/etc/kumo-common.env: sourced by kumod and tsa
* /opt/kumomta/etc/tsa-daemon.env: sourced by tsa
* /opt/kumomta/etc/kumod.env: sourced by kumod

The format of these files is `NAME=VALUE` on each line, as
per the `EnvironmentFile` docs in systemd.

One practical application for this is on an over-committed system
where the number of reported cores is larger than the number of
available cores.

For such a system you will need to configure the
`KUMO_AVAILABLE_PARALLELISM` environment variable for each kumo
service running on your system. With these environment files you
can do that simply by creating `/opt/kumomta/etc/kumo-common.env`
with a line like this inside:

```
KUMO_AVAILABLE_PARALLELISM=48
```
2025-04-03 07:26:15 -07:00
Wez Furlong 3b14587192 fix delayed shutdown for non-smtp delivery handlers
Occasionally we'll have someone report that systemd timed out
and sigkill'd their kumo on shutdown.

One possible scenario for this is a lua delivery handler that
is taking too long, presumably because the other end of it
(eg: webhook or other custom endpoint) is not responding in
a timely fashion.

The way that we handle shutdown is that we compute a maximum
theoretical timeout value by summing up all of the smtp client
timeout values.  Some of those can be several minutes in
duration because the are using default values derived from
a very conservative set of values suggested by the SMTP
RFCs from the '70s.

Those obviously should not apply to a custom delivery handler,
but also, in the context of an established SMTP session, we
should not add in the connection-establishment-specific values
when we're just waiting for a per-message send.

This commit addresses this situation on two fronts:

* Introduce a new system_shutdown_timeout value that allows the
  user to conveniently express their desired timeout value
  in a single option.  This is *not* set by default!
* The default value for system_shutdown_timeout is computed by
  summing the per-message-delivery smtp timeout options, which
  is a much more reasonable, and more importantly, shorter than
  our 300s TimeoutStopSec value in kumomta.service
2025-04-02 14:21:31 -07:00
Wez Furlong 1e55d47b93 Add default TSA shaping config to shaping.toml
We've seen folks trip over this a couple of times, and it's
because we don't document this and include it in the defaults,
so here we go.
2025-03-31 12:02:54 -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 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 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 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 bb2e671f4e add explain-throttle script 2025-03-12 11:07:52 -07:00
Wez Furlong f1f5d27591 sources.lua: surface socks5_proxy_source_address issues better
This field only accepts IP addresses; it is an error to use
a DNS name with it.

The sources helper was swallowing the helpful part of the context
about the issue with that field.

This commit ensures that we do surface it.
2025-03-11 06:55:44 -07:00
Wez Furlong f23875b1a1 shaping.lua: mostly switch prints to kumo.log_XXX
Keeping the validation stuff as prints for the time being,
as I think that looks nicer in the context of a standalone
validation mode.
2025-03-07 08:06:35 -07:00
Wez Furlong 5c154417c7 shaping.lua: fix missing string.format calls
closes: https://github.com/KumoCorp/kumomta/issues/351
2025-03-04 16:24:58 -07:00
Wez Furlong 0666374f58 tsa: expose underlying log hook back_pressure to configuration 2025-02-24 08:59:58 -07:00
Wez Furlong a805184a8f remove deprecated unused fields from tsa shaping object 2025-02-24 08:59:24 -07:00
Wez Furlong 161e7b6d3b shaping.lua: ignore Rebind and Delayed log record types
Cut out rebind and delayed log records from the feed to the TSA
daemons.  These don't make sense to have TSA rules applied to
them, and in some configurations (such as deferred injection)
these records can 2x the volume of records being processed.

With pre-filtering enabled those records won't make it to the TSA
daemon, but we would still need to run those records through the
rules to realize that.

With this commit we can cut these out in O(1) and minimize the
local CPU cost of that.
2025-02-24 08:31:46 -07:00