Commit Graph
113 Commits
Author SHA1 Message Date
Wez Furlong c8a8d7da00 docs: install gelatyx earlier 2023-02-25 11:24:37 -07:00
Wez Furlong b8573f8059 ci: fix typo in doc builder 2023-02-25 11:10:21 -07:00
Wez Furlong bb328ca000 ci: automate doc build and publish to gh_pages branch 2023-02-25 11:00:18 -07:00
Wez Furlong 831bfe9aab docs: skeleton for building the docs
Rather than edit SUMMARY.md, you edit docs/generate-toc.py
and it will flesh out sections based on the list of files
in a directory.
2023-02-25 10:50:58 -07:00
Wez Furlong c1849551ed http injector: make a first pass at it
Still needs to call out to lua for routing and meta updates.
May need to parallelize the generation stage if throughput
isn't where we want it to be.
2023-02-25 10:12:07 -07:00
Wez Furlong 282dae670d refactor: move http auth to its own module 2023-02-24 11:17:21 -07:00
Wez Furlong 79ff6354c7 format 2023-02-24 10:53:17 -07:00
Wez Furlong 12f1637087 http: add https and some plumbing for auth
* Reuse the tls acceptor stuff from the smtp_server.
  We'll automatically generate self-signed certs when
  none are provided.
* Add trusted_hosts setting for the http server
* Add an auth middleware that will accept connections from
  trusted hosts as pre-authenticated. Other hosts must provide
  http authorization.
* Add lua hooks for the policy script to validate either http
  basic auth (user+pass), or bearer auth (token).

There's not currently an authentication storage subsystem, but
the lua hook allows for very basic stuff to be configured, and
could also be used to employ eg: looking things up from a database
once we add some lua utility functions for that purpose.

The `/metrics` endpoint will only respond to trusted IPs.

Other endpoints all require some kind of successful authentication.
2023-02-24 10:47:06 -07:00
Wez Furlong c9ad8db439 note about graceful shutdown of the http server 2023-02-24 06:30:14 -07:00
Wez Furlong 995e066572 queue: fix priority inversion issue with QueueManager
QueueManager::insert could acquire MANAGER lock then a queue handle
lock.

Meanwhile, the queue maintainer would hold a queue handle lock
and then attempt to acquire MANAGER lock when idling out and removing
itself, leading to a livelock because MANAGER is protected by a
tokio Mutex which ping pongs in and out of the event loop.
2023-02-23 20:35:16 -07:00
Wez Furlong af653a489f make docker build work with older versions of docker 2023-02-23 10:16:48 -07:00
Wez Furlong 2cba4196c5 revise docker build; move away from musl/alpine
A downside of pulling in rocksdb is that it is a pretty big
C++ library and musl/alpine don't really get on with it.

Switch to using the latest ubuntu LTS image as our base.
2023-02-23 10:07:29 -07:00
Wez Furlong 602e9721c9 CI: fixup path for rename from smtpd -> kumod 2023-02-23 07:57:08 -07:00
Wez Furlong 6b85cfb2ee CI: don't require a tty to build docker image 2023-02-23 07:38:12 -07:00
Wez Furlong 42b173eac5 CI: take a run at building the docker image 2023-02-23 07:36:48 -07:00
Wez Furlong df232cbc48 refactor: rename shutdown/lifetime -> lifecycle 2023-02-23 07:30:32 -07:00
Wez Furlong 229a093560 shutdown if we have errors setting up the spool
Adds some plumbing that allows the application to request
a shutdown that is channelled along the same path as ctrl-c
handling.

If we have errors defining spools or during spool start,
then we request a shutdown on the basis that we can't store
anything and it would be unsafe to continue.
2023-02-23 07:23:06 -07:00
Wez Furlong a2fa65a5cc spool: improve some startup error messages 2023-02-23 07:08:10 -07:00
Wez Furlong 6067de108c spool: use bytes rather than strings for rocksdb keys
Reduces space of id keys by half
2023-02-22 23:28:38 -07:00
Wez Furlong 175dbb46e0 spool: break out of startup enumeration early if ctrl-c is pressed 2023-02-22 23:23:42 -07:00
Wez Furlong 5438824ef3 smtp_server: add reception limits
allow limiting the number of messages and the number of recipients
that come in on a single connection
2023-02-22 23:12:39 -07:00
Wez Furlong 029b922e68 smtp_server: avoid logging verbose errors when client disconnects
This transforms any read error into a Disconnect that we process
silently.

The error is logged at trace level.
2023-02-22 20:26:28 -07:00
Wez Furlong dd7c7a6292 graceful shutdown part 2
This adds some logic to save any messages that had spooling
deferred and release them once shutdown is requested.
2023-02-22 18:50:19 -07:00
Wez Furlong 85f4ab69b9 add graceful shutdown, part 1
This teaches the smtp listener and delivery sides
how to shutdown when a shutdown is requested, as well
as how to indicate when they are still doing important
work.

