636 Commits

Author SHA1 Message Date
Alberto Bertogli
6713fb7aef modules: Update Go dependencies 2023-10-27 18:00:23 +01:00
Ernesto Alfonso
359d45a3de docker: Fix using a domain directory path as a domain name
There is a bug causing an invalid config in the generated
/etc/dovecot/auto-ssl.conf, e.g.:

ssl_cert = </etc/letsencrypt/live//etc/letsencrypt/live/mail.grouplok.com/fullchain.pem
ssl_key = </etc/letsencrypt/live//etc/letsencrypt/live/mail.grouplok.com/privkey.pem

This patch fixes it by using the domain name instead of the path, which
matches the original intent.

https://github.com/albertito/chasquid/pull/42

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message.
2023-10-27 10:48:34 +01:00
Alberto Bertogli
27fd7e7220 docs: v1.12 release notes 2023-10-07 16:53:58 +01:00
Alberto Bertogli
8cc42df249 modules: Update Go dependencies (again)
This patch does a general pass updating dependencies to their latest
versions.
2023-10-07 16:53:58 +01:00
Alberto Bertogli
f5d8c68a39 test: Add the embedded aliases file to the fuzz corpus
This patch adds the embedded aliases file to the fuzz corpus, because it
is trivial to do so, and is a reasonable seed which will be naturally
adjusted over time as the package evolves (as it happened in recent
commits).
2023-10-07 16:41:26 +01:00
Alberto Bertogli
5cdbd9ff6e Fix documentation/comment typos
This patch fixes a variety of typos in documentation and comments, found
by running `codespell`.
2023-10-07 12:41:57 +01:00
Alberto Bertogli
43e98e08a8 test: Minor bash style fixes to t-04-aliases
This patch contains minor bash style fixes to test/t-04-aliases, for
readability and consistency.
2023-10-07 12:41:57 +01:00
Alberto Bertogli
669bccc13f modules: Update Go dependencies
This patch does a general pass updating dependencies to their latest
versions.
2023-10-04 15:43:41 +01:00
Alberto Bertogli
a80051657a docs/man: Auto-generate markdown manpages
This patch adds auto-generation of markdown manpages, for ease of
reference in other documents and links.
2023-10-04 00:31:14 +01:00
Alberto Bertogli
8ded1f6f5e Auto-format protobuf files
This patch runs clang-format on the protobuf files, and also adds a
Makefile target for auto-formatting code (Go and protobuf) for
convenience.
2023-10-03 23:34:23 +01:00
Alberto Bertogli
d57037273c localrpc test: Don't call t.Fatal from a goroutine
The testing package does not allow t.Fatal to be called from a different
goroutine; however, we do that if the testing server fails listen or
accept connections.

Since that is unexpected and rare, this patch turns those calls into
panics.
2023-10-03 23:32:30 +01:00
Alberto Bertogli
74e7c96031 aliases: Drop characters when parsing, and support suffix-specific aliases
Today, when a user sets an alias with drop characters and/or suffixes,
those go unused, since we always "clean" addresses before alias
resolution.

This results in unexpected and surprising behaviour, and it's not
properly documented either.

This patch resolves this unexpected behaviour as follows:

- Drop characters are ignored, both at parsing time and at lookup time.
- Lookups are done including the suffixes first, and if that results in
  no matches, they are retried without suffixes.

This results in aliases working more intuitively for the most common use
cases: of users wanting to have different aliases for specific suffixes,
and not having to care for drop characters.

Hooks can be used to get different behaviour if needed, since the first
lookup is done with the address as-is.

Thanks to znerol@ (lo+github@znerol.ch) for reporting this, and the
discussion on how to fix it, in
https://github.com/albertito/chasquid/issues/41.
2023-09-24 09:33:01 +01:00
Alberto Bertogli
d086fbbb97 aliases: Make parsing functions methods of the resolver
Today, the parsing functions are stand-alone since they don't need
anything from the resolver.

But in future patches, that will change.

In anticipation of that, move those functions to be methods of the
resolver.
2023-09-24 09:32:32 +01:00
Alberto Bertogli
8bbb6118e5 aliases: Exists does not need to return the "clean" address
The aliases.Resolver.Exists function currently returns the "clean"
address (with the drop characters and suffixes removed), which is relied
upon in its only caller.

That, however, makes the logic more difficult to follow, hiding some
of the address manipulation behind what should be a read-only check.

So this patch reorganizes that code a little bit, removing the
"cleaning" of the address as part of Exists, and making it explicit when
needed instead.

