From dd3e49e0a0843e4e380c68f7e3b720bfd3e33e5a Mon Sep 17 00:00:00 2001 From: Luke Cyca Date: Sun, 30 Aug 2026 08:55:34 -0700 Subject: [PATCH] chore: update Rspamd DKIM default config to improve multi-domain setups (#4653) Signed-off-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> Co-authored-by: Georg Lauterbach <44545919+georglauterbach@users.noreply.github.com> --- CHANGELOG.md | 10 ++ .../config/best-practices/dkim_dmarc_spf.md | 105 ++++----------- docs/content/config/security/rspamd.md | 2 +- target/bin/rspamd-dkim | 71 ++++++++-- .../parallel/set1/spam_virus/rspamd_dkim.bats | 121 ++++++++++++------ 5 files changed, 178 insertions(+), 131 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d36c62d..bbf28c8e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,16 @@ All notable changes to this project will be documented in this file. The format > **Note**: Changes and additions listed here are contained in the `:edge` image tag. These changes may not be as stable as released changes. +### Breaking + +- **Rspamd:** + - `setup config dkim` now writes keys as `-.private` (previously `---.private.txt`). The default `dkim_signing.conf` uses a `$domain-$selector` path template with `try_fallback = true`, so multiple domains share one config. Existing `dkim_signing.conf` files are not overwritten. Rename keys to the new layout if you regenerate them (OpenDKIM: `opendkim/keys//.private` → `rspamd/dkim/-.private`). ([#4653](https://github.com/docker-mailserver/docker-mailserver/pull/4653)) + +### Updated + +- **Rspamd** + - `setup config dkim` writes a persisted `dkim_selectors.map` for custom selectors. Documentation covers multi-domain setup, OpenDKIM migration, and Ed25519 + RSA fallback (distinct selectors plus a `selectors` array). ([#4653](https://github.com/docker-mailserver/docker-mailserver/pull/4653)) + ## [v16.0.0](https://github.com/docker-mailserver/docker-mailserver/releases/tag/v16.0.0) > [!note] diff --git a/docs/content/config/best-practices/dkim_dmarc_spf.md b/docs/content/config/best-practices/dkim_dmarc_spf.md index 86c72db9..b606de53 100644 --- a/docs/content/config/best-practices/dkim_dmarc_spf.md +++ b/docs/content/config/best-practices/dkim_dmarc_spf.md @@ -133,96 +133,39 @@ DKIM is currently supported by either OpenDKIM or Rspamd: 1. [Verifying DKIM signatures from inbound mail][rspamd-docs-dkim-checks] is enabled by default. 2. [Signing outbound mail with your DKIM key][rspamd-docs-dkim-signing] needs additional setup (key + dns + config). - ??? warning "Using Multiple Domains" + After running `setup config dkim`, the key files for your primary domain will be located in `/tmp/docker-mailserver/rspamd/dkim/` using the `-.private` naming convention (default: `example.com-mail.private`). A basic signing configuration is created in `/tmp/docker-mailserver/rspamd/override.d/dkim_signing.conf`. You can modify this configuration manually if you have advanced needs. - If you have multiple domains, you need to: + If you have multiple domains, run `setup config dkim domain ` for each one to create additional keys. The default config uses a `$domain-$selector` path template, so one `dkim_signing.conf` covers every domain that has a matching key file. Custom selectors are recorded in `/tmp/docker-mailserver/rspamd/dkim_selectors.map`. - - Create a key with `docker exec -it setup config dkim domain ` for each domain DMS should sign outgoing mail for. - - Provide a custom `dkim_signing.conf` (for which an example is shown below), as the default config only supports one domain. - - !!! info "About the Helper Script" - - The script will persist the keys in `/tmp/docker-mailserver/rspamd/dkim/`. Hence, if you are already using the default volume mounts, the keys are persisted in a volume. The script also restarts Rspamd directly, so changes take effect without restarting DMS. - - The script provides you with log messages along the way of creating keys. In case you want to read the complete log, use `-v` (verbose) or `-vv` (very verbose). - - --- - - In case you have not already provided a default DKIM signing configuration, the script will create one and write it to `/tmp/docker-mailserver/rspamd/override.d/dkim_signing.conf`. If this file already exists, it will not be overwritten. - - An example of what a default configuration file for DKIM signing looks like can be found by expanding the example below. - - ??? example "DKIM Signing Module Configuration Examples" - - A simple configuration could look like this: - - ```cf - # documentation: https://rspamd.com/doc/modules/dkim_signing.html - - enabled = true; - - sign_authenticated = true; - sign_local = true; - - use_domain = "header"; - use_redis = false; # don't change unless Redis also provides the DKIM keys - use_esld = true; - check_pubkey = true; # you want to use this in the beginning - - selector = "mail"; - # The path location is searched for a DKIM key with these variables: - # - `$domain` is sourced from the MIME mail message `From` header - # - `$selector` is configured for `mail` (as a default fallback) - path = "/tmp/docker-mailserver/dkim/keys/$domain/$selector.private"; - - # domain specific configurations can be provided below: - domain { - example.com { - path = "/tmp/docker-mailserver/rspamd/dkim/mail.private"; - selector = "mail"; - } - } - ``` - - As shown next: - - - You can add more domains into the `domain { ... }` section (in the following example: `example.com` and `example.org`). - - A domain can also be configured with multiple selectors and keys within a `selectors [ ... ]` array (in the following example, this is done for `example.org`). - - ```cf - # ... - - domain { - example.com { - path = /tmp/docker-mailserver/rspamd/example.com/ed25519.private"; - selector = "dkim-ed25519"; - } - example.org { - selectors [ - { - path = "/tmp/docker-mailserver/rspamd/dkim/example.org/rsa.private"; - selector = "dkim-rsa"; - }, - { - path = "/tmp/docker-mailserver/rspamd/dkim/example.org/ed25519.private"; - selector = "dkim-ed25519"; - } - ] - } - } - ``` + To migrate keys from OpenDKIM, copy `/tmp/docker-mailserver/opendkim/keys//.private` to `/tmp/docker-mailserver/rspamd/dkim/-.private`. Keys generated by earlier DMS Rspamd releases were named `---.private.txt` (for example `rsa-2048-mail-example.com.private.txt`) and must be renamed to the new layout. ??? warning "Support for DKIM Keys using ED25519" This modern elliptic curve is supported by Rspamd, but support by third-parties for [verifying Ed25519 DKIM signatures is unreliable][dkim-ed25519-support]. - If you sign your mail with this key type, you should include RSA as a fallback, like shown in the above example. + Ed25519 and RSA cannot share a selector (each selector has one DNS TXT record). Generate the RSA fallback with a different selector, then add both keys to a domain-specific `selectors` array in `dkim_signing.conf`: - ??? tip "Let Rspamd Check Your Keys" + ```sh + setup config dkim + setup config dkim keytype ed25519 selector mail-ed25519 + ``` - When `check_pubkey = true;` is set, Rspamd will query the DNS record for each DKIM selector, verifying each public key matches the private key configured. - - If there is a mismatch, a warning will be emitted to the Rspamd log `/var/log/mail/rspamd.log`. + ```conf + domain { + example.com { + selectors [ + { + path = "/tmp/docker-mailserver/rspamd/dkim/example.com-mail.private"; + selector = "mail"; + }, + { + path = "/tmp/docker-mailserver/rspamd/dkim/example.com-mail-ed25519.private"; + selector = "mail-ed25519"; + } + ] + } + } + ``` ### DNS Record { #dkim-dns } diff --git a/docs/content/config/security/rspamd.md b/docs/content/config/security/rspamd.md index 6964bf34..33ef5a15 100644 --- a/docs/content/config/security/rspamd.md +++ b/docs/content/config/security/rspamd.md @@ -366,7 +366,7 @@ There is a dedicated [section for setting up DKIM with Rspamd in our documentati domain { example.com { - path = "/tmp/docker-mailserver/rspamd/dkim/rsa-2048-mail-example.com.private.txt"; + path = "/tmp/docker-mailserver/rspamd/dkim/example.com-mail.private"; selector = "mail"; } } diff --git a/target/bin/rspamd-dkim b/target/bin/rspamd-dkim index 802fb663..30b5c1b8 100755 --- a/target/bin/rspamd-dkim +++ b/target/bin/rspamd-dkim @@ -57,7 +57,9 @@ ${ORANGE}EXAMPLES${RESET} ${LWHITE}setup config dkim keytype ed25519 domain edward.com selector elliptic-test${RESET} Generate the DKIM key using the ED25519 elliptic curve for the domain - edward.com and the selector elliptic-test. + edward.com and the selector elliptic-test. Ed25519 and RSA cannot share + a selector (one DNS TXT record per selector). Dual signing needs a + distinct selector per key and a 'selectors' array in dkim_signing.conf. ${ORANGE}EXIT STATUS${RESET} Exit status is 0 if command was successful. If wrong arguments are provided or arguments contain @@ -158,22 +160,24 @@ function _preflight_checks() { mkdir -p "${RSPAMD_DMS_DKIM_D}" "${RSPAMD_DMS_OVERRIDE_D}" chown _rspamd:_rspamd "${RSPAMD_DMS_DKIM_D}" + + SELECTOR_MAP_FILE="${RSPAMD_DMS_D}/dkim_selectors.map" } function _create_keys() { + local BASE_FILE_NAME="${RSPAMD_DMS_DKIM_D}/${DOMAIN}-${SELECTOR}" if [[ ${KEYTYPE} == 'rsa' ]]; then - local BASE_FILE_NAME="${RSPAMD_DMS_DKIM_D}/${KEYTYPE}-${KEYSIZE}-${SELECTOR}-${DOMAIN}" KEYTYPE_OPTIONS=('-b' "${KEYSIZE}") _log 'info' "Creating DKIM keys of type '${KEYTYPE}' and length '${KEYSIZE}' with selector '${SELECTOR}' for domain '${DOMAIN}'" else - local BASE_FILE_NAME="${RSPAMD_DMS_DKIM_D}/${KEYTYPE}-${SELECTOR}-${DOMAIN}" KEYTYPE_OPTIONS=('-t' "${KEYTYPE}") _log 'info' "Creating DKIM keys of type '${KEYTYPE}' with selector '${SELECTOR}' for domain '${DOMAIN}'" + _log 'info' "Ed25519 and RSA cannot share a selector; generate an RSA fallback with a different selector and add both to a 'selectors' array in dkim_signing.conf" fi PUBLIC_KEY_FILE="${BASE_FILE_NAME}.public.txt" PUBLIC_KEY_DNS_FILE="${BASE_FILE_NAME}.public.dns.txt" - PRIVATE_KEY_FILE="${BASE_FILE_NAME}.private.txt" + PRIVATE_KEY_FILE="${BASE_FILE_NAME}.private" if [[ -f ${PUBLIC_KEY_FILE} ]] || [[ -f ${PUBLIC_KEY_DNS_FILE} ]] || [[ -f ${PRIVATE_KEY_FILE} ]]; then if [[ ${FORCE} -eq 0 ]]; then @@ -222,7 +226,7 @@ function _check_permissions() { function _setup_default_signing_conf() { local DEFAULT_CONFIG_FILE="${RSPAMD_DMS_OVERRIDE_D}/dkim_signing.conf" if [[ -f ${DEFAULT_CONFIG_FILE} ]]; then - _log 'info' "'${DEFAULT_CONFIG_FILE}' exists, not supplying a default ('--force' does not overwrite this file, manual adjustment required)" + _log 'info' "'${DEFAULT_CONFIG_FILE}' exists, not supplying a default ('--force' does not overwrite this file, manual adjustment may be required)" else _log 'info' "Supplying a default configuration (to '${DEFAULT_CONFIG_FILE}')" cat >"${DEFAULT_CONFIG_FILE}" << EOF @@ -232,7 +236,6 @@ enabled = true; sign_authenticated = true; sign_local = false; -try_fallback = false; use_domain = "header"; use_redis = false; # don't change unless Redis also provides the DKIM keys @@ -241,12 +244,30 @@ allow_username_mismatch = true; check_pubkey = true; # you want to use this in the beginning -domain { - ${DOMAIN} { - path = "${PRIVATE_KEY_FILE}"; - selector = "${SELECTOR}"; - } -} +try_fallback = true; +selector_map = "${SELECTOR_MAP_FILE}"; +selector = "mail"; + +# The path location is searched for a DKIM key with these variables: +# - '\$domain' is sourced from the MIME mail message 'From' header +# - '\$selector' comes from selector_map when present, otherwise the default below +path = "${RSPAMD_DMS_DKIM_D}/\$domain-\$selector.private"; + +# Dual signing (e.g. RSA + Ed25519) needs a domain-specific selectors array: +#domain { +# example.com { +# selectors [ +# { +# path = "${RSPAMD_DMS_DKIM_D}/example.com-mail.private"; +# selector = "mail"; +# }, +# { +# path = "${RSPAMD_DMS_DKIM_D}/example.com-mail-ed25519.private"; +# selector = "mail-ed25519"; +# } +# ] +# } +#} EOF @@ -256,6 +277,31 @@ EOF cp "${DEFAULT_CONFIG_FILE}" "${RSPAMD_OVERRIDE_D}/dkim_signing.conf" chown _rspamd:_rspamd "${DEFAULT_CONFIG_FILE}" "${RSPAMD_OVERRIDE_D}/dkim_signing.conf" fi + + # Rspamd fails to load selector_map when the file is missing; keep an empty map around. + touch "${SELECTOR_MAP_FILE}" + chown _rspamd:_rspamd "${SELECTOR_MAP_FILE}" +} + +# Record DOMAIN -> SELECTOR so a custom selector is used with the path template. +# One map entry per domain; dual signing needs a 'selectors' array in dkim_signing.conf. +function _update_selector_map() { + local TMP_FILE="${SELECTOR_MAP_FILE}.tmp" + local PREVIOUS_SELECTOR + + touch "${SELECTOR_MAP_FILE}" + PREVIOUS_SELECTOR=$(awk -v domain="${DOMAIN}" '$1 == domain { print $2; exit }' "${SELECTOR_MAP_FILE}") + if [[ -n "${PREVIOUS_SELECTOR}" ]] && [[ "${PREVIOUS_SELECTOR}" != "${SELECTOR}" ]]; then + _log 'warn' "Selector map for '${DOMAIN}' already used '${PREVIOUS_SELECTOR}'; replacing with '${SELECTOR}'. Dual signing (RSA + Ed25519) needs a 'selectors' array in dkim_signing.conf, not selector_map" + fi + + awk -v domain="${DOMAIN}" -v selector="${SELECTOR}" ' + $1 != domain { print } + END { print domain, selector } + ' "${SELECTOR_MAP_FILE}" >"${TMP_FILE}" + mv "${TMP_FILE}" "${SELECTOR_MAP_FILE}" + chown _rspamd:_rspamd "${SELECTOR_MAP_FILE}" + chmod 644 "${SELECTOR_MAP_FILE}" } function _transform_public_key_file_to_dns_record_contents() { @@ -284,5 +330,6 @@ _preflight_checks _create_keys _check_permissions _setup_default_signing_conf +_update_selector_map _transform_public_key_file_to_dns_record_contents _final_steps diff --git a/test/tests/parallel/set1/spam_virus/rspamd_dkim.bats b/test/tests/parallel/set1/spam_virus/rspamd_dkim.bats index f5e030b5..b3984103 100644 --- a/test/tests/parallel/set1/spam_virus/rspamd_dkim.bats +++ b/test/tests/parallel/set1/spam_virus/rspamd_dkim.bats @@ -6,6 +6,7 @@ CONTAINER_NAME='dms-test_rspamd-dkim' DOMAIN_NAME='example.test' SIGNING_CONF_FILE='/tmp/docker-mailserver/rspamd/override.d/dkim_signing.conf' +SELECTOR_MAP_FILE='/tmp/docker-mailserver/rspamd/dkim_selectors.map' function setup_file() { _init_with_defaults @@ -30,6 +31,7 @@ function setup_file() { # We want each test to start with a clean state. function teardown() { __remove_signing_config_file + __remove_selector_map _run_in_container rm -rf /tmp/docker-mailserver/rspamd/dkim assert_success } @@ -63,7 +65,8 @@ function teardown_file() { _default_teardown ; } assert_output --partial "Supplying a default configuration (to '${SIGNING_CONF_FILE}')" refute_output --partial "'${SIGNING_CONF_FILE}' exists, not supplying a default" assert_output --partial "Finished DKIM key creation" - _file_exists_in_container "${SIGNING_CONF_FILE}" + __check_default_signing_config + __check_selector_map_entry "${DOMAIN_NAME}" 'mail' _exec_in_container_bash "echo 'blabla' >${SIGNING_CONF_FILE}" local INITIAL_SHA512_SUM=$(_exec_in_container sha512sum "${SIGNING_CONF_FILE}") @@ -88,22 +91,27 @@ function teardown_file() { _default_teardown ; } _count_files_in_directory_in_container /tmp/docker-mailserver/rspamd/dkim/ 3 _file_exists_in_container "${SIGNING_CONF_FILE}" - - __check_path_in_signing_config "/tmp/docker-mailserver/rspamd/dkim/rsa-2048-mail-${DOMAIN_NAME}.private.txt" - __check_selector_in_signing_config 'mail' + _file_exists_in_container "${SELECTOR_MAP_FILE}" } @test "argument 'domain' is applied correctly" { + local FIRST=1 for DOMAIN in 'blabla.org' 'someother.com' 'random.de'; do _run_in_container setup config dkim domain "${DOMAIN}" assert_success assert_line --partial "Domain set to '${DOMAIN}'" + if [[ ${FIRST} -eq 1 ]]; then + assert_output --partial "Supplying a default configuration" + FIRST=0 + else + assert_output --partial "exists, not supplying a default" + fi - local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/rsa-2048-mail-${DOMAIN}" - __check_key_files_are_present "${BASE_FILE_NAME}" - __check_path_in_signing_config "${BASE_FILE_NAME}.private.txt" - __remove_signing_config_file + __check_key_files_are_present "/tmp/docker-mailserver/rspamd/dkim/${DOMAIN}-mail" + __check_selector_map_entry "${DOMAIN}" 'mail' done + + __check_default_signing_config } @test "argument 'keytype' is applied correctly" { @@ -116,16 +124,17 @@ function teardown_file() { _default_teardown ; } assert_success assert_line --partial "Keytype set to '${KEYTYPE}'" - local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/ed25519-mail-${DOMAIN_NAME}" - [[ ${KEYTYPE} == 'rsa' ]] && BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/rsa-2048-mail-${DOMAIN_NAME}" + local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/${DOMAIN_NAME}-mail" __check_key_files_are_present "${BASE_FILE_NAME}" _run_in_container grep ".*k=${KEYTYPE};.*" "${BASE_FILE_NAME}.public.txt" assert_success _run_in_container grep ".*k=${KEYTYPE};.*" "${BASE_FILE_NAME}.public.dns.txt" assert_success - __check_path_in_signing_config "${BASE_FILE_NAME}.private.txt" __remove_signing_config_file + _exec_in_container rm -f "${BASE_FILE_NAME}.public.txt" + _exec_in_container rm -f "${BASE_FILE_NAME}.public.dns.txt" + _exec_in_container rm -f "${BASE_FILE_NAME}.private" done } @@ -135,15 +144,15 @@ function teardown_file() { _default_teardown ; } assert_success assert_line --partial "Selector set to '${SELECTOR}'" - local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/rsa-2048-${SELECTOR}-${DOMAIN_NAME}" + local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/${DOMAIN_NAME}-${SELECTOR}" __check_key_files_are_present "${BASE_FILE_NAME}" _run_in_container grep "^${SELECTOR}\._domainkey.*" "${BASE_FILE_NAME}.public.txt" assert_success - __check_rsa_keys 2048 "${SELECTOR}-${DOMAIN_NAME}" - __check_path_in_signing_config "${BASE_FILE_NAME}.private.txt" - __check_selector_in_signing_config "${SELECTOR}" - __remove_signing_config_file + __check_rsa_keys 2048 "${DOMAIN_NAME}-${SELECTOR}" + __check_default_signing_config + __check_selector_map_entry "${DOMAIN_NAME}" "${SELECTOR}" + __remove_selector_map done } @@ -153,8 +162,12 @@ function teardown_file() { _default_teardown ; } assert_success __log_is_free_of_warnings_and_errors assert_line --partial "Keysize set to '${KEYSIZE}'" - __check_rsa_keys "${KEYSIZE}" "mail-${DOMAIN_NAME}" + __check_rsa_keys "${KEYSIZE}" "${DOMAIN_NAME}-mail" __remove_signing_config_file + local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/${DOMAIN_NAME}-mail" + _exec_in_container rm -f "${BASE_FILE_NAME}.public.txt" + _exec_in_container rm -f "${BASE_FILE_NAME}.public.dns.txt" + _exec_in_container rm -f "${BASE_FILE_NAME}.private" done } @@ -177,9 +190,30 @@ function teardown_file() { _default_teardown ; } assert_line --partial "Selector set to '${SELECTOR}'" assert_line --partial "Domain set to '${DOMAIN}'" - local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/${KEYTYPE}-${SELECTOR}-${DOMAIN}" - __check_path_in_signing_config "${BASE_FILE_NAME}.private.txt" - __check_selector_in_signing_config 'someselector' + __check_key_files_are_present "/tmp/docker-mailserver/rspamd/dkim/${DOMAIN}-${SELECTOR}" + __check_default_signing_config + __check_selector_map_entry "${DOMAIN}" "${SELECTOR}" +} + +@test "same selector cannot hold both RSA and Ed25519 keys" { + __create_key 'rsa' 'mail' + assert_success + __create_key 'ed25519' 'mail' + assert_failure + assert_output --partial "Not overwriting existing files" +} + +@test "RSA and Ed25519 keys coexist when selectors differ" { + __create_key 'rsa' 'mail' + assert_success + __create_key 'ed25519' 'mail-ed25519' + assert_success + assert_output --partial "replacing with 'mail-ed25519'" + + __check_key_files_are_present "/tmp/docker-mailserver/rspamd/dkim/${DOMAIN_NAME}-mail" + __check_key_files_are_present "/tmp/docker-mailserver/rspamd/dkim/${DOMAIN_NAME}-mail-ed25519" + __check_default_signing_config + __check_selector_map_entry "${DOMAIN_NAME}" 'mail-ed25519' } # Create DKIM keys. @@ -213,13 +247,10 @@ function __create_key() { function __check_rsa_keys() { local KEYSIZE=${1:?Keysize must be supplied to __check_rsa_keys} local SELECTOR_AND_DOMAIN=${2:?Selector and domain name must be supplied to __check_rsa_keys} - local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/rsa-${KEYSIZE}-${SELECTOR_AND_DOMAIN}" - - __check_key_files_are_present "${BASE_FILE_NAME}" - __check_path_in_signing_config "${BASE_FILE_NAME}.private.txt" + local BASE_FILE_NAME="/tmp/docker-mailserver/rspamd/dkim/${SELECTOR_AND_DOMAIN}" # Check the private key matches the specification - _run_in_container_bash "openssl rsa -in '${BASE_FILE_NAME}.private.txt' -noout -text" + _run_in_container_bash "openssl rsa -in '${BASE_FILE_NAME}.private' -noout -text" assert_success assert_line --index 0 "Private-Key: (${KEYSIZE} bit, 2 primes)" @@ -239,26 +270,37 @@ function __check_rsa_keys() { # @param ${1} = base file name that all DKIM key files have function __check_key_files_are_present() { local BASE_FILE_NAME="${1:?Base file name must be supplied to __check_key_files_are_present}" - for FILE in ${BASE_FILE_NAME}.{public.txt,public.dns.txt,private.txt}; do + for FILE in ${BASE_FILE_NAME}.{public.txt,public.dns.txt,private}; do _file_exists_in_container "${FILE}" done } -# Check whether `path = .*` is set correctly in the signing configuration file. -# -# @param ${1} = file name that `path` should be set to -function __check_path_in_signing_config() { - local BASE_FILE_NAME=${1:?Base file name must be supplied to __check_path_in_signing_config} - _run_in_container grep "[[:space:]]*path = \"${BASE_FILE_NAME}\";" "${SIGNING_CONF_FILE}" +# Check the generated default signing config uses the path template. +function __check_default_signing_config() { + _file_exists_in_container "${SIGNING_CONF_FILE}" + _run_in_container grep -F 'try_fallback = true;' "${SIGNING_CONF_FILE}" + assert_success + _run_in_container grep -F 'selector = "mail";' "${SIGNING_CONF_FILE}" + assert_success + _run_in_container grep -F 'selector_map = "/tmp/docker-mailserver/rspamd/dkim_selectors.map";' "${SIGNING_CONF_FILE}" + assert_success + # shellcheck disable=SC2016 + _run_in_container grep -F 'path = "/tmp/docker-mailserver/rspamd/dkim/$domain-$selector.private";' "${SIGNING_CONF_FILE}" assert_success } -# Check whether `selector = .*` is set correctly in the signing configuration file. +# Check whether DOMAIN maps to SELECTOR in the persisted selector map. # -# @param ${1} = name that `selector` should be set to -function __check_selector_in_signing_config() { - local SELECTOR=${1:?Selector name must be supplied to __check_selector_in_signing_config} - _run_in_container grep "[[:space:]]*selector = \"${SELECTOR}\";" "${SIGNING_CONF_FILE}" +# @param ${1} = domain +# @param ${2} = selector +function __check_selector_map_entry() { + local DOMAIN=${1:?Domain must be supplied to __check_selector_map_entry} + local SELECTOR=${2:?Selector must be supplied to __check_selector_map_entry} + _file_exists_in_container "${SELECTOR_MAP_FILE}" + # shellcheck disable=SC2016 + _run_in_container awk -v domain="${DOMAIN}" -v selector="${SELECTOR}" \ + '$1 == domain && $2 == selector { found = 1 } END { exit found ? 0 : 1 }' \ + "${SELECTOR_MAP_FILE}" assert_success } @@ -273,3 +315,8 @@ function __log_is_free_of_warnings_and_errors() { function __remove_signing_config_file() { _exec_in_container rm -f "${SIGNING_CONF_FILE}" } + +# Remove the persisted selector map inside the container. +function __remove_selector_map() { + _exec_in_container rm -f "${SELECTOR_MAP_FILE}" +}