This doesn't guarantee that any deferred spooling is
done; that will be part 2.
2023-02-22 17:00:00 -07:00
Wez Furlong 3c5959aa9d fixup build, add compression level as an option 2023-02-22 12:52:44 -07:00
Wez Furlong daf3b87753 add num_attempts field, and zstd compress the logs
I don't plan to remove compression or to allow it to be disabled: it
makes a massive difference to the size of the log files and saves IO and
storage space.
2023-02-22 12:33:58 -07:00
Wez Furlong bcd4a6fc6d take a crack at logging receptions and deliveries 2023-02-22 11:57:26 -07:00
Wez Furlong b03f74f2c0 kumod: remove unused parameter 2023-02-22 07:47:58 -07:00
Wez Furlong 681784f3e1 allow "mail from:user@host" with no <>
Same for "rcpt to". The <> are required in the ABNF in the spec,
but they are widely considered to be optional by major implementations,
which makes it convenient when ad-hoc testing via telnet.

We require the <> when ESMTP mail from or rcpt to parameters are
used.
2023-02-22 07:20:14 -07:00
Wez Furlong aa508b012a smtpclient: include command in Response
This will make the logs more useful when we start writing those
2023-02-22 06:59:13 -07:00
Wez Furlong 1cd30161e7 Allow starting as root in order to bind to port 25
We require that `--user username` be passed and specify
the user id that we should assume instead of running as
root.

We do the magic setup needed to preserve the ability
to bind to port 25 while dropping the other privs.
2023-02-21 22:38:51 -07:00
Wez Furlong 5cfb086fed spool: remove sled
It's beta and rocksdb performs better; there's not a compelling
reason to retain it until it stabilizes.
2023-02-21 21:28:36 -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 ed8aa53d55 Add RocksDB as a spool option
Looks pretty good compared to Sled.

|kind         | flush | throughput |
+-------------+-------+------------+
|RocksDB      | false | 102mm/hr   |
|RocksDB      | true  | 96mm/hr    | *
|Sled         | false | 96mm/hr    |
|Sled         | true  | 34mm/hr    |
|LocalDisk    | false | 24mm/hr    |
|LocalDisk    | true  | 1mm/hr     |

These numbers are from a 5950x (32 core) with an nvme drive,
as reported by:

```
cargo run --release -p traffic-gen -- --target 127.0.0.1:2025 --duration 20 --concurrency 16024
```

Note that the flush implementation with rocksdb just adjusts the setting
of use_fsync when opening the database.

There is an explicit db-wide flush that can be called, but it is very
aggressive and thorougly tanks performance down to 0.25mm/hr.

Note as well that rocksdb has a number of configuration options that may
work better as a write-once spool than the currently selected defaults;
more analysis could be done, but at the time of writing this commit
message, the defaults are the best performing storage option and going
further isn't a priority.
2023-02-20 23:04:01 -07:00
Wez Furlong 973a3b6f10 spool: add Sled as an alternative local spool
Add a `kind` and `flush` fields when defining a spool.  Add a new
[sled](https://docs.rs/sled/latest/sled/index.html) based spool
implementation.

Initial benchmarking, especially at high concurrency, shows
promising numbers:

|kind         | flush | throughput |
+-------------+-------+------------+
|Sled         | false | 96mm/hr    |
|Sled         | true  | 34mm/hr    |
|LocalDisk    | false | 24mm/hr    |
|LocalDisk    | true  | 1mm/hr     |

These numbers are from a 5950x (32 core) with an nvme drive,
as reported by:

```
cargo run --release -p traffic-gen -- --target 127.0.0.1:2025 --duration 20 --concurrency 16024
```

What's the catch? sled is considered beta by its authors.
https://github.com/spacejam/sled#known-issues-warnings
2023-02-20 22:08:05 -07:00
Wez Furlong aa70b4ab23 spool: revise how we split uuid into directory components
This should give a better distribution and result in fewer
directories overall
2023-02-20 19:46:28 -07:00
Wez Furlong c049277d61 parallelize writing spool and metadata when saving the message 2023-02-20 18:21:24 -07:00
Wez Furlong d944246595 remove a bottleneck, add deferred spool mode
During DATA, spawn the queue resolve and insertion into a separate
task so that we can respond to the injection with lower latency.
2023-02-20 13:52:04 -07:00
Wez Furlong 002d9f94dd traffic-gen: adjust waiting strategy
At very high concurrency we can get a bit stuck waiting for
the tasks to finish.

Adjust so that we wait for the desired duration and sample the
count at that point, then we'll proceed to report that without
worrying about joining the sender tasks.
2023-02-20 12:07:38 -07:00
Wez Furlong 2399495a60 traffic-gen: improve error reporting 2023-02-20 11:15:04 -07:00
Wez Furlong caf47d4c4e add traffic generator 2023-02-20 10:30:58 -07:00
Wez Furlong ca0456a6f7 fix detecting EOF 2023-02-20 10:27:20 -07:00
Wez Furlong d8021a0ebf add redis build with redis-cell 2023-02-20 06:10:20 +00:00
Wez Furlong bda38adf90 restructure docker build bits
This makes it a bit easier to add other docker images
for other things in the future
2023-02-20 02:47:59 +00:00
Wez Furlong 6ebf6762ce may need to load metadata to resolve the queue 2023-02-19 16:53:42 -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 a8ddc72dee add counters for transient and permanent failures 2023-02-19 12:45:04 -07:00
Wez Furlong 5a8280626b metrics: add connection and msg delivery totals
These counters are monotonic but can be used with eg: prometheus'
rate operator to derive message and connection rates.
2023-02-19 12:25:40 -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