This patch does not have any user-visible change in behaviour, it is
just internal reorganization.

This is in preparation for further patches which will improve the
handling of some aliases corner cases.
2023-09-24 09:32:32 +01:00
Alberto Bertogli
dc10031e1c docs: Reflect chasquid-util alias-resolve changes
Since commit e6c6df45, `chasquid-util alias-resolve` talks to the server
and returns authoritative answers.

This patch updates docs/aliases.md to reflect that, which was missed in
the original set of changes.
2023-09-24 09:32:32 +01:00
Alberto Bertogli
9d7842878b test: Make t-04-aliases fail on unexpected mail
Today we check the aliases deliver mail to the expected locations, but
we don't fail if there are unexpected deliveries.

Doing so can help catch bugs (including test bugs), so this patch
implements that.

In addition, fix two of the tests that were printing on error, but not
causing the tests to fail (which was the original intention).
2023-09-24 09:08:23 +01:00
Alberto Bertogli
f51b449c69 chasquid: Move the certificate loading logic in a separate function
This patch moves the top-level certificate loading logic out of main and
into a separate function.

This is only for readability and consistency with how we handle domains
(which have a similar structure already). There are no logic changes.
2023-09-17 10:58:25 +01:00
Alberto Bertogli
b9e222f6eb chasquid: Remove unnecessary logging on loading aliases and users on startup
When starting up, for each domain we parse aliases and users files (if
they exist).

Today we print a line for each, which gets quite verbose and doesn't
offer much useful information.

This patch adjusts that logic so that we only print errors (unless a
file does not exist, which is a normal case).

This also improves the scenario where chasquid does not have permissions
to access the users file: before this patch, that would fail silently,
but with this patch we show the correct error.

While at it, make the "Loading" messages consistent with each other, for
readability.
2023-09-17 10:54:49 +01:00
Alberto Bertogli
2c02f0d128 test: Make t-20-bad_configs less flaky due to asynchronous logging
The t-20-bad_configs test can sometimes have false positives because
the last line recorded in the log isn't always the one causing the
failure, due to asynchronous logging and in particular in combination
with coverage tests (which alter the os.Exit behaviour subtly).

This patch fixes that by having the tests look at the last 4 lines of
output instead. This is not super pretty, but it should be good enough
to cover for any timing issues that arise in these particular tests.
2023-09-02 14:12:36 +01:00
Alberto Bertogli
888b2df4c1 Handle symlinks under the certs/ directory
Currently, if the `certs/` directory has a symlink inside, we skip it.
That is not really intended, it's an unfortunate side-effect of skipping
regular files.

To fix this, this patch adjusts the logic to only ignore regular files
instead. It also adds a message when a directory is skipped, to make it
easier to debug permission issues.

Thanks to @erjoalgo for reporting this in
https://github.com/albertito/chasquid/pull/39, and providing an
alternative patch!
2023-09-02 13:58:24 +01:00
Alberto Bertogli
47535651d2 chasquid-util: Remove aliases-add subcommand
The aliases-add subcommand was added before aliases hooks were
implemented and polished, it is undocumented, and the implementation is
nowadays a bit brittle, has some rough edges, and adds significant code
complexity to chasquid-util.

