Commit Graph
235 Commits
Author SHA1 Message Date
Wez Furlong ef2abc7031 allow comments in json parsed by kumo.json_load, kumo.json_parse 2023-04-26 15:08:29 -07:00
Wez Furlong 278bc81aa0 move shaping -> policy-extras/shaping, and deploy with package
The assets/policy-extras dir is now deployed to
`/opt/kumomta/share/policy-extras` and added to the require path,
so you can do:

```lua
local shaping = require 'policy-extras.shaping'
```

to pull it into your policy.
2023-04-26 14:51:52 -07:00
Wez Furlong cb8e75c37e queue: fix missing async dispatch of get_queue_config event 2023-04-26 06:38:04 -07:00
Wez Furlong 183621c396 fix get_egress_path_config site-name param, fix async call
Ensure that we trigger an async compatible callback so that
we can use eg: DNS resolution and memoization when processing it.

Fix the site name so that it doesn't include "source->site" and is
just the pure site name.
2023-04-25 15:58:17 -07:00
Wez Furlong ea8a8f7bb2 load meta/payload if needed during logging
In some cases (eg: initial spool -> expiration) we don't have
any metadata loaded, causing the logs to say that the metadata
wasn't loaded.

This commit loads it as needed.
2023-04-21 12:51:16 -07:00
Wez Furlong 217a9ba09f log transient failure when all connection attempts fail
We log all of the connection failure results in the log message
to aid in diagnostics.
2023-04-21 12:33:53 -07:00
Wez Furlong bb64d6d2a8 dns: fix IPv4 and IPv6 literal domain resolving
Bypass the actual DNS resolver when handling literal
domains.
2023-04-21 12:17:09 -07:00
Wez Furlong cb362592e7 Fix Domain::Tagged to_string issue
When given an extension/tagged domain, we didn't include the closing
square bracket when rendering it as text.

Note that this looks like an IPv6 address, but it is not a conforming
IPv6 address which looks like `[IPv6:aaaa::bbbb]` rather than
`[aaaa:bbbb]`. The latter uses tag "aaaa" to define a different
addressing namespace that has no known implementation.

<https://datatracker.ietf.org/doc/html/rfc5321#section-4.1.3>
2023-04-21 11:41:14 -07:00
Wez Furlong 15e886646c fix compilation of individual crates 2023-04-18 16:31:52 -07:00
Wez Furlong b8694d00d8 remove problematic time 0.1 dependency 2023-04-18 15:02:59 -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 385788765e rename delayed_count -> scheduled_count in metrics 2023-04-12 12:07:58 -07:00
Wez Furlong 7f0fd509f1 dns: fix ipv6 lookups
A couple of issues in here:

1. a copypasta incident meant that the v6 lookup was really just a v4
   lookup. doh!
2. We would lookup v4 addresses and just be satisfied with those,
   ignoring any v6 addresses

We now run the v4 and v6 lookups concurrently and merge the results
together.

We do still list the v4 addresses first in the list of addresses.
We don't try to be smart about using the "right" addresses when
work through the list; we try them all until one works out.

Correctly guessing at which one will work means replicating logic
in the kernel, and would potentially be screwed up when we add in
HAProxy support later.
2023-04-04 13:04:16 -07:00
Wez Furlong 95a3c37104 tailer: implement checkpointing
It doesn't do much more than act as a glorified persistent
cursor at the moment, but the plumbing will enable calling
out to eg: lua or an arbitrary subprocess to process batches
in the future.
2023-04-04 12:36:43 -07:00
Wez Furlong 9225644ce7 export ready queue size
```
  "ready_count": {
    "help": "number of messages in the ready queue",
    "type": "gauge",
    "value": {
      "service": {
        "smtp_client:source1->loopback.dummy-mx.example.com": 46.0,
        "smtp_client:source2->loopback.dummy-mx.example.com": 152.0,
      }
    }
  },
```

closes: #30
2023-04-03 10:14:16 -07:00
Wez Furlong d3a5626180 Add log tailer utility
This commit adjusts the logger:

* When a log segment is finised, the `w` permission bits are removed.
  This is used to signal to the tailer that there will be no additional
  data written to that file.

* On startup, kumod will remove the `w` bits from all files in the
  configured log directories so that any that were left on by a prior
  incarnation will be considered closed when the new generation is
  started up.

* Add a `tailer` utility that will essentially `cat` all of the log
  files in a given directory in the appropriate order, then go into
  log tailing mode, where it will wait for new data to show up.

* When reading data, if it hits EOF, the tailer will wait around until
  more data shows up, or until the `w` bit is removed from the file
  that it is reading.

The idea is that, in a later commit, the tailer will be able to persist
a checkpoint file to record where it got to, and be able to dispatch
chunks of data to eg: a webhook push utility, advancing the checkpoint
only when the utility indicates success.

For now, running `cargo run -p tailer -- --tail /var/tmp/kumo-logs` is
a convenient way to tail the logs as they are written.
2023-03-30 14:01:46 -07:00
Wez Furlong 4b9c2f5238 fix default policy and include path to match docs 2023-03-27 09:41:42 -07:00
Wez Furlong e87a5b18bb Improve performance of finding CRLF.CRLF for large messages by 20x
Using a better tuned algorithm for finding a substring match removes
a CPU bottleneck and improves message throughput by 20x at 100Kb
message sizes.
2023-03-27 09:39:51 -07:00
Wez Furlong ece1b89b00 add admin HTTP API for changing the log level 2023-03-24 10:04:00 -07:00
Wez Furlong 6740a68fad add kumo.set_diagnostic_log_filter for adjusting log levels via config 2023-03-24 09:02:10 -07:00
Wez Furlong fbf50bc28f adjust debug log levels for the logging thread 2023-03-24 08:00:57 -07:00
Wez Furlong a81d9d19f9 adjust default logging to include INFO logs 2023-03-24 07:59:46 -07:00
Wez Furlong b57126f724 allow STARTTLS to fail without wiping out the connection
This should improve diagnostics around handshake errors
2023-03-23 16:01:47 -07:00
Wez Furlong 80c6f21b22 marginally improve logging of failed TLS handshake from server side 2023-03-23 15:16:44 -07:00
Wez Furlong 3a26c60438 also export counters as json
expand the docs to show what the data looks like
2023-03-23 10:47:17 -07:00
Wez Furlong cf1ba5f0b2 add key_data source for key data, refactor docs
Break out the KeySource object into its own reference page to
avoid manually duplicating the same information into multiple pages.

Explain how to use data fetched from eg: sqlite.
2023-03-23 08:27:14 -07:00
Wez Furlong 0167041ed0 add kumo.memoize as a way to add caching to any lua function 2023-03-22 17:01:07 -07:00
Wez Furlong b6633b95dc sqlite: bind params as strings, fixup empty rows case
We were binding as blobs which we could read back as strings,
but which didn't match string inputs! Very confusing!
Always bind as strings.

For the empty rows case: don't return the affected row count
unless the query has 0 columns, as we otherwise cannot distinguish
between no matching results and a single column with 0.
2023-03-22 17:01:07 -07:00
Wez Furlong ab18aea416 revert last whitespace change 2023-03-22 17:01:07 -07:00
Wez Furlong 48f55d574d whitespace only commit to force new debs and rpms to build 2023-03-22 12:33:27 -07:00
Wez Furlong 97e52636ed log receptions for messages assigned to the null queue 2023-03-21 11:42:01 -07:00
Wez Furlong 66454f8efc fix weird permission denied issue when dropping privs
Need to set real and effective gid in order for the kernel
to allow us to access the spool directories fully.
2023-03-20 15:03:30 -07:00
Wez Furlong a6f1b450ca fix shutdown deadlock if multiple things call request_shutdown
The issue in my case was:

```
2023-03-20T21:38:56.945962Z ERROR localset-0 kumod::mod_kumo: Error in spool: Opening spool data: Corruption: While creating a new Db, wal_dir contains existing log file: : 000004.log
Shutdown requested, please wait while work is saved
Shutdown completed OK!
2023-03-20T21:38:56.966846Z ERROR localset-0 kumod::mod_kumo: Error in spool: Opening spool meta: Corruption: While creating a new Db, wal_dir contains existing log file: : 000004.log
2023-03-20T21:38:57.025241Z ERROR localset-0 kumod: problem initializing: No spools have been defined
smtp listener on 0.0.0.0:25 -> stopping
Error: Initialization raised an error
smtp listener on [::]:25 -> stopping
```
2023-03-20 14:38:29 -07:00
Wez Furlong f9c6eb8ce3 add ed25519 dkim signer 2023-03-16 10:23:54 -07:00
Wez Furlong f0fc5c37f3 handle malformed names better
There are MX records in the wild that return invalid hostnames.
Skip those when considering the set of MX records.
2023-03-15 15:14:58 -07:00
Wez Furlong b43e88985c add kumo.dns.lookup_mx
This function returns MX information, including the computed site_name.
Update the queue example to show how to use it to populate the SITE_OF
map used in that example.

This commit switches to using the `Name` type under the covers to ensure
that we use canonical names for our cache keys.
2023-03-15 09:34:23 -07:00
Wez Furlong be0fd76d0b add ehlo_domain config option 2023-03-14 22:26:07 -07:00
Wez Furlong e1f0939d81 add json functions 2023-03-14 20:07:40 -07:00
Wez Furlong d978d259c9 set the default policy path 2023-03-14 19:43:12 -07:00
Wez Furlong a0015424e4 add /opt/kumomta/policy to the default require path 2023-03-14 18:59:43 -07:00
Wez Furlong b3f3f877df add functions for working with address headers 2023-03-14 18:53:47 -07:00
Wez Furlong c2cb5b798b fix centos7 build, adjust docker to use /opt/kumomta
Revert building static/bundled sqlite, as the logic deep in sqlite3-src
makes no attempt to deal with this mess on centos7:

  = note: /opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/ld: /__w/kumomta/kumomta/target/release/deps/libsqlite3_src-b3c44e6f34aac065.rlib(sqlite3.o):(.data.rel.aSyscall+0xb0): undefined reference to `fcntl64'
          collect2: error: ld returned 1 exit status

(I don't blame it!)

Deal with that in the docker image by simply installing sqlite
in the docker image.

And since I'm touching the docker stuff, adjust its install
path and layout to match that of the rpm and deb packages.
2023-03-14 14:14:37 -07:00
Wez Furlong b287db1944 ensure that we statically link sqlite
This avoids picking up a dynamic dep on libsqlite3.so
when we build the docker image.
2023-03-13 19:41:33 -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 e0df3362ca dns-resolver: unit test for A-then-B vs B-then-A ordering 2023-03-12 19:53:23 -07:00
Wez Furlong 31f072978d refactor: move mx resolver into separate crate 2023-03-12 15:00:02 -07:00
Wez Furlong 98091b688d cidr-map: add CidrMap type
Unfortunately, the upstream bitstring-trees crate didn't expose
a way to query the tree (only iterate it), so I pulled in a copy
of the implementation and adjusted it for that purpose, removing
some unsafe code that replaced values during insertion (for performance)
with a simpler implementation that clones values instead.

With the map implementation in the crate, I adjusted the set
implementation to be a `CidrMap<()>` and dropped the bitstring-trees
dependency.
2023-03-12 10:59:57 -07:00
Wez Furlong 6304ee18c3 improve cidrset data structure
Improve the big-O cost of finding an entry by storing
the ranges in a compressed radix tree under the covers.

Make it a bit easier to work with the type in code while
we're in here.

"any" is now a possible value for cidrsets, representing
any value.
2023-03-12 09:21:56 -07:00
Wez Furlong 6477fc8a25 refactor: move CidrSet to its own crate 2023-03-12 06:46:54 -07:00
Wez Furlong 269e0702b4 add SMTP AUTH PLAIN support
Verified via:

```
swaks ... --auth plain --tls --auth-user scott --auth-password tiger
```
2023-03-11 16:23:49 -07:00