Commit Graph

24 Commits

Author SHA1 Message Date
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 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 bcd4a6fc6d take a crack at logging receptions and deliveries 2023-02-22 11:57:26 -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 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 caf47d4c4e add traffic generator 2023-02-20 10:30:58 -07:00
Wez Furlong e1e96b3931 tidy up some debug logging 2023-02-19 08:31:21 -07:00
Wez Furlong 9812eef7ac add prometheus metrics export
This commit adds in an http listener that provides a `/metrics`
endpoint that can be configured as a target by prometheus to
scrape and record metrics.

You may also curl it for yourself.

While playing around with this, I found and fixed a deadlock
in the case that the initial spool in logic found and expired
a message; it would reuse a helper function that wanted to acquire
a lock, but it already held the lock.
2023-02-19 00:17:58 -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 086d9008a1 allow configuring the smtp listener banner text 2023-02-18 07:40:01 -07:00
Wez Furlong acf36fe010 slightly expand readme and comments 2023-02-17 14:06:56 -07:00
Wez Furlong 054501e535 some basic plumbing for configuring outbound settings
A callback is used to resolve the config at the time that
we set up the destination site structure (eg: when we get the first
ready-to-send message for it, and again after it has idled out).

This is used in the example configs to enable "OpportunisticInsecure"
TLS mode so that we can successfully delivery over TLS to the
default self-signed TLS certs on the sink.
2023-02-17 13:52:34 -07:00
Wez Furlong 36a84b15bb add relay_hosts config, default to loopback 2023-02-16 19:42:36 -07:00
Wez Furlong ab8fea32e9 allow rejecting incoming messages 2023-02-15 14:03:46 -07:00
Wez Furlong 79afc79794 add lua code formatting 2023-02-15 06:51:59 -07:00
Wez Furlong 52044f578c reject connections until spool is ready. smtp hostname configurable 2023-02-15 06:45:33 -07:00
Wez Furlong 82f9ace9d1 connect spool 2023-02-14 18:33:32 -07:00
Wez Furlong 25bde5ee18 allow configuring listeners from lua 2023-02-12 23:14:31 -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 ce502e8e35 add basic lua policy hooks 2023-02-11 18:59:55 -07:00