636 Commits

Author SHA1 Message Date
Alberto Bertogli
d78056aff5 test: Skip integration tests if $HOSTALIASES is not functional
Most integration tests depend on the $HOSTALIASES environment variable
being functional. That variable works on most systems, but not all. In
particular, systems with `systemd-resolved` can cause the variable to be
ignored.

This was reported by Alex Ellwein in
https://github.com/albertito/chasquid/issues/20.

This patch makes the affected tests to be skipped if $HOSTALIASES is not
working properly. It also removes unnecessary hosts files from tests
which don't need it, and documents this behaviour.

Thanks to Alex Ellwein and foxcpp@ for reporting and helping investigate
this issue!
2021-07-15 00:20:21 +01:00
Alberto Bertogli
4eaf5b38c8 hooks: Use chasquid-rspamd if available
The chasquid-rspamd utility (https://github.com/Thor77/chasquid-rspamd)
provides a better integration with rspamd, by taking envelope and
connection information from the environment variables, and communicating
with rspamd using its protocol.

So if it is available, use it instead of rspamc in the default hook.
2021-07-08 10:18:56 +01:00
Alberto Bertogli
8f1f943fca mda-lmtp: Add -to_puny, to punycode-encode addresses
Some LMTP servers (like dovecot) can't handle UTF8 addresses in the LMTP
commands. This can be problematic if we want to use them with UTF8
domains or usernames, which are well supported by chasquid.

To help workaround this issue, this patch adds a new -to_puny flag for
mda-lmtp, that makes it encode `from` and `recipient` in punycode.

That way, the server will get punycode-encoded (ASCII) strings in the
LTMP commands.

This can be particularly convenient when the recipients are ASCII
(because they're under the mail server control), but `from` may not be
(because it comes from the network).
2021-06-25 12:15:42 +01:00
Alberto Bertogli
f137702f23 trace: Remove restriction on tracing pages
By default, golang.org/x/net/trace currently only allows the tracing
pages to be seen from localhost.

This restriction can be confusing for people accessing the monitoring
server remotely, and adds no value in our environment.

The monitoring server already exports very sensitive information, and
must be enabled with care, and is not on by default. This is well
documented.

This patch removes the restriction, making all the monitoring pages
equally accessible.
2021-06-11 23:29:52 +01:00
Alberto Bertogli
cfe0e48c0a auth: Allow users without a domain
Some deployments already have users that authenticate without a domain.
Today, we refuse to even consider those, and reject them at parsing time.

However, it is a use-case worth supporting, at least with some
restrictions that make the complexity manageable.

This patch changes the auth package to support authenticating users
without an "@domain" part.

Those requests will always be directly passed on to the fallback
authenticator, if available.

The dovecot fallback authenticator can already handle this case just fine.
2021-06-11 20:09:15 +01:00
Alberto Bertogli
099e2e2269 expvarom: Use application/openmetrics-text as content type
The openmetrics proposed standard says we should use the
`application/openmetrics-text` content type when exporting the metrics.

Currently we use `text/plain` for backwards compatibility with
Prometheus, but the new content type is apparently supported since 2018,
so it should be safe to update to match the current proposed standard.
2021-06-11 12:48:45 +01:00
Alberto Bertogli
8c8e64dc29 smtpsrv: Reject HTTP commands
To help with defense-in-depth on cross-protocol attacks (e.g.
https://alpaca-attack.com/), this patch makes chasquid reject HTTP
commands.
2021-06-11 10:35:51 +01:00
Alberto Bertogli
85305f4bd9 smtpsrv: Close the connection after 3 errors (lowering from 10)
Today, we close the connection after 10 errors. While this is fine for
normal use, it is unnecessarily large.

Lowering it to 3 helps with defense-in-depth for cross-protocol attacks
(e.g. https://alpaca-attack.com/), while still being large enough for
useful troubleshooting and normal operation.

As part of this change, we also remove the AUTH-specific failures limit,
because they're covered by the connection limit.
2021-06-11 10:34:20 +01:00
Alberto Bertogli
44eb0b903a smtpsrv: Quote unknown commands for debugging
When we receive unknown commands, we use the first 6 bytes for
troubleshooting (e.g. put them in traces and exported metrics).

While this is safe, since the different places know how to quote them
properly, it makes things more difficult to analyse, since it's not
uncommon to see be binary blobs.

This patch makes us use the ascii-quoted version instead, to make things
easier to analyze.
2021-06-11 10:34:20 +01:00
Alberto Bertogli
27f4356f67 modules: Add missing golang.org/x/tools sum
This patch adds a missing golang.org/x/tools sum, that is used by the
coverage view generator, so it was missed in the last general update.
2021-06-11 10:34:20 +01:00
Alberto Bertogli
c2f2e4c7bb doc: Expand contact to include GitHub issues, and security reports
This patch extends the README to mention explicitly that reporting bugs
and sending patches on GitHub is welcome, and also adds a private email
where to report security issues.

The changes matches the common practice so far, but it's useful to have
it explicitly documented.
2021-06-06 02:10:01 +01:00
Alberto Bertogli
b9f147fa8b trace: Use request tracing in auth and domaininfo
This patch adds tracing for the auth and domaininfo modules. In the
latter, we replace the long-running event with the short-term request
tracing, which is more practical and useful.

There are no logic changes, it only adds tracing instrumentation to help
troubleshooting.
2021-06-05 18:37:07 +01:00
Alberto Bertogli
a3685439dc docs: v1.7 release notes 2021-05-31 15:03:38 +01:00
Alberto Bertogli
61245eec27 cirrus: Remove Linux tests
The Linux tests under the Cirrus CI are currently brittle due to
environmental issues. They're also redundant, since Linux testing is
much better covered by the GitLab CI tests.

So this patch removes them, which removes the false positives and speeds
up the Cirrus CI runs.
2021-05-31 15:03:38 +01:00
Alberto Bertogli
fb680336f0 modules: Update Go modules and regenerate protobufs
This patch does a general pass updating Go modules to recent versions,
and regenerates the protobufs accordingly.

The main purpose is to make sure people building from source are using
relatively recent versions of our dependencies.

We also regenerate protobufs since the newer versions of the liberaries
have a much cleaner dependency tree, which speeds up fetches.
2021-05-31 11:43:06 +01:00
Alberto Bertogli
d3396ace0b smtpsrv: Return a temporary error when we fail to check if a user exists
When we fail to check if a user exists, we currently return a permanent
error, which can be misleading and also make things more difficult to
troubleshoot.

This patch makes chasquid return a temporary error in that case.

Thanks to Thor77 (thor77@thor77.org) for suggesting this change.
2021-05-30 00:39:24 +01:00
Alberto Bertogli
fa651e74e3 dovecot: Retry auto-detect until we find a usable socket pair
Currently, chasquid attempts to auto-detect dovecot sockets when
starting up (if needed). If autodetection fails, chasquid emits an
error, continues serving, and never tries again.

This can be problematic if chasquid starts up before dovecot, and at the
time the dovecot sockets are not present (e.g. after a reboot). In that
case, chasquid will not use dovecot for authentication even after
dovecot has started.

This patch changes the autodetect logic, by doing autodetection at
startup and on each request, until we find a working pair of sockets.
Once we do, they're used consistently.

That way, if dovecot is not ready when chasquid starts, it's not a
problem and chasquid will start using dovecot once it becomes available.

Thanks to Thor77 (thor77@thor77.org) for reporting and helping
troubleshoot this issue.
2021-05-24 10:21:33 +01:00
Alberto Bertogli
84e6c066fa docs: Add known issue about dkimsign and post-data hook
There's a known issue in versions 0.07 to 1.5 where the post-data hook
invocation can fail if the dkimsign binary exists, due to a bug in the
post-data hook check.

This was fixed by commit b6248f3, but it is found on occasion since the
current Debian stable ships 0.07, and Ubuntu 20.04 LTS ships 1.2.

So this patch adds it to the known issues list.
2021-05-24 01:02:43 +01:00
Alberto Bertogli
b1a4b0ce08 docs: Add a page for known issues
It's common that people running old releases (for example, because of
their Linux distribution version) run into issues that have already been
fixed.

It can be convenient to have a list of the most common known issues and,
when available, their workarounds.

This patch creates the documentation page for them, currently empty. It
will be filled in subsequent patches.
2021-05-24 01:01:16 +01:00
Alberto Bertogli
ec7234c0a9 docs: #chasquid has moved to OFTC
The IRC channel has been moved to OFTC, reflect that in the
documentation.
2021-05-23 10:15:44 +01:00
Alberto Bertogli
5f58b942f4 docs: Update how-to with new links and fix mda-lmtp path
This patch adds a new link to the RBL checking suggestion, since the
existing one doesn't work with IPv6, and it's important to get good
coverage.

While at it, it also fixes the path to mda-lmtp, which was wrong before.
2021-03-15 18:32:22 +00:00
Alberto Bertogli
607ea4400d docker: Set the hostname option unconditionally
In commit 5305d584 we fixed an issue with the way the Docker image
adds the "hostname" option to chasquid.conf.

Currently, the Docker entrypoint sets the "hostname" option in
chasquid.conf if it's missing.

That works fine, except when there is a configuration change and the
domain is removed. In that case, the hostname option will have a stale
value, forcing the user to re-create the container, which can be
cumbersome.

This patch fixes the issue by unconditionally setting the hostname
option to one of the available domains at the time of start up.

Thanks to Jaywann@github for finding and reporting this problem on
https://github.com/albertito/chasquid/issues/16, and suggesting an
alternative fix!
2021-02-23 00:21:55 +00:00
Alberto Bertogli
e7a5a4875c test: Update Dockerfile to the new "go get" restrictions
In Go 1.16, "go get" on non-module paths now require an explicit version
to point to.  Without a specific version, the invocation fails.

See https://golang.org/doc/go1.16#go-command for more details on the
change.

The test Dockerfile uses "go get" to fetch driusan/dkim's binaries, used
for integration testing.

So this patch adjusts the Dockerfile to fetch the latest version.
2021-02-18 02:10:13 +00:00
lordwelch
c6775d2d4d Print auth info from config 2021-02-01 19:53:22 -08:00
lordwelch
660da4a85b Allow multiple authentications for the same relay based on from domain
Allow dovecot auth paths to use tcp
Add any domains of authenticated users to localDomains
2021-01-29 14:19:19 -08:00
Alberto Bertogli
5305d58418 docker: Fix duplicate "hostname" configuration entry
When the chasquid docker container is restarted, entrypoint.sh will add
the hostname again, even if it is present.

This causes chasquid to fail to start due to the duplicated option
(`non-repeated field "hostname" is repeated`).

Thanks to Jaywann@github for finding and reporting this problem, on
https://github.com/albertito/chasquid/issues/16.

This patch fixes the issue by only adding the option if it isn't already
present.
2021-01-28 09:48:48 +00:00
lordwelch
e685366a28 Add support for sending mail to a specific relay
Update go-cmp and protobuf
Add support for dovecot auth over tcp
2021-01-24 13:27:07 -08:00
Alberto Bertogli
5c09138db8 chasquid-util: Remove dependency on docopt-go
The docopt-go library is quite convenient, but it has been abandoned for
a while :(

Since we only use it for chasquid-util, this patch removes it and
replaces it with a custom small parser, that is a reasonable fit for the
required use cases.

The patch also adds a couple of tests to increase coverage.

NOTE: docopt-go accepted some undocumented behaviour, in particular the
use of "-a b" instead of "-a=b". The new parser does not, so some
user scripts may require updating.

I think this should be rare enough not to be worth the complexity of
adjusting the parser to allow it.
2021-01-16 23:21:35 +00:00
Alberto Bertogli
def6e1cee2 dovecot-auth-cli: Test invalid arguments handling
This patch adds a minor test to dovecot-auth-cli to verify that the
check for invalid number of arguments is working as expected.

It's mostly for consistency, as the utility is only used for testing
purposes.
2021-01-16 23:21:35 +00:00
Alberto Bertogli
34b1f6cf21 expvarom: Add EOF marker, and minor documentation updates
This patch adds the EOF marker as required by the new specification, and
also adds some links to it in the comments, as reference.
2021-01-16 13:08:46 +00:00
Alberto Bertogli
887a1cef68 gitlab-ci: Only run the image jobs if we have credentials
The image jobs should only run if there are valid credentials for
pushing the images to the respective registries, to avoid false
negatives in the test pipeline.

This can happen when the gitlab CI is run on projects that aren't set up
to push docker images, either because they're clones of the official
repo, or they are under a different gitlab instance (e.g. Debian's
salsa).

We do it by using a "rules:if" clause on specific variables:
- for Docker, $DOCKER_REGISTRY_USER which is set externally
- for GitLab, $CI_REGISTRY_IMAGE which has the address of the registry
  tied to the project.

Note that for GitLab we can't use the credentials for conditional
execution directly, since they are "persisted variables" which are not
available in this context (see [1] for more details). The
$CI_REGISTRY_IMAGE should be good enough to determine whether image
registry is enabled for the repo.

[1]: https://docs.gitlab.com/ee/ci/variables/where_variables_can_be_used.html#persisted-variables
2020-11-22 12:46:58 +00:00
Alberto Bertogli
aa9455c418 test: Ignore fexp in the regular Go build
fexp is a testing utility, including it in the regular Go build confuses
some automation as it can think it's part of chasquid proper.

All other testing utilities are ignored via the "+build ignore"
annotation for this reason, so this patch adds it to fexp to fix this
issue.
2020-11-22 11:57:14 +00:00
Alberto Bertogli
78df715a02 docs: v1.6 release notes 2020-11-22 09:35:08 +00:00
Alberto Bertogli
8769e01f23 test: Update haproxy test config
The haproxy test config includes an obsolete "debug" entry, and is
missing some timeouts which, while harmless in this context, cause a
warning that can be confusing.

This patch fixes the debug entry by running haproxy -d as recommended,
and adds the essential timeouts to avoid the warning.
2020-11-22 09:35:08 +00:00
Alberto Bertogli
a9d7e36d29 gitlab: Export test directory as an artifact
To debug test failures, it can be convenient to explore the contents of
the test directories after the test runs, as they contain logs and
generated files.

This patch configures the GitLab CI to export the repo tree (which
includes the test directory) as GitLab CI artifacts, so they can be
easily accessed after the tests have completed.
2020-11-13 20:49:42 +00:00
Alberto Bertogli
e79586a014 Implement HAProxy protocol support
This patch implements support for incoming connections wrapped in the
HAProxy protocol v1.

This is useful when running chasquid behind a HAProxy server, as it
needs the original source IP to perform SPF checks.

This patch is a reimplementation of one originally provided by Denys
Vitali in pull request #15, except the logic for the protocol handling
is moved to a new package, and the smtpsrv.Conn handling of the source
IP is simplified.

It is marked as experimental for now, since we want to give it a bit
more exposure just in case the option/api needs adjustment.

Thanks a lot to Denys Vitali (@denysvitali in github) for sending the
original patch for this, and helping test it!
2020-11-13 20:49:42 +00:00
Leandro Lucarella
c9d3ba0ca0 Add @domain to chasquid-util --help where appropriate
This makes it more clear how to specify which domain the user being
operated on is the sub-command targeting when using `--help`.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Update code to match the updated parameter name.
2020-11-12 23:24:21 +00:00
ThinkChaos
bb1b921e3c Add /exit endpoint to monitoring server
Allows terminating chasquid via the network. Useful to trigger a restart
(if there is an init system to relaunch chasquid) and thus reload certificates.

Amended-by: Alberto Bertogli <albertito@blitiri.com.ar>
  Added tests, and adjusted shutdown sequence.
2020-11-12 23:24:21 +00:00
Alberto Bertogli
e9c6775418 test: Remove dependency on wget
This patch removes the dependency on wget for fetching content over
http, which was used in one of the tests to do some checking on debug
and metric pages, as well as loop detection.

Instead of wget, we now use a small built-in utility called fexp.
2020-11-12 23:24:21 +00:00
Alberto Bertogli
025cb2d96a courier: Rename Procmail to MDA
This patch renames courier.Procmail to courier.MDA, to make it more
obvious that the functionality is not tied to that particular MDA.

It's just for readability, there are no functional changes.
2020-09-17 02:47:42 +01:00
Alberto Bertogli
1cc7b9a864 smtpsrv: Pass EHLO/HELO domain to the post-data hook
Some utilities might want to access the EHLO/HELO domain in the
post-data hook (for example, to do additional SPF validations).

This patch implements that support, including sanitizing the EHLO domain
on the environment variable to reduce the risk of problems.
2020-09-17 01:29:49 +01:00
Alberto Bertogli
5bebb00af9 smtpsrv: Rename internal variable ehloAddress -> ehloDomain
The EHLO parameter is generally referred to as "domain", even though it
can take either a domain or an address.

For clarity, rename the variable and comments to match.

This is stylistic only, there are no functional changes.
2020-09-17 01:29:49 +01:00
Alberto Bertogli
4c26713f40 docs: Add details about the hook variables
This patch adds some wording to explain each of the hook variables.
2020-09-17 01:29:49 +01:00
Alberto Bertogli
7914590cfa docs: Update and extend links to distribution packages
This patch updates and extends the links to the distribution packages,
referencing them from the README (it's more likely to be what the reader
wants to see), and also extending the Arch packaging with binary package
information.
2020-09-13 11:31:31 +01:00
Alberto Bertogli
9e3c102f34 docs: v1.5 release notes 2020-09-12 12:03:25 +01:00
Alberto Bertogli
1fcc4ffe0f queue: Remove dependency on external protobuf package
The queue protobuf definition currently uses the well-known timestamp
protobuf package.

This adds a build-time dependency on it, which is fairly harmless when
building from source (since the golang protobuf compiler includes it
already), but adds overhead for packaging on distributions.

Since this is the only external proto dependency we have, and the
protobuf message itself is trivial, this patch removes it an instead
embeds a compatible definition.

That way we remove the dependency and simplify packaging, with almost
negligible code overhead.

The change is fully backwards compatible and has no functional changes.
2020-09-12 10:56:17 +01:00
Alberto Bertogli
48c37b5687 monitoring: Show the go version used to build the binary
This patch makes the monitoring web server index show the go compiler
version used to build the binary, which can be convenient when
troubleshooting.
2020-09-11 12:34:36 +01:00
Alberto Bertogli
a2ce7c7323 docs: Minor style changes to the monitoring documentation
This patch contains minor style and formatting changes to the Monitoring
documentation, to (hopefully) improve readability and consistency.
2020-08-21 12:07:33 +01:00
Alberto Bertogli
7fe42a368a monitoring: Add OpenMetrics exporter
This patch makes chasquid's monitoring server expose an OpenMetrics
metrics endpoint.

It adds a new package "expvarom" which implements an HTTP handler that
exports expvar variables in the OpenMetrics text format.

Then, the handler is registered by the monitoring server at /metrics
(where most things expect it to be).

The existing exported variables are also extended with descriptions,
which is optional, but improves the readability of the metrics.
2020-08-21 12:07:33 +01:00
Alberto Bertogli
7e412db19b test: Check debugging pages are not empty
When testing the debugging pages, do a quick check to verify that the
returned pages are not empty.

This covers the case where a template fails to execute at runtime, and
without this change it wouldn't be caught by tests.
2020-08-20 00:08:36 +01:00