mirror of
https://github.com/docker-mailserver/docker-mailserver
synced 2026-11-27 16:14:45 +01:00
* refactor: move image contents into rootfs/ Put everything that ships in the image into rootfs/, laid out like the container's filesystem, so that the repository path of a file is its image path with a `rootfs/` prefix. Moves (git mv, history is kept) - etc/ -> rootfs/etc/ - scripts/bin/ -> rootfs/usr/local/bin/ - scripts/lib/ -> rootfs/usr/local/lib/dms/ - scripts/build.sh -> build.sh (build time only, next to setup.sh) - scripts/ no longer exists. The paths inside the image are unchanged, as are the file modes tracked by Git, so there is no changelog entry. The Dockerfile copies `rootfs/etc/` to `/etc/` and `rootfs/usr/local/` to `/usr/local/`. The two script COPY instructions became one, it still applies `--chmod=755` to everything below `/usr/local/`. All references are updated: the Dockerfile, .dockerignore, .gitattributes, the CI path filters (`rootfs/**` and `build.sh`), ShellCheck source directives, the tests that source repository files, code comments, links to the repository in the docs, and AGENTS.md. * ci: update linter Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> * breaking: remove SHELL and HEALTHCHECK from the Dockerfile and clean it up Neither `SHELL` nor `HEALTHCHECK` is part of the OCI image specification. Builders like Podman and Buildah warn about them and ignore them unless `--format docker` is used. Without them the image builds without warnings with every OCI compliant builder. Breaking: the image no longer ships a `HEALTHCHECK`. Users that rely on the health status (e.g. `depends_on: condition: service_healthy`) must configure `dms-healthcheck` in their runtime. `compose.yaml` now does so. The image filesystem is unchanged. Without `SHELL`, `RUN` uses `/bin/sh`: - every heredoc starts with `set -e` - `echo -e` became `printf` (the written bytes are identical) - the pipe in `echo | crontab -` cannot fail, DL4006 is ignored for it Cleanup - Describe the three stages in the header and use uniform banners with titles that match their content. - Merge the small `RUN` instructions of stage-main into three: ClamAV, package configuration and logs. - Move the removal of locales, man pages and docs, and `update-locale` into `_post_installation_steps` of build.sh, next to the APT cleanup. - Replace the stale permalink in the comment of the ENV defaults. * chore: simplify .gitattributes Replace the 150 lines of per-extension rules with `* text=auto eol=lf` plus the entries for binaries, `-diff` and `export-ignore`. All tracked text files are already LF in the index and the working tree, `git add --renormalize .` is a no-op, and Git detects the six binaries itself. The change closes a gap: `rootfs/etc/`, `test/config/`, the docs and the workflows had no `eol=lf`, so a checkout on Windows could ship CRLF configs into the image or into the test containers. Also drops stale comments (`target/shared/`, `test/linting/`) and entries that had no effect (e.g. `Makefile`). * tests: move bats libraries into test/helper/, retire the legacy helper - Move the submodules bats-support and bats-assert from test/test_helper/ to test/helper/ and rename them in .gitmodules. test/test_helper/ no longer exists. - Update the load paths in test/helper/common.bash and the lint excludes in the Makefile. - Delete the legacy test/test_helper/common.bash and its test serial/test_helper.bats. The test only covered the legacy functions and used a fixture that does not exist. - Port serial/trusted_networks_subnet.bats, the last user of the legacy helper, to the test/helper/ API: unique `dms-test_` container and network names, `_init_with_defaults` and `_common_container_*`, and the `_`-prefixed helpers. The permanently skipped third test targeted a container that no longer exists and is dropped. - Point the comment in change-detection.sh to the existing test/helper/change-detection.bash. Existing checkouts keep working: `git mv` moved the worktrees, the submodule names and gitdirs follow the new paths. * tests: rename test/files to test/fixtures and group transactions by protocol `test/files/` mixed unrelated things under unclear names. The new layout says what each file is and how a test consumes it: - `emails/` mail bodies for `_send_email --data` - `transactions/{smtp,imap,pop3,policy}/` raw protocol transcripts for `_send_raw_transaction*` (replaces `nc/`, `auth/` and `emails/nc_raw/`) - `tls/` certificates (replaces `ssl/`) The Postgrey transcripts live in `transactions/policy/` because they speak Postfix's policy delegation protocol, not SMTP. `TEST_FILES_*` become `TEST_FIXTURES_*`; the in-container mount point `/tmp/docker-mailserver-test` is unchanged. --------- Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com>
126 lines
5.5 KiB
Caddyfile
126 lines
5.5 KiB
Caddyfile
# Mocked OAuth2 /userinfo endpoint normally provided via an Authorization Server (AS) / Identity Provider (IdP)
|
|
#
|
|
# Dovecot will query the mocked `/userinfo` endpoint with the OAuth2 bearer token it was provided during login.
|
|
# If the session for the token is valid, a response returns an attribute to perform a UserDB lookup on (default: email).
|
|
|
|
# `DMS_YWNjZXNzX3Rva2Vu` is the access token our OAuth2 tests expect for an authorization request to be successful.
|
|
# - The token was created by base64 encoding the string `access_token`, followed by adding `DMS_` as a prefix.
|
|
# - Normally an access token is a short-lived value associated to a login session. The value does not encode any real data.
|
|
# It is an opaque token: https://oauth.net/2/bearer-tokens/
|
|
|
|
# NOTE: The main server config is at the end within the `:80 { ... }` block.
|
|
# This is because the endpoints are extracted out into Caddy snippets, which must be defined before they're referenced.
|
|
|
|
# /userinfo
|
|
(route-userinfo) {
|
|
vars token "DMS_YWNjZXNzX3Rva2Vu"
|
|
|
|
# Expects to match an authorization header with a specific bearer token:
|
|
# https://developer.mozilla.org/en-US/docs/Web/HTTP/Authentication#authentication_schemes
|
|
@auth header Authorization "Bearer {vars.token}"
|
|
|
|
# If the provided authorization header has the expected value (bearer token), respond with this JSON payload:
|
|
handle @auth {
|
|
# JSON inlined via HereDoc string feature:
|
|
# Dovecot OAuth2 defaults to `username_attribute = email`, which must be returned in the response to match
|
|
# with the `user` credentials field that Dovecot received via base64 encoded IMAP `AUTHENTICATE` value.
|
|
respond <<EOF
|
|
{
|
|
"email": "user1@localhost.localdomain",
|
|
"email_verified": true
|
|
}
|
|
EOF
|
|
}
|
|
|
|
# Failed to authorize, close connection and send a 401 status (unauthorized):
|
|
respond 401 {
|
|
close
|
|
}
|
|
}
|
|
|
|
# /introspect
|
|
# Mocked RFC 7662 token introspection endpoint. Unlike `/userinfo`, it requires client credentials.
|
|
# Dovecot is configured with `introspection_mode = post`, and the credentials in the URL (`http://dms-dovecot:hunter2@auth.example.test/introspect`).
|
|
# It then makes a POST request with the token as content, and the credentials as an `Authorization: Basic` header.
|
|
(route-introspect) {
|
|
# Base64 encoded `client_id:client_secret` (`dms-dovecot:hunter2`):
|
|
vars credentials "ZG1zLWRvdmVjb3Q6aHVudGVyMg=="
|
|
|
|
@auth {
|
|
method POST
|
|
header Authorization "Basic {vars.credentials}"
|
|
}
|
|
|
|
# `active` is what Dovecot checks with `active_attribute` + `active_value`, `email` is the default `username_attribute`:
|
|
handle @auth {
|
|
respond <<EOF
|
|
{
|
|
"active": true,
|
|
"email": "user1@localhost.localdomain"
|
|
}
|
|
EOF
|
|
}
|
|
|
|
respond 401 {
|
|
close
|
|
}
|
|
}
|
|
|
|
# NOTE: This portion of config is only relevant for understanding what happens seamlesssly,
|
|
# DMS tests no longer use raw IMAP commands with netcat, thus none of this is relevant beyond reference for troubleshooting.
|
|
#
|
|
# /imap/xoauth2
|
|
# Generate IMAP commands for authentication testing
|
|
# Base64 encoded credentials can alternative be done via CLI with:
|
|
# echo -en 'user=${USERNAME}\001auth=Bearer ${ACCESS_TOKEN}\001\001' | base64 -w0; echo
|
|
#
|
|
# Provide `user` and `access_token` values via query string parameters:
|
|
# curl 'http://auth.example.test/imap/xoauth2?user=user1@localhost.localdomain&access_token=DMS_YWNjZXNzX3Rva2Vu'
|
|
# curl 'http://auth.example.test/imap/oauthbearer?user=user1@localhost.localdomain&access_token=DMS_YWNjZXNzX3Rva2Vu'
|
|
#
|
|
# Example Response:
|
|
# a0 AUTHENTICATE XOAUTH2 dXNlcj11c2VyMUBsb2NhbGhvc3QubG9jYWxkb21haW4BYXV0aD1CZWFyZXIgRE1TX1lXTmpaWE56WDNSdmEyVnUBAQ==
|
|
# a1 EXAMINE INBOX
|
|
# a2 LOGOUT
|
|
#
|
|
# When Dovecot queries /userinfo endpoint, it will be after base64 decoding the IMAP `AUTHENTICATE` value,
|
|
# and sending the `auth` value from the `credentials` variable as an HTTP Authorization header.
|
|
(route-imap) {
|
|
# The login username + OAuth2 access token prior to Base64 encoding, as per the XOAUTH2 spec:
|
|
# https://developers.google.com/gmail/imap/xoauth2-protocol#the_sasl_xoauth2_mechanism
|
|
# For OAUTHBEARER `host` and `port` do not appear to affect authentication with Dovecot
|
|
map {path} {sasl_mechanism} {credentials} {
|
|
/xoauth2 XOAUTH2 "user={query.user}\001auth=Bearer {query.access_token}\001\001"
|
|
/oauthbearer OAUTHBEARER "n,a={query.user},\001host=localhost\001port=143\001auth=Bearer {query.access_token}\001\001"
|
|
}
|
|
|
|
# Responds with the raw IMAP commands for testing XOAUTH2 authentication.
|
|
# Uses the `b64enc` template function to encode credentials as required for `IMAP AUTHENTICATE`:
|
|
templates
|
|
respond <<EOF
|
|
a0 AUTHENTICATE {sasl_mechanism} {{b64enc "{credentials}"}}
|
|
a1 EXAMINE INBOX
|
|
a2 LOGOUT
|
|
EOF
|
|
}
|
|
|
|
# Routes the endpoints to the logical blocks extracted out as snippets above
|
|
:80 {
|
|
# This is the `/userinfo` endpoint that Dovecot connects to with the OAuth2 setting (default: `introspection_mode = auth`).
|
|
# Example: curl http://auth.example.test/userinfo -H 'Authorization: Bearer DMS_YWNjZXNzX3Rva2Vu'
|
|
handle_path /userinfo {
|
|
import route-userinfo
|
|
}
|
|
|
|
# The `/introspect` endpoint that Dovecot connects to with `introspection_mode = post` (see `dovecot.cf` in the OAuth2 docs).
|
|
# Example: curl http://auth.example.test/introspect -u dms-dovecot:hunter2 -d 'token=DMS_YWNjZXNzX3Rva2Vu'
|
|
handle_path /introspect {
|
|
import route-introspect
|
|
}
|
|
|
|
# An additional endpoint for maintainers to generate `test/fixtures/transactions/imap/imap-oauth2-auth.txt`
|
|
handle_path /imap/* {
|
|
import route-imap
|
|
}
|
|
}
|