AFAIK nobody is using it either (checked with some specific folks
directly, and it's not very discoverable either).

For all those reasons, this patch removes it.
2023-08-10 00:12:56 +01:00
Alberto Bertogli
57ee3733f4 modules: Update Go modules
This patch does a general pass updating dependencies to their latest
versions.
2023-07-30 13:21:07 +01:00
Alberto Bertogli
e6c6df457d chasquid-util: Use server for aliases-resolve and domaininfo-remove
This patch makes chasquid-util's aliases-resolve and domaininfo-remove
commands talk to the chasquid server (via the new localrpc server).

For aliases-resolve, currently has fairly hacky logic which reimplements
a bunch of the servers', and is also incomplete because it does not
support hooks.

In this patch we fix that by having it talk to the server, where we get
authoritative responses and have no issues with aliases hooks. This
resolves https://github.com/albertito/chasquid/issues/18.

For domaininfo-remove, currently its implementation is also very hacky
since it manipulates files behind the servers' back and without even
using the internal library.

In this patch we fix that by doing the operation through the server,
avoiding the need for those hacks, and also remove the need to manually
reload the server afterwards.
2023-07-30 13:21:07 +01:00
Alberto Bertogli
ddd1b6d96e chasquid: Run a localrpc server
This patch makes chasquid run a localrpc server, exporting two methods:
alias resolve, and domaininfo clear.

They will be used by chasquid-util in later patches.
2023-07-30 13:21:07 +01:00
Alberto Bertogli
360ac13a73 localrpc: Add a package for local RPC over UNIX sockets
This patch adds a new package for doing local lightweight RPC calls over UNIX
sockets. This will be used in later patches for communication between chasquid
and chasquid-util.
2023-07-30 13:21:07 +01:00
Alberto Bertogli
764c09e94d domaininfo: Add a Clear method to clear information for a given domain
This patch adds a Clear method to the domaininfo database, which removes
information for the given domain.

This can be used to manually make the server forget about a domain, in
case there are operational reasons to do so.

Today, this is done via chasquid-util (which removes the backing file),
but that is hacky, and this is part of replacing it with a cleaner
implementation.
2023-07-30 11:34:27 +01:00
Alberto Bertogli
ac1c849a27 docs: Document how to report a security issue
Some systems, like GitHub, can use `docs/SECURITY.md` to inform users on
how to report security issues.

This patch adds one to the tree. It is not linked explicitly in mkdocs
because the same information is already covered in the doc index and
README already.
2023-07-28 10:05:15 +01:00
Alberto Bertogli
2e279de304 github: Run coverage tests
This patch adds a job to the docker workflow to run coverage tests, and
upload the results to coveralls.
2023-07-28 10:05:15 +01:00
Alberto Bertogli
a3f7914e29 sts: Remove unused struct member
There is no synchronization needed in the sts cache, because changes are
handled atomically on-disk and there is no in-memory persistence.
2023-07-28 10:05:15 +01:00
Alberto Bertogli
2b7e33a615 domaininfo: Do not reload the database periodically
It is not expected that the user modifies the domaininfo database behind
chasquid's back, and reloading it can be somewhat expensive.

So this patch removes the periodic reload, and instead makes it triggered
by SIGHUP so the user can trigger a reload manually if needed.
2023-07-28 10:05:15 +01:00
znerol
ad0dbb9cda smtp-check: Add flag to specify local name
Some MTAs reject client connections unless the local name (used in the
HELO/EHLO command) looks like an FQDN. Currently, smtp-check always uses
`localhost`, which does not look like an FQDN.

This patch adds a command line flag to smtp-check to specify the
local name to be used.

Fixes https://github.com/albertito/chasquid/issues/37.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Minor edits to the commit message, adjust flag name, go fmt.
2023-07-16 10:03:50 +01:00
Alberto Bertogli
9e8452520a docs: Update badge/link to the CI status
The current badge, which covers all the branch checks doesn't work, it
always says "pending".

This patch replaces it with the gotest workflow status. It is much more
narrow, but at least it works and gives a decent indication of the
testing status.
2023-05-24 22:18:12 +01:00
Alberto Bertogli
01a6d088e2 test: Add a set of tests for handling bad/invalid configs
This patch adds a set of tests to validate chasquid's handling of bad
and invalid configurations, to make sure we fail as expected.
2023-05-17 00:44:54 +01:00
Alberto Bertogli
0c9d1536db docs: Update tests.md to reflect coverage changes, and add links
This patch updates tests.md to reflect the recent changes around
coverage testing, specifically we no longer have coverage issues with
fatal/non-zero exits, so remove that section from the docs.

Also while at it, add links to the software we reference, for
convenience.
2023-05-16 10:50:26 +01:00
Alberto Bertogli
e85ad54a73 Regenerate auto-generated files
This patch regenerates the auto-generated files.

There are no significant changes, the protobuf just get an updated
comment due to protoc version change, but it is just informational.

Two new TLS ciphers are added, matching the new IANA assignments.
2023-03-03 11:24:40 +00:00
Alberto Bertogli
fd9c6a748b courier/smtp: Retry over plaintext on STARTTLS errors
When the SMTP courier gets an error on STARTTLS (either because the
command itself failed, or because there was a low-level TLS negotiation
error), today we just fail that attempt.

This can cause messages to never be delivered if the underlying reason
is a server misconfiguration (e.g. a server certificate that Go cannot
parse). This is quite rare in practice, but it can happen.

To prevent this situation, this patch adds logic so that the SMTP
courier retries over plaintext when STARTTLS fails.

This is still subject to security level checks, so this type of failures
cannot be used to downgrade connections to domains we successfully
established a TLS connection previously.

Note that certificate validation issues are NOT included in this
type of failure, so they will not trigger a retry. The certificate
validation handling is unchanged by this patch.
2023-03-03 09:51:48 +00:00
Alberto Bertogli
1927e15ea2 docs: v1.11 release notes 2023-02-19 16:20:50 +00:00
Alberto Bertogli
34977fe834 modules: Update Go modules
This patch does a general pass updating Go modules to recent versions.

This should fix a minor security advisories around http/2 handling. Even
though chasquid doesn't directly expose http/2, the monitoring server
could be affected.
Reference: https://pkg.go.dev/vuln/GO-2023-1495.
2023-02-19 08:54:44 +00:00
Alberto Bertogli
efefee9fbb test: Update fuzz tests to use the built-in infrastructure
Go 1.18 supports fuzzing natively, so this patch migrates our fuzzing
tests to make use of it.
2023-02-05 12:30:25 +00:00
Alberto Bertogli
a54d81f406 monitoring: Get build information from Go's runtime
Currently, chasquid gets version information from build-time flags that
have to be passed by the user.

This patch extends this logic so, if no flags are given, Go's build
information will be used to construct a synthetic version string.
2023-02-05 11:01:36 +00:00
Alberto Bertogli
ab63834cba Update minimum supported Go version 1.17 -> 1.18, and modules
This patch updates the minimum supported Go version from 1.17 to 1.18,
and also the versions of our dependencies.

Go 1.18 is now 2 releases old, and easily available in most Linux
distributions, including Debian stable (via backports).
2023-02-05 10:42:37 +00:00
Alberto Bertogli
77328b88ed test: Remove unnecessary "exit" calls 2023-02-01 23:45:51 +00:00
Alberto Bertogli
7d6a59ba77 test: Update coverage tests to Go 1.20
Go 1.20 finally includes proper support for instrumenting binaries for
coverage. This allows us to drop quite a few hacks and workarounds that
we used for it, and we can now also test exiting cases.

The downside is that coverage tests now require Go 1.20, but it is an
acceptable price to pay for the more accurate results.

Normal integration tests are unchanged.

This patch updates the coverage testing infrastructure to make use of
the new Go 1.20 features.
2023-02-01 23:43:12 +00:00
Alberto Bertogli
795f2a7ceb ci: Use Github Actions to run integration tests and push Docker images
We're running against the usage limits in Gitlab CI (500), and Github
Actions should have more (2000).

So this patch replaces Gitlab CI with Github actions for running
integration tests, and build and push Docker images (to Dockerhub and
Gitlab registry).

We'll see how the usage levels are in a few months.
2022-11-13 19:16:10 +00:00
Alberto Bertogli
948cee1ce1 Improve bash quoting, and other similar best practices
This patch updates the shell scripts with some of the common best
practices, which should make them more resilient to unusual failures and
unexpected environments (in particular, directories with spaces).

Most of these were identified by shellcheck.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
e2481b07a9 cirrus: Remove the golangci-lint test
Cirrus CI runs golangci-lint, which is often way too noisy with false
positives and irrelevant checks. Last one was errcheck on
http.ResponseWriter.Write, but there have been others before.

Disable it for now, since it doesn't add enough value to justify the
introduced friction.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
4d1526e0c8 test: Reduce main sources of overhead in integration tests
The integration tests spend a lot of time on some ancilliary actions,
which slows them down: generating certificates, adding users, and
waiting for things to happen.

To improve the performance of those actions, this patch:

- Makes (most) tests use plain passwords (-20%)
- Adds a certificate cache to reuse certs (-10%)
- Tightens the sleep loops (-5%)

In aggregate, this patch results in a speedup of the integration tests
of ~30-40%.

Note that some of the tests required adjusting the username, because
`chasquid-util user-add` would convert them to lowercase as per PRECIS
mapping.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
4a00a83c23 Add tracing annotations
This patch changes several internal packages to receive and pass tracing
annotations, making use of the new tracing library, so we can have
better debugging information.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
9c6661eca2 nettrace: Add a new tracing library
This commit introduces a new tracing library, that replaces
golang.org/x/net/trace, and supports (amongts other thing) nested
traces.

This is a minimal change, future patches will make use of the new
functionality.
2022-11-13 11:09:19 +00:00
Alberto Bertogli
3ebe5c5173 Replace uses of ioutil
ioutil package was deprecated in Go 1.16, replace all uses with their
respective replacements.

This patch was generated with a combination of `gofmt -r`, `eg`, and
manually (for `ioutil.ReadDir`).
2022-11-12 20:06:35 +00:00