Commit Graph
37 Commits
Author SHA1 Message Date
Wez Furlong 15e886646c fix compilation of individual crates 2023-04-18 16:31:52 -07:00
Wez Furlong 07b75dd117 remove oldtime feature from chrono crate
it pulls in an old version of the time crate that flags many
rust projects as being vulnerable to an old CVE.

We still have other references to time that I'll remove in a follow up.
2023-04-18 15:02:59 -07:00
Wez Furlong f9c6eb8ce3 add ed25519 dkim signer 2023-03-16 10:23:54 -07:00
Wez Furlong b3f3f877df add functions for working with address headers 2023-03-14 18:53:47 -07:00
Wez Furlong ec920535e3 refactor: move arf and bounce report parsing to kumo-log-types
This reduces transitive deps for other crates that want ostensibly just
the type definitions.
2023-03-12 20:16:05 -07:00
Wez Furlong 722876a144 first pass at memory awareness
This commit introduces awareness of memory limits that may
have been established for the process.

The idea is that the hard/soft limits are read from the active
cgroup, falling back to classic ulimit hard/soft limits, falling
back to the system RAM size.

In the absence of an explicitly configured hard limit, the RAM size
is used for the hard limit.

In the absence of an explicitly configured soft limit, 75% of the
hard limit is used for the soft limit.

A background thread monitors the memory usage and (potentially
adjusted) memory limits.

A low memory state is when the usage is within 10% of the soft limit.
In this state, we start to trim back memory usage, shrinking loaded
data when messages are placed into the ready queue.

A more severe memory state is when the usage exceeds the soft limit.
In this state, new message reception is rejected until the usage
recovers.

kumod doesn't do anything directly with the hard limit, but assumes
that the system will terminate the process with no opportunity to
safely clean up if that value is reached.

In order to reduce the memory usage, the allocator has been switched
to jemalloc which has superior management of fragmentation and
a control interface to request release of various memory caches.

We make use of jemalloc specific functions in the tokio thread pools;
when they park (idle), we release the thread local cache, and when
we reach the soft limit we aggressively flush the caches until
memory usage falls below the limit.

There's like some room for tuning of the thresholds around this,
but this is a reasonable start.

Note that there are no explicit config options in kumod to set
the soft and hard limits: those are taken from the process
environment and can be simply set either via ulimit in a calling
shell script, or via systemd service configuration.

We may introduce some knobs for the low memory state threshold
in the future.
2023-03-09 18:50:24 -07:00
Wez Furlong 56135506f2 refactor: use any_err in more places 2023-03-05 10:44:54 -07:00
Wez Furlong c184214253 allow loading TLS key+cert from hashicorp vault
refactor to allow reusing the same key loader logic for dkim, smtp
and http.
2023-03-04 11:01:35 -07:00
Wez Furlong 38e60f9274 rename vault object fields to have vault_ prefix
This disambiguates for future alternative credential storage
systems.
2023-03-04 10:29:25 -07:00
Wez Furlong 6204642270 add trace headers configuration and link to ARF parsing 2023-03-04 07:22:02 -07:00
Wez Furlong bfe3c49d77 add rfc5965 ARF report parsing
Refactor the rfc3464 parsing to simplify both of them
2023-03-03 13:58:12 -07:00
Wez Furlong 2000be18d4 fix formatting 2023-03-03 11:14:03 -07:00
Wez Furlong 7d76b3d9d7 add support for retrieving signing keys from hashicorp vault 2023-03-03 10:32:16 -07:00
Wez Furlong ef7fa59355 synthesize OOB log records from OOB reports
* When logging the reception of a message, if we can parse it
  as an rfc3464 oob report, then synthesize OOB records for
  each recipient
* Add config to allow relaying for domains for which bounces
  are received, so that we can accept their message content.
* If the domain config allows bounces but not relaying, then
  the message will not be spooled or queued after reception;
  it will be dropped with no additional logging.
2023-03-03 06:53:33 -07:00
Wez Furlong da5f2433c0 add rfc3464 delivery status report parser 2023-03-02 14:46:30 -07:00
Wez Furlong c7a8405ddf fix code formatting 2023-03-01 09:45:22 -07:00
Wez Furlong 2b0ba702cb add scheduling constraints
This is implemented by allowing the Message:set_due method to
load the message metadata to consult the scheduling constraints,
which should mean that all scheduling updates have the constraints
applied to them.
2023-03-01 09:43:48 -07:00
Wez Furlong 39e08d602b add scheduling restriction datatype
This will be used in the future to adjust the message
sending schedule on a per-message basis.
2023-03-01 09:43:48 -07:00
Wez Furlong 0eefb02bed make destination site queues per-tenant
To facilitate this, formatlize the `campaign:tenant@domain` naming
and add a helper type to parse and format that tuple of information
to make it easier to work with in the code.

Adjust the get_x_config events to accept those parameters.
2023-02-26 19:59:56 -07:00
Wez Furlong 6dfb44012e add some header manipulation functions 2023-02-26 15:01:05 -07:00
Wez Furlong 1d9f65d07b dkim: refactor
This will support adding ed25519 signing in the future,
but stops short because I need to read up on the storage:
the library only supports PKCS8 DER encoded binary data.
2023-02-26 07:27:18 -07:00
Wez Furlong b25ff76118 add dkim signing
A fairly sprawling commit:

* Move config to its own crate to facilitate making things more modular
* Crates/modules can now provide a registration function that can be
  used to setup functions in the lua environment
* Message crate now has a dkim module with a signer type that can
  be loaded from lua; signers are cached (with ttl) and shareable
* Message now has a dkim_sign method that does the signing, as well
  as methods for appending and prepending headers that are necessary
  to support signing.
2023-02-21 21:18:49 -07:00
Wez Furlong c049277d61 parallelize writing spool and metadata when saving the message 2023-02-20 18:21:24 -07:00
Wez Furlong caf47d4c4e add traffic generator 2023-02-20 10:30:58 -07:00
Wez Furlong 9149063b57 Add Received header at reception time
Also fix missing CRLFs in message bodies!
2023-02-19 16:49:11 -07:00
Wez Furlong f8fc4582fc add counters for messages in different states 2023-02-19 15:39:51 -07:00
Wez Furlong 17e5d7f113 refactor queue insertion logic
more DRY, less likely to miss out on bumping metrics
2023-02-19 12:01:29 -07:00
Wez Furlong 54e230ffca message expiration
* Switch uuids to v1 format, so that we can cheaply determine
  when a message was created without having to load its metadata
  from the spool
* Add some message delivery parameters; retry interval, limit, max age
* Respect those parameters when spooling in and when we encounter
  a transient failure.
2023-02-18 14:39:54 -07:00
Wez Furlong 667bb91525 formalize tenant/campaign components of default queue naming 2023-02-18 07:28:03 -07:00
Wez Furlong d889acc275 replace mail-send with our own client implementation
This removes a dep on an AGPL crate
2023-02-17 11:08:59 -07:00
Wez Furlong 82f9ace9d1 connect spool 2023-02-14 18:33:32 -07:00
Wez Furlong 5422a5fa76 can now deliver mail 2023-02-14 16:11:24 -07:00
Wez Furlong 800bcd7217 connect esmtp server to queue
We can now queue messages to per-domain queues.
The per-domain queues feed into a destination site keyed
by distinct set of MX host names.

The destination site doesn't know what to do with messages yet.
2023-02-13 14:48:48 -07:00
Wez Furlong 5a8bc19a1c prep for adding a Queue type 2023-02-13 09:38:10 -07:00
Wez Furlong 3bddce299a fixup tests 2023-02-12 15:26:24 -07:00
Wez Furlong 79816d9479 adjust policy event to take bifurcated messages rather than state 2023-02-12 15:13:09 -07:00
Wez Furlong aeb49003ad start building out the Message type 2023-02-12 14:43:10 -07:00