mirror of
https://github.com/chatmail/relay.git
synced 2026-05-11 08:24:37 +00:00
Compare commits
46 Commits
rspamd
...
socks-setu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e331659851 | ||
|
|
c8d9f20a48 | ||
|
|
6a30db7ce0 | ||
|
|
9e9ab80422 | ||
|
|
5b9debfbdf | ||
|
|
788309b85a | ||
|
|
5bbb3d9b21 | ||
|
|
6bc2186912 | ||
|
|
8d5f91bf98 | ||
|
|
9ddf60d0fc | ||
|
|
05bdf65996 | ||
|
|
6d6217812d | ||
|
|
ea36e73b8e | ||
|
|
da268b57d4 | ||
|
|
5588e13e54 | ||
|
|
7c7f1cad7f | ||
|
|
a6b333672d | ||
|
|
29857143c9 | ||
|
|
d1460e7a1a | ||
|
|
87ab7e83d5 | ||
|
|
9f31357a9c | ||
|
|
c94ef0379a | ||
|
|
bc66325d71 | ||
|
|
27f44ae911 | ||
|
|
3940b9256d | ||
|
|
4886ff9b86 | ||
|
|
38a9fc3d6e | ||
|
|
e676545f7a | ||
|
|
ef95627138 | ||
|
|
bfaedb5cf1 | ||
|
|
ea8d53aa9b | ||
|
|
be7a000de6 | ||
|
|
ad3cf9ecaa | ||
|
|
691324a3e8 | ||
|
|
23a9f893b4 | ||
|
|
3ea826aecb | ||
|
|
532d094a08 | ||
|
|
0cea5840df | ||
|
|
45686778ea | ||
|
|
45108d9c93 | ||
|
|
3665d957a7 | ||
|
|
86940b2ee1 | ||
|
|
24fb9eb65b | ||
|
|
700256c273 | ||
|
|
d575d62b18 | ||
|
|
8cdf8ce376 |
20
.github/workflows/staging.testrun.org-default.zone
vendored
Normal file
20
.github/workflows/staging.testrun.org-default.zone
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
;; Zone file for staging.testrun.org
|
||||||
|
|
||||||
|
$ORIGIN staging.testrun.org.
|
||||||
|
$TTL 300
|
||||||
|
|
||||||
|
@ IN SOA ns.testrun.org. root.nine.testrun.org (
|
||||||
|
2023010101 ; Serial
|
||||||
|
7200 ; Refresh
|
||||||
|
3600 ; Retry
|
||||||
|
1209600 ; Expire
|
||||||
|
3600 ; Negative response caching TTL
|
||||||
|
)
|
||||||
|
|
||||||
|
;; Nameservers.
|
||||||
|
@ IN NS ns.testrun.org.
|
||||||
|
|
||||||
|
;; DNS records.
|
||||||
|
@ IN A 37.27.37.98
|
||||||
|
mta-sts.staging.testrun.org. CNAME staging.testrun.org.
|
||||||
|
www.staging.testrun.org. CNAME staging.testrun.org.
|
||||||
72
.github/workflows/test-and-deploy.yaml
vendored
Normal file
72
.github/workflows/test-and-deploy.yaml
vendored
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
name: deploy on staging.testrun.org, and run tests
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- staging-ci
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
name: deploy on staging.testrun.org, and run tests
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: prepare SSH
|
||||||
|
run: |
|
||||||
|
mkdir ~/.ssh
|
||||||
|
echo "${{ secrets.STAGING_SSH_KEY }}" >> ~/.ssh/id_ed25519
|
||||||
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
|
ssh-keyscan staging.testrun.org > ~/.ssh/known_hosts
|
||||||
|
# rsync -avz root@staging.testrun.org:/var/lib/acme . || true
|
||||||
|
# rsync -avz root@staging.testrun.org:/var/lib/rspamd/dkim . || true
|
||||||
|
|
||||||
|
#- name: rebuild staging.testrun.org to have a clean VPS
|
||||||
|
# run: |
|
||||||
|
# curl -X POST \
|
||||||
|
# -H "Authorization: Bearer ${{ secrets.HETZNER_API_TOKEN }}" \
|
||||||
|
# -H "Content-Type: application/json" \
|
||||||
|
# -d '{"image":"debian-12"}' \
|
||||||
|
# "https://api.hetzner.cloud/v1/servers/${{ secrets.STAGING_SERVER_ID }}/actions/rebuild"
|
||||||
|
|
||||||
|
- run: scripts/initenv.sh
|
||||||
|
|
||||||
|
- name: append venv/bin to PATH
|
||||||
|
run: echo venv/bin >>$GITHUB_PATH
|
||||||
|
|
||||||
|
- name: run formatting checks
|
||||||
|
run: cmdeploy fmt -v
|
||||||
|
|
||||||
|
- name: run deploy-chatmail offline tests
|
||||||
|
run: pytest --pyargs cmdeploy
|
||||||
|
|
||||||
|
#- name: upload TLS cert after rebuilding
|
||||||
|
# run: |
|
||||||
|
# echo " --- wait until staging.testrun.org VPS is rebuilt --- "
|
||||||
|
# rm ~/.ssh/known_hosts
|
||||||
|
# while ! ssh -o ConnectTimeout=180 -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u ; do sleep 1 ; done
|
||||||
|
# ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org id -u
|
||||||
|
# rsync -avz acme root@staging.testrun.org:/var/lib/ || true
|
||||||
|
# rsync -avz dkim root@staging.testrun.org:/var/lib/rspamd/ || true
|
||||||
|
|
||||||
|
- run: cmdeploy init staging.testrun.org
|
||||||
|
|
||||||
|
- run: cmdeploy run
|
||||||
|
|
||||||
|
- name: set DNS entries
|
||||||
|
run: |
|
||||||
|
#ssh -o StrictHostKeyChecking=accept-new -v root@staging.testrun.org chown _rspamd:_rspamd -R /var/lib/rspamd/dkim
|
||||||
|
cmdeploy dns --zonefile staging-generated.zone
|
||||||
|
cat staging-generated.zone >> .github/workflows/staging.testrun.org-default.zone
|
||||||
|
cat .github/workflows/staging.testrun.org-default.zone
|
||||||
|
scp -o StrictHostKeyChecking=accept-new .github/workflows/staging.testrun.org-default.zone root@ns.testrun.org:/etc/nsd/staging.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org nsd-checkzone staging.testrun.org /etc/nsd/staging.testrun.org.zone
|
||||||
|
ssh root@ns.testrun.org systemctl reload nsd
|
||||||
|
|
||||||
|
- name: cmdeploy test
|
||||||
|
run: CHATMAIL_DOMAIN2=nine.testrun.org cmdeploy test --slow
|
||||||
|
|
||||||
|
- name: cmdeploy dns (try 3 times)
|
||||||
|
run: cmdeploy dns || cmdeploy dns || cmdeploy dns
|
||||||
|
|
||||||
@@ -160,6 +160,19 @@ def handle_dovecot_request(msg, db, config: Config):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def handle_dovecot_protocol(rfile, wfile, db: Database, config: Config):
|
||||||
|
while True:
|
||||||
|
msg = rfile.readline().strip().decode()
|
||||||
|
if not msg:
|
||||||
|
break
|
||||||
|
res = handle_dovecot_request(msg, db, config)
|
||||||
|
if res:
|
||||||
|
wfile.write(res.encode("ascii"))
|
||||||
|
wfile.flush()
|
||||||
|
else:
|
||||||
|
logging.warning("request had no answer: %r", msg)
|
||||||
|
|
||||||
|
|
||||||
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
class ThreadedUnixStreamServer(ThreadingMixIn, UnixStreamServer):
|
||||||
request_queue_size = 100
|
request_queue_size = 100
|
||||||
|
|
||||||
@@ -173,16 +186,7 @@ def main():
|
|||||||
class Handler(StreamRequestHandler):
|
class Handler(StreamRequestHandler):
|
||||||
def handle(self):
|
def handle(self):
|
||||||
try:
|
try:
|
||||||
while True:
|
handle_dovecot_protocol(self.rfile, self.wfile, db, config)
|
||||||
msg = self.rfile.readline().strip().decode()
|
|
||||||
if not msg:
|
|
||||||
break
|
|
||||||
res = handle_dovecot_request(msg, db, config)
|
|
||||||
if res:
|
|
||||||
self.wfile.write(res.encode("ascii"))
|
|
||||||
self.wfile.flush()
|
|
||||||
else:
|
|
||||||
logging.warn("request had no answer: %r", msg)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("Exception in the handler")
|
logging.exception("Exception in the handler")
|
||||||
raise
|
raise
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ password_min_length = 9
|
|||||||
passthrough_senders =
|
passthrough_senders =
|
||||||
|
|
||||||
# list of e-mail recipients for which to accept outbound un-encrypted mails
|
# list of e-mail recipients for which to accept outbound un-encrypted mails
|
||||||
passthrough_recipients =
|
passthrough_recipients = xstore@testrun.org groupsbot@hispanilandia.net
|
||||||
|
|
||||||
#
|
#
|
||||||
# Deployment Details
|
# Deployment Details
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
[privacy]
|
[privacy]
|
||||||
|
|
||||||
passthrough_recipients = privacy@testrun.org
|
passthrough_recipients = privacy@testrun.org xstore@testrun.org groupsbot@hispanilandia.net
|
||||||
|
|
||||||
privacy_postal =
|
privacy_postal =
|
||||||
Merlinux GmbH, Represented by the managing director H. Krekel,
|
Merlinux GmbH, Represented by the managing director H. Krekel,
|
||||||
|
|||||||
@@ -28,5 +28,5 @@ def test_read_config_testrun(make_config):
|
|||||||
assert config.username_min_length == 9
|
assert config.username_min_length == 9
|
||||||
assert config.username_max_length == 9
|
assert config.username_max_length == 9
|
||||||
assert config.password_min_length == 9
|
assert config.password_min_length == 9
|
||||||
assert config.passthrough_recipients == ["privacy@testrun.org"]
|
assert "privacy@testrun.org" in config.passthrough_recipients
|
||||||
assert config.passthrough_senders == []
|
assert config.passthrough_senders == []
|
||||||
|
|||||||
@@ -1,11 +1,17 @@
|
|||||||
|
import io
|
||||||
import json
|
import json
|
||||||
import pytest
|
import pytest
|
||||||
import threading
|
|
||||||
import queue
|
import queue
|
||||||
|
import threading
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
import chatmaild.doveauth
|
import chatmaild.doveauth
|
||||||
from chatmaild.doveauth import get_user_data, lookup_passdb, handle_dovecot_request
|
from chatmaild.doveauth import (
|
||||||
|
get_user_data,
|
||||||
|
lookup_passdb,
|
||||||
|
handle_dovecot_request,
|
||||||
|
handle_dovecot_protocol,
|
||||||
|
)
|
||||||
from chatmaild.database import DBError
|
from chatmaild.database import DBError
|
||||||
|
|
||||||
|
|
||||||
@@ -69,6 +75,15 @@ def test_handle_dovecot_request(db, example_config):
|
|||||||
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
assert userdata["password"].startswith("{SHA512-CRYPT}")
|
||||||
|
|
||||||
|
|
||||||
|
def test_handle_dovecot_protocol(db, example_config):
|
||||||
|
rfile = io.BytesIO(
|
||||||
|
b"H3\t2\t0\t\tauth\nLshared/userdb/foobar@chat.example.org\tfoobar@chat.example.org\n"
|
||||||
|
)
|
||||||
|
wfile = io.BytesIO()
|
||||||
|
handle_dovecot_protocol(rfile, wfile, db, example_config)
|
||||||
|
assert wfile.getvalue() == b"N\n"
|
||||||
|
|
||||||
|
|
||||||
def test_50_concurrent_lookups_different_accounts(db, gencreds, example_config):
|
def test_50_concurrent_lookups_different_accounts(db, gencreds, example_config):
|
||||||
num_threads = 50
|
num_threads = 50
|
||||||
req_per_thread = 5
|
req_per_thread = 5
|
||||||
|
|||||||
@@ -126,6 +126,107 @@ def _install_remote_venv_with_chatmaild(config) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def _configure_opendkim(domain: str, dkim_selector: str = "dkim") -> bool:
|
||||||
|
"""Configures OpenDKIM"""
|
||||||
|
need_restart = False
|
||||||
|
|
||||||
|
server.group(name="Create opendkim group", group="opendkim", system=True)
|
||||||
|
server.user(
|
||||||
|
name="Create opendkim user",
|
||||||
|
user="opendkim",
|
||||||
|
groups=["opendkim"],
|
||||||
|
system=True,
|
||||||
|
)
|
||||||
|
server.user(
|
||||||
|
name="Add postfix user to opendkim group for socket access",
|
||||||
|
user="postfix",
|
||||||
|
groups=["opendkim"],
|
||||||
|
system=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
main_config = files.template(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("opendkim/opendkim.conf"),
|
||||||
|
dest="/etc/opendkim.conf",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
config={"domain_name": domain, "opendkim_selector": dkim_selector},
|
||||||
|
)
|
||||||
|
need_restart |= main_config.changed
|
||||||
|
|
||||||
|
screen_script = files.put(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("opendkim/screen.lua"),
|
||||||
|
dest="/etc/opendkim/screen.lua",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
need_restart |= screen_script.changed
|
||||||
|
|
||||||
|
final_script = files.put(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("opendkim/final.lua"),
|
||||||
|
dest="/etc/opendkim/final.lua",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
need_restart |= final_script.changed
|
||||||
|
|
||||||
|
files.directory(
|
||||||
|
name="Add opendkim directory to /etc",
|
||||||
|
path="/etc/opendkim",
|
||||||
|
user="opendkim",
|
||||||
|
group="opendkim",
|
||||||
|
mode="750",
|
||||||
|
present=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
keytable = files.template(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("opendkim/KeyTable"),
|
||||||
|
dest="/etc/dkimkeys/KeyTable",
|
||||||
|
user="opendkim",
|
||||||
|
group="opendkim",
|
||||||
|
mode="644",
|
||||||
|
config={"domain_name": domain, "opendkim_selector": dkim_selector},
|
||||||
|
)
|
||||||
|
need_restart |= keytable.changed
|
||||||
|
|
||||||
|
signing_table = files.template(
|
||||||
|
src=importlib.resources.files(__package__).joinpath("opendkim/SigningTable"),
|
||||||
|
dest="/etc/dkimkeys/SigningTable",
|
||||||
|
user="opendkim",
|
||||||
|
group="opendkim",
|
||||||
|
mode="644",
|
||||||
|
config={"domain_name": domain, "opendkim_selector": dkim_selector},
|
||||||
|
)
|
||||||
|
need_restart |= signing_table.changed
|
||||||
|
files.directory(
|
||||||
|
name="Add opendkim socket directory to /var/spool/postfix",
|
||||||
|
path="/var/spool/postfix/opendkim",
|
||||||
|
user="opendkim",
|
||||||
|
group="opendkim",
|
||||||
|
mode="750",
|
||||||
|
present=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
apt.packages(
|
||||||
|
name="apt install opendkim opendkim-tools",
|
||||||
|
packages=["opendkim", "opendkim-tools"],
|
||||||
|
)
|
||||||
|
|
||||||
|
if not host.get_fact(File, f"/etc/dkimkeys/{dkim_selector}.private"):
|
||||||
|
server.shell(
|
||||||
|
name="Generate OpenDKIM domain keys",
|
||||||
|
commands=[
|
||||||
|
f"opendkim-genkey -D /etc/dkimkeys -d {domain} -s {dkim_selector}"
|
||||||
|
],
|
||||||
|
_sudo=True,
|
||||||
|
_sudo_user="opendkim",
|
||||||
|
)
|
||||||
|
|
||||||
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
def _install_mta_sts_daemon() -> bool:
|
def _install_mta_sts_daemon() -> bool:
|
||||||
need_restart = False
|
need_restart = False
|
||||||
|
|
||||||
@@ -200,6 +301,18 @@ def _configure_postfix(config: Config, debug: bool = False) -> bool:
|
|||||||
)
|
)
|
||||||
need_restart |= header_cleanup.changed
|
need_restart |= header_cleanup.changed
|
||||||
|
|
||||||
|
# Login map that 1:1 maps email address to login.
|
||||||
|
login_map = files.put(
|
||||||
|
src=importlib.resources.files(__package__).joinpath(
|
||||||
|
"postfix/login_map"
|
||||||
|
),
|
||||||
|
dest="/etc/postfix/login_map",
|
||||||
|
user="root",
|
||||||
|
group="root",
|
||||||
|
mode="644",
|
||||||
|
)
|
||||||
|
need_restart |= login_map.changed
|
||||||
|
|
||||||
return need_restart
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
@@ -305,105 +418,9 @@ def _configure_nginx(domain: str, debug: bool = False) -> bool:
|
|||||||
return need_restart
|
return need_restart
|
||||||
|
|
||||||
|
|
||||||
def remove_opendkim() -> None:
|
def _remove_rspamd() -> None:
|
||||||
"""Remove OpenDKIM, deprecated"""
|
"""Remove rspamd"""
|
||||||
files.file(
|
apt.packages(name="Remove rspamd", packages="rspamd", present=False)
|
||||||
name="Remove legacy opendkim.conf",
|
|
||||||
path="/etc/opendkim.conf",
|
|
||||||
present=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
files.directory(
|
|
||||||
name="Remove legacy opendkim socket directory from /var/spool/postfix",
|
|
||||||
path="/var/spool/postfix/opendkim",
|
|
||||||
present=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
apt.packages(name="Remove openDKIM", packages="opendkim", present=False)
|
|
||||||
|
|
||||||
|
|
||||||
def _configure_rspamd(dkim_selector: str, mail_domain: str) -> bool:
|
|
||||||
"""Configures rspamd for Rate Limiting."""
|
|
||||||
need_restart = False
|
|
||||||
|
|
||||||
apt.packages(
|
|
||||||
name="apt install rspamd",
|
|
||||||
packages="rspamd",
|
|
||||||
)
|
|
||||||
|
|
||||||
for module in ["phishing", "rbl", "hfilter", "ratelimit"]:
|
|
||||||
disabled_module_conf = files.put(
|
|
||||||
name=f"disable {module} rspamd plugin",
|
|
||||||
src=importlib.resources.files(__package__).joinpath("rspamd/disabled.conf"),
|
|
||||||
dest=f"/etc/rspamd/local.d/{module}.conf",
|
|
||||||
user="root",
|
|
||||||
group="root",
|
|
||||||
mode="644",
|
|
||||||
)
|
|
||||||
need_restart |= disabled_module_conf.changed
|
|
||||||
|
|
||||||
options_inc = files.put(
|
|
||||||
name="disable fuzzy checks",
|
|
||||||
src=importlib.resources.files(__package__).joinpath("rspamd/options.inc"),
|
|
||||||
dest="/etc/rspamd/local.d/options.inc",
|
|
||||||
user="root",
|
|
||||||
group="root",
|
|
||||||
mode="644",
|
|
||||||
)
|
|
||||||
need_restart |= options_inc.changed
|
|
||||||
|
|
||||||
# https://rspamd.com/doc/modules/force_actions.html
|
|
||||||
force_actions_conf = files.put(
|
|
||||||
name="Set up rules to reject on DKIM, SPF and DMARC fails",
|
|
||||||
src=importlib.resources.files(__package__).joinpath(
|
|
||||||
"rspamd/force_actions.conf"
|
|
||||||
),
|
|
||||||
dest="/etc/rspamd/local.d/force_actions.conf",
|
|
||||||
user="root",
|
|
||||||
group="root",
|
|
||||||
mode="644",
|
|
||||||
)
|
|
||||||
need_restart |= force_actions_conf.changed
|
|
||||||
|
|
||||||
dkim_directory = "/var/lib/rspamd/dkim/"
|
|
||||||
dkim_key_path = f"{dkim_directory}{mail_domain}.{dkim_selector}.key"
|
|
||||||
dkim_dns_file = f"{dkim_directory}{mail_domain}.{dkim_selector}.zone"
|
|
||||||
|
|
||||||
dkim_config = files.template(
|
|
||||||
src=importlib.resources.files(__package__).joinpath(
|
|
||||||
"rspamd/dkim_signing.conf.j2"
|
|
||||||
),
|
|
||||||
dest="/etc/rspamd/local.d/dkim_signing.conf",
|
|
||||||
user="root",
|
|
||||||
group="root",
|
|
||||||
mode="644",
|
|
||||||
config={
|
|
||||||
"dkim_selector": str(dkim_selector),
|
|
||||||
"mail_domain": mail_domain,
|
|
||||||
"dkim_key_path": dkim_key_path,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
need_restart |= dkim_config.changed
|
|
||||||
|
|
||||||
files.directory(
|
|
||||||
name="ensure DKIM key directory exists",
|
|
||||||
path=dkim_directory,
|
|
||||||
present=True,
|
|
||||||
user="_rspamd",
|
|
||||||
group="_rspamd",
|
|
||||||
)
|
|
||||||
|
|
||||||
if not host.get_fact(File, dkim_key_path):
|
|
||||||
server.shell(
|
|
||||||
name="Generate DKIM domain keys with rspamd",
|
|
||||||
commands=[
|
|
||||||
f"rspamadm dkim_keygen -b 2048 -s {dkim_selector} -d {mail_domain} -k {dkim_key_path} > {dkim_dns_file}"
|
|
||||||
],
|
|
||||||
_sudo=True,
|
|
||||||
_sudo_user="_rspamd",
|
|
||||||
)
|
|
||||||
|
|
||||||
return need_restart
|
|
||||||
|
|
||||||
|
|
||||||
def check_config(config):
|
def check_config(config):
|
||||||
@@ -442,7 +459,10 @@ def deploy_chatmail(config_path: Path) -> None:
|
|||||||
)
|
)
|
||||||
server.shell(
|
server.shell(
|
||||||
name="Generate root keys for validating DNSSEC",
|
name="Generate root keys for validating DNSSEC",
|
||||||
commands=["unbound-anchor -a /var/lib/unbound/root.key || true"],
|
commands=[
|
||||||
|
"unbound-anchor -a /var/lib/unbound/root.key || true",
|
||||||
|
"systemctl reset-failed unbound.service",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="Start and enable unbound",
|
name="Start and enable unbound",
|
||||||
@@ -491,15 +511,15 @@ def deploy_chatmail(config_path: Path) -> None:
|
|||||||
mta_sts_need_restart = _install_mta_sts_daemon()
|
mta_sts_need_restart = _install_mta_sts_daemon()
|
||||||
nginx_need_restart = _configure_nginx(mail_domain)
|
nginx_need_restart = _configure_nginx(mail_domain)
|
||||||
|
|
||||||
remove_opendkim()
|
_remove_rspamd()
|
||||||
rspamd_need_restart = _configure_rspamd("dkim", mail_domain)
|
opendkim_need_restart = _configure_opendkim(mail_domain, "opendkim")
|
||||||
|
|
||||||
systemd.service(
|
systemd.service(
|
||||||
name="Start and enable rspamd",
|
name="Start and enable OpenDKIM",
|
||||||
service="rspamd.service",
|
service="opendkim.service",
|
||||||
running=True,
|
running=True,
|
||||||
enabled=True,
|
enabled=True,
|
||||||
restarted=rspamd_need_restart,
|
restarted=opendkim_need_restart,
|
||||||
)
|
)
|
||||||
|
|
||||||
systemd.service(
|
systemd.service(
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ _imap._tcp.{chatmail_domain}. SRV 0 1 143 {chatmail_domain}.
|
|||||||
_imaps._tcp.{chatmail_domain}. SRV 0 1 993 {chatmail_domain}.
|
_imaps._tcp.{chatmail_domain}. SRV 0 1 993 {chatmail_domain}.
|
||||||
{chatmail_domain}. CAA 128 issue "letsencrypt.org;accounturi={acme_account_url}"
|
{chatmail_domain}. CAA 128 issue "letsencrypt.org;accounturi={acme_account_url}"
|
||||||
{chatmail_domain}. TXT "v=spf1 a:{chatmail_domain} -all"
|
{chatmail_domain}. TXT "v=spf1 a:{chatmail_domain} -all"
|
||||||
_dmarc.{chatmail_domain}. TXT "v=DMARC1;p=reject;rua=mailto:{email};ruf=mailto:{email};fo=1;adkim=s;aspf=s"
|
_dmarc.{chatmail_domain}. TXT "v=DMARC1;p=reject;adkim=s;aspf=s"
|
||||||
_mta-sts.{chatmail_domain}. TXT "v=STSv1; id={sts_id}"
|
_mta-sts.{chatmail_domain}. TXT "v=STSv1; id={sts_id}"
|
||||||
mta-sts.{chatmail_domain}. CNAME {chatmail_domain}.
|
mta-sts.{chatmail_domain}. CNAME {chatmail_domain}.
|
||||||
www.{chatmail_domain}. CNAME {chatmail_domain}.
|
www.{chatmail_domain}. CNAME {chatmail_domain}.
|
||||||
_smtp._tls.{chatmail_domain}. TXT "v=TLSRPTv1;rua=mailto:{email}"
|
|
||||||
{dkim_entry}
|
{dkim_entry}
|
||||||
|
_adsp._domainkey.{chatmail_domain}. TXT "dkim=discardable"
|
||||||
|
|||||||
@@ -82,7 +82,8 @@ def dns_cmd_options(parser):
|
|||||||
|
|
||||||
def dns_cmd(args, out):
|
def dns_cmd(args, out):
|
||||||
"""Generate dns zone file."""
|
"""Generate dns zone file."""
|
||||||
show_dns(args, out)
|
exit_code = show_dns(args, out)
|
||||||
|
exit(exit_code)
|
||||||
|
|
||||||
|
|
||||||
def status_cmd(args, out):
|
def status_cmd(args, out):
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ class DNS:
|
|||||||
return result == f"{mail_domain}."
|
return result == f"{mail_domain}."
|
||||||
|
|
||||||
|
|
||||||
def show_dns(args, out):
|
def show_dns(args, out) -> int:
|
||||||
|
"""Check existing DNS records, optionally write them to zone file, return exit code 0 or 1."""
|
||||||
template = importlib.resources.files(__package__).joinpath("chatmail.zone.f")
|
template = importlib.resources.files(__package__).joinpath("chatmail.zone.f")
|
||||||
mail_domain = args.config.mail_domain
|
mail_domain = args.config.mail_domain
|
||||||
ssh = f"ssh root@{mail_domain}"
|
ssh = f"ssh root@{mail_domain}"
|
||||||
@@ -60,9 +61,6 @@ def show_dns(args, out):
|
|||||||
continue
|
continue
|
||||||
line = line.replace("\t", " ")
|
line = line.replace("\t", " ")
|
||||||
lines.append(line)
|
lines.append(line)
|
||||||
lines[0] = f"dkim._domainkey.{mail_domain}. IN TXT " + lines[0].strip(
|
|
||||||
"dkim._domainkey IN TXT "
|
|
||||||
)
|
|
||||||
return "\n".join(lines)
|
return "\n".join(lines)
|
||||||
|
|
||||||
print("Checking your DKIM keys and DNS entries...")
|
print("Checking your DKIM keys and DNS entries...")
|
||||||
@@ -70,10 +68,8 @@ def show_dns(args, out):
|
|||||||
acme_account_url = out.shell_output(f"{ssh} -- acmetool account-url")
|
acme_account_url = out.shell_output(f"{ssh} -- acmetool account-url")
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
print("Please run `cmdeploy run` first.")
|
print("Please run `cmdeploy run` first.")
|
||||||
return
|
return 1
|
||||||
dkim_entry = read_dkim_entries(
|
dkim_entry = read_dkim_entries(out.shell_output(f"{ssh} -- opendkim-genzone -F"))
|
||||||
out.shell_output(f"{ssh} -- cat /var/lib/rspamd/dkim/{mail_domain}.dkim.zone")
|
|
||||||
)
|
|
||||||
|
|
||||||
ipv6 = dns.get_ipv6()
|
ipv6 = dns.get_ipv6()
|
||||||
reverse_ipv6 = dns.check_ptr_record(ipv6, mail_domain)
|
reverse_ipv6 = dns.check_ptr_record(ipv6, mail_domain)
|
||||||
@@ -86,7 +82,6 @@ def show_dns(args, out):
|
|||||||
f.read()
|
f.read()
|
||||||
.format(
|
.format(
|
||||||
acme_account_url=acme_account_url,
|
acme_account_url=acme_account_url,
|
||||||
email=f"root@{args.config.mail_domain}",
|
|
||||||
sts_id=datetime.datetime.now().strftime("%Y%m%d%H%M"),
|
sts_id=datetime.datetime.now().strftime("%Y%m%d%H%M"),
|
||||||
chatmail_domain=args.config.mail_domain,
|
chatmail_domain=args.config.mail_domain,
|
||||||
dkim_entry=dkim_entry,
|
dkim_entry=dkim_entry,
|
||||||
@@ -99,14 +94,13 @@ def show_dns(args, out):
|
|||||||
with open(args.zonefile, "w+") as zf:
|
with open(args.zonefile, "w+") as zf:
|
||||||
zf.write(zonefile)
|
zf.write(zonefile)
|
||||||
print(f"DNS records successfully written to: {args.zonefile}")
|
print(f"DNS records successfully written to: {args.zonefile}")
|
||||||
return
|
return 0
|
||||||
except TypeError:
|
except TypeError:
|
||||||
pass
|
pass
|
||||||
started_dkim_parsing = False
|
started_dkim_parsing = False
|
||||||
for line in zonefile.splitlines():
|
for line in zonefile.splitlines():
|
||||||
line = line.format(
|
line = line.format(
|
||||||
acme_account_url=acme_account_url,
|
acme_account_url=acme_account_url,
|
||||||
email=f"root@{args.config.mail_domain}",
|
|
||||||
sts_id=datetime.datetime.now().strftime("%Y%m%d%H%M"),
|
sts_id=datetime.datetime.now().strftime("%Y%m%d%H%M"),
|
||||||
chatmail_domain=args.config.mail_domain,
|
chatmail_domain=args.config.mail_domain,
|
||||||
dkim_entry=dkim_entry,
|
dkim_entry=dkim_entry,
|
||||||
@@ -139,7 +133,7 @@ def show_dns(args, out):
|
|||||||
continue
|
continue
|
||||||
if current != value:
|
if current != value:
|
||||||
to_print.append(line)
|
to_print.append(line)
|
||||||
if " IN TXT ( " in line:
|
if "IN TXT ( " in line:
|
||||||
started_dkim_parsing = True
|
started_dkim_parsing = True
|
||||||
dkim_lines = [line]
|
dkim_lines = [line]
|
||||||
if started_dkim_parsing and line.startswith('"'):
|
if started_dkim_parsing and line.startswith('"'):
|
||||||
@@ -147,12 +141,13 @@ def show_dns(args, out):
|
|||||||
domain, data = "\n".join(dkim_lines).split(" IN TXT ")
|
domain, data = "\n".join(dkim_lines).split(" IN TXT ")
|
||||||
current = dns.get("TXT", domain.strip()[:-1])
|
current = dns.get("TXT", domain.strip()[:-1])
|
||||||
if current:
|
if current:
|
||||||
current = "( %s" % (current.replace('" "', '"\n "'))
|
current = "( %s )" % (current.replace('" "', '"\n "'))
|
||||||
if current != data:
|
if current.replace(";", "\\;") != data:
|
||||||
to_print.append(dkim_entry)
|
to_print.append(dkim_entry)
|
||||||
else:
|
else:
|
||||||
to_print.append(dkim_entry)
|
to_print.append(dkim_entry)
|
||||||
|
|
||||||
|
exit_code = 0
|
||||||
if to_print:
|
if to_print:
|
||||||
to_print.insert(
|
to_print.insert(
|
||||||
0, "You should configure the following DNS entries at your provider:\n"
|
0, "You should configure the following DNS entries at your provider:\n"
|
||||||
@@ -161,6 +156,7 @@ def show_dns(args, out):
|
|||||||
"\nIf you already configured the DNS entries, wait a bit until the DNS entries propagate to the Internet."
|
"\nIf you already configured the DNS entries, wait a bit until the DNS entries propagate to the Internet."
|
||||||
)
|
)
|
||||||
print("\n".join(to_print))
|
print("\n".join(to_print))
|
||||||
|
exit_code = 1
|
||||||
else:
|
else:
|
||||||
out.green("Great! All your DNS entries are correct.")
|
out.green("Great! All your DNS entries are correct.")
|
||||||
|
|
||||||
@@ -180,6 +176,8 @@ def show_dns(args, out):
|
|||||||
print(
|
print(
|
||||||
"You can do so at your hosting provider (maybe this isn't your DNS provider)."
|
"You can do so at your hosting provider (maybe this isn't your DNS provider)."
|
||||||
)
|
)
|
||||||
|
exit_code = 1
|
||||||
|
return exit_code
|
||||||
|
|
||||||
|
|
||||||
def check_necessary_dns(out, mail_domain):
|
def check_necessary_dns(out, mail_domain):
|
||||||
|
|||||||
@@ -13,13 +13,15 @@ auth_cache_size = 100M
|
|||||||
mail_debug = yes
|
mail_debug = yes
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
mail_server_admin = mailto:root@{{ config.mail_domain }}
|
||||||
|
mail_server_comment = Chatmail server
|
||||||
|
|
||||||
mail_plugins = quota
|
mail_plugins = quota
|
||||||
|
|
||||||
# these are the capabilities Delta Chat cares about actually
|
# these are the capabilities Delta Chat cares about actually
|
||||||
# so let's keep the network overhead per login small
|
# so let's keep the network overhead per login small
|
||||||
# https://github.com/deltachat/deltachat-core-rust/blob/master/src/imap/capabilities.rs
|
# https://github.com/deltachat/deltachat-core-rust/blob/master/src/imap/capabilities.rs
|
||||||
imap_capability = IMAP4rev1 IDLE MOVE QUOTA CONDSTORE NOTIFY
|
imap_capability = IMAP4rev1 IDLE MOVE QUOTA CONDSTORE NOTIFY METADATA
|
||||||
|
|
||||||
|
|
||||||
# Authentication for system users.
|
# Authentication for system users.
|
||||||
@@ -73,6 +75,7 @@ mail_privileged_group = vmail
|
|||||||
# <https://datatracker.ietf.org/doc/html/rfc4978.html>
|
# <https://datatracker.ietf.org/doc/html/rfc4978.html>
|
||||||
protocol imap {
|
protocol imap {
|
||||||
mail_plugins = $mail_plugins imap_zlib imap_quota
|
mail_plugins = $mail_plugins imap_zlib imap_quota
|
||||||
|
imap_metadata = yes
|
||||||
}
|
}
|
||||||
|
|
||||||
protocol lmtp {
|
protocol lmtp {
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
# delete all mails after {{ config.delete_mails_after }} days, in the Inbox
|
# delete all mails after {{ config.delete_mails_after }} days, in the Inbox
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/cur -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
# or in any IMAP subfolder
|
# or in any IMAP subfolder
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/.*/cur -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/cur/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
# even if they are unseen
|
# even if they are unseen
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/new -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/.*/new -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/new/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
# or only temporary (but then they shouldn't be around after {{ config.delete_mails_after }} days anyway).
|
# or only temporary (but then they shouldn't be around after {{ config.delete_mails_after }} days anyway).
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/tmp -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }}/*/.*/tmp -mtime +{{ config.delete_mails_after }} -type f -delete
|
2 0 * * * dovecot find /home/vmail/mail/{{ config.mail_domain }} -path '*/.*/tmp/*' -mtime +{{ config.delete_mails_after }} -type f -delete
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import io
|
|||||||
|
|
||||||
|
|
||||||
def gen_qr_png_data(maildomain):
|
def gen_qr_png_data(maildomain):
|
||||||
url = f"DCACCOUNT:https://{maildomain}/cgi-bin/newemail.py"
|
url = f"DCACCOUNT:https://{maildomain}/new"
|
||||||
image = gen_qr(maildomain, url)
|
image = gen_qr(maildomain, url)
|
||||||
temp = io.BytesIO()
|
temp = io.BytesIO()
|
||||||
image.save(temp, format="png")
|
image.save(temp, format="png")
|
||||||
|
|||||||
@@ -45,8 +45,33 @@ http {
|
|||||||
default_type text/plain;
|
default_type text/plain;
|
||||||
}
|
}
|
||||||
|
|
||||||
# add cgi-bin support
|
location /new {
|
||||||
include /usr/share/doc/fcgiwrap/examples/nginx.conf;
|
if ($request_method = GET) {
|
||||||
|
# Redirect to Delta Chat,
|
||||||
|
# which will in turn do a POST request.
|
||||||
|
return 301 dcaccount:https://{{ config.domain_name }}/new;
|
||||||
|
}
|
||||||
|
|
||||||
|
fastcgi_pass unix:/run/fcgiwrap.socket;
|
||||||
|
include /etc/nginx/fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/newemail.py;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Old URL for compatibility with e.g. printed QR codes.
|
||||||
|
#
|
||||||
|
# Copy-paste instead of redirect to /new
|
||||||
|
# because Delta Chat core does not follow redirects.
|
||||||
|
#
|
||||||
|
# Redirects are only for browsers.
|
||||||
|
location /cgi-bin/newemail.py {
|
||||||
|
if ($request_method = GET) {
|
||||||
|
return 301 dcaccount:https://{{ config.domain_name }}/new;
|
||||||
|
}
|
||||||
|
|
||||||
|
fastcgi_pass unix:/run/fcgiwrap.socket;
|
||||||
|
include /etc/nginx/fastcgi_params;
|
||||||
|
fastcgi_param SCRIPT_FILENAME /usr/lib/cgi-bin/newemail.py;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Redirect www. to non-www
|
# Redirect www. to non-www
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
dkim._domainkey.{{ config.domain_name }} {{ config.domain_name }}:{{ config.opendkim_selector }}:/etc/dkimkeys/dkim.private
|
{{ config.opendkim_selector }}._domainkey.{{ config.domain_name }} {{ config.domain_name }}:{{ config.opendkim_selector }}:/etc/dkimkeys/{{ config.opendkim_selector }}.private
|
||||||
|
|||||||
28
cmdeploy/src/cmdeploy/opendkim/final.lua
Normal file
28
cmdeploy/src/cmdeploy/opendkim/final.lua
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
if odkim.internal_ip(ctx) == 1 then
|
||||||
|
-- Outgoing message will be signed,
|
||||||
|
-- no need to look for signatures.
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
nsigs = odkim.get_sigcount(ctx)
|
||||||
|
if nsigs == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, nsigs do
|
||||||
|
sig = odkim.get_sighandle(ctx, i - 1)
|
||||||
|
sigres = odkim.sig_result(sig)
|
||||||
|
|
||||||
|
-- All signatures that do not correspond to From:
|
||||||
|
-- were ignored in screen.lua and return sigres -1.
|
||||||
|
--
|
||||||
|
-- Any valid signature that was not ignored like this
|
||||||
|
-- means the message is acceptable.
|
||||||
|
if sigres == 0 then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
odkim.set_reply(ctx, "554", "5.7.1", "No valid DKIM signature found")
|
||||||
|
odkim.set_result(ctx, SMFIS_REJECT)
|
||||||
|
return nil
|
||||||
@@ -8,10 +8,12 @@ SyslogSuccess yes
|
|||||||
# oversigned, because it is often the identity key used by reputation systems
|
# oversigned, because it is often the identity key used by reputation systems
|
||||||
# and thus somewhat security sensitive.
|
# and thus somewhat security sensitive.
|
||||||
Canonicalization relaxed/simple
|
Canonicalization relaxed/simple
|
||||||
#Mode sv
|
|
||||||
#SubDomains no
|
|
||||||
OversignHeaders From
|
OversignHeaders From
|
||||||
|
|
||||||
|
On-BadSignature reject
|
||||||
|
On-KeyNotFound reject
|
||||||
|
On-NoSignature reject
|
||||||
|
|
||||||
# Signing domain, selector, and key (required). For example, perform signing
|
# Signing domain, selector, and key (required). For example, perform signing
|
||||||
# for domain "example.com" with selector "2020" (2020._domainkey.example.com),
|
# for domain "example.com" with selector "2020" (2020._domainkey.example.com),
|
||||||
# using the private key stored in /etc/dkimkeys/example.private. More granular
|
# using the private key stored in /etc/dkimkeys/example.private. More granular
|
||||||
@@ -22,6 +24,15 @@ KeyFile /etc/dkimkeys/{{ config.opendkim_selector }}.private
|
|||||||
KeyTable /etc/dkimkeys/KeyTable
|
KeyTable /etc/dkimkeys/KeyTable
|
||||||
SigningTable refile:/etc/dkimkeys/SigningTable
|
SigningTable refile:/etc/dkimkeys/SigningTable
|
||||||
|
|
||||||
|
# Sign Autocrypt header in addition to the default specified in RFC 6376.
|
||||||
|
SignHeaders *,+autocrypt
|
||||||
|
|
||||||
|
# Script to ignore signatures that do not correspond to the From: domain.
|
||||||
|
ScreenPolicyScript /etc/opendkim/screen.lua
|
||||||
|
|
||||||
|
# Script to reject mails without a valid DKIM signature.
|
||||||
|
FinalPolicyScript /etc/opendkim/final.lua
|
||||||
|
|
||||||
# In Debian, opendkim runs as user "opendkim". A umask of 007 is required when
|
# In Debian, opendkim runs as user "opendkim". A umask of 007 is required when
|
||||||
# using a local socket with MTAs that access the socket as a non-privileged
|
# using a local socket with MTAs that access the socket as a non-privileged
|
||||||
# user (for example, Postfix). You may need to add user "postfix" to group
|
# user (for example, Postfix). You may need to add user "postfix" to group
|
||||||
@@ -29,22 +40,10 @@ SigningTable refile:/etc/dkimkeys/SigningTable
|
|||||||
UserID opendkim
|
UserID opendkim
|
||||||
UMask 007
|
UMask 007
|
||||||
|
|
||||||
# Socket for the MTA connection (required). If the MTA is inside a chroot jail,
|
|
||||||
# it must be ensured that the socket is accessible. In Debian, Postfix runs in
|
|
||||||
# a chroot in /var/spool/postfix, therefore a Unix socket would have to be
|
|
||||||
# configured as shown on the last line below.
|
|
||||||
#Socket local:/run/opendkim/opendkim.sock
|
|
||||||
#Socket inet:8891@localhost
|
|
||||||
#Socket inet:8891
|
|
||||||
Socket local:/var/spool/postfix/opendkim/opendkim.sock
|
Socket local:/var/spool/postfix/opendkim/opendkim.sock
|
||||||
|
|
||||||
PidFile /run/opendkim/opendkim.pid
|
PidFile /run/opendkim/opendkim.pid
|
||||||
|
|
||||||
# Hosts for which to sign rather than verify, default is 127.0.0.1. See the
|
|
||||||
# OPERATION section of opendkim(8) for more information.
|
|
||||||
#InternalHosts 192.168.0.0/16, 10.0.0.0/8, 172.16.0.0/12
|
|
||||||
|
|
||||||
# The trust anchor enables DNSSEC. In Debian, the trust anchor file is provided
|
# The trust anchor enables DNSSEC. In Debian, the trust anchor file is provided
|
||||||
# by the package dns-root-data.
|
# by the package dns-root-data.
|
||||||
TrustAnchorFile /usr/share/dns/root.key
|
TrustAnchorFile /usr/share/dns/root.key
|
||||||
#Nameservers 127.0.0.1
|
|
||||||
|
|||||||
21
cmdeploy/src/cmdeploy/opendkim/screen.lua
Normal file
21
cmdeploy/src/cmdeploy/opendkim/screen.lua
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
-- Ignore signatures that do not correspond to the From: domain.
|
||||||
|
|
||||||
|
from_domain = odkim.get_fromdomain(ctx)
|
||||||
|
if from_domain == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
n = odkim.get_sigcount(ctx)
|
||||||
|
if n == nil then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
|
||||||
|
for i = 1, n do
|
||||||
|
sig = odkim.get_sighandle(ctx, i - 1)
|
||||||
|
sig_domain = odkim.sig_getdomain(sig)
|
||||||
|
if from_domain ~= sig_domain then
|
||||||
|
odkim.sig_ignore(sig)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return nil
|
||||||
1
cmdeploy/src/cmdeploy/postfix/login_map
Normal file
1
cmdeploy/src/cmdeploy/postfix/login_map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/^(.*)$/ ${1}
|
||||||
@@ -23,6 +23,31 @@ smtp_tls_CApath=/etc/ssl/certs
|
|||||||
smtp_tls_security_level=may
|
smtp_tls_security_level=may
|
||||||
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache
|
||||||
smtp_tls_policy_maps = socketmap:inet:127.0.0.1:8461:postfix
|
smtp_tls_policy_maps = socketmap:inet:127.0.0.1:8461:postfix
|
||||||
|
smtpd_tls_protocols = >=TLSv1.2
|
||||||
|
|
||||||
|
# Disable anonymous cipher suites
|
||||||
|
# and known insecure algorithms.
|
||||||
|
#
|
||||||
|
# Disabling anonymous ciphers
|
||||||
|
# does not generally improve security
|
||||||
|
# because clients that want to verify certificate
|
||||||
|
# will not select them anyway,
|
||||||
|
# but makes cipher suite list shorter and security scanners happy.
|
||||||
|
# See <https://www.postfix.org/TLS_README.html> for discussion.
|
||||||
|
#
|
||||||
|
# Only ancient insecure ciphers should be disabled here
|
||||||
|
# as MTA clients that do not support more secure cipher
|
||||||
|
# likely do not support MTA-STS either and will
|
||||||
|
# otherwise fall back to using plaintext connection.
|
||||||
|
smtpd_tls_exclude_ciphers = aNULL, RC4, MD5, DES
|
||||||
|
|
||||||
|
# Override client's preference order.
|
||||||
|
# <https://www.postfix.org/postconf.5.html#tls_preempt_cipherlist>
|
||||||
|
#
|
||||||
|
# This is mostly to ensure cipher suites with forward secrecy
|
||||||
|
# are preferred over non cipher suites without forward secrecy.
|
||||||
|
# See <https://www.postfix.org/FORWARD_SECRECY_README.html#server_fs>.
|
||||||
|
tls_preempt_cipherlist = yes
|
||||||
|
|
||||||
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
|
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated defer_unauth_destination
|
||||||
myhostname = {{ config.mail_domain }}
|
myhostname = {{ config.mail_domain }}
|
||||||
@@ -46,7 +71,9 @@ inet_protocols = all
|
|||||||
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
virtual_transport = lmtp:unix:private/dovecot-lmtp
|
||||||
virtual_mailbox_domains = {{ config.mail_domain }}
|
virtual_mailbox_domains = {{ config.mail_domain }}
|
||||||
|
|
||||||
smtpd_milters = inet:127.0.0.1:11332
|
mua_client_restrictions = permit_sasl_authenticated, reject
|
||||||
non_smtpd_milters = $smtpd_milters
|
mua_sender_restrictions = reject_sender_login_mismatch, permit_sasl_authenticated, reject
|
||||||
|
mua_helo_restrictions = permit_mynetworks, reject_invalid_helo_hostname, reject_non_fqdn_helo_hostname, permit
|
||||||
|
|
||||||
header_checks = regexp:/etc/postfix/submission_header_cleanup
|
# 1:1 map MAIL FROM to SASL login name.
|
||||||
|
smtpd_sender_login_maps = regexp:/etc/postfix/login_map
|
||||||
|
|||||||
@@ -11,13 +11,10 @@
|
|||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
{% if debug == true %}
|
{% if debug == true %}
|
||||||
smtp inet n - y - - smtpd -v
|
smtp inet n - y - - smtpd -v
|
||||||
{% else %}
|
{%- else %}
|
||||||
smtp inet n - y - - smtpd
|
smtp inet n - y - - smtpd
|
||||||
{% endif %}
|
{%- endif %}
|
||||||
#smtp inet n - y - 1 postscreen
|
-o smtpd_milters=unix:opendkim/opendkim.sock
|
||||||
#smtpd pass - - y - - smtpd
|
|
||||||
#dnsblog unix - - y - 0 dnsblog
|
|
||||||
#tlsproxy unix - - y - 0 tlsproxy
|
|
||||||
submission inet n - y - - smtpd
|
submission inet n - y - - smtpd
|
||||||
-o syslog_name=postfix/submission
|
-o syslog_name=postfix/submission
|
||||||
-o smtpd_tls_security_level=encrypt
|
-o smtpd_tls_security_level=encrypt
|
||||||
@@ -34,6 +31,7 @@ submission inet n - y - - smtpd
|
|||||||
-o milter_macro_daemon_name=ORIGINATING
|
-o milter_macro_daemon_name=ORIGINATING
|
||||||
-o smtpd_client_connection_count_limit=1000
|
-o smtpd_client_connection_count_limit=1000
|
||||||
-o smtpd_proxy_filter=127.0.0.1:{{ config.filtermail_smtp_port }}
|
-o smtpd_proxy_filter=127.0.0.1:{{ config.filtermail_smtp_port }}
|
||||||
|
-o cleanup_service_name=authclean
|
||||||
smtps inet n - y - - smtpd
|
smtps inet n - y - - smtpd
|
||||||
-o syslog_name=postfix/smtps
|
-o syslog_name=postfix/smtps
|
||||||
-o smtpd_tls_wrappermode=yes
|
-o smtpd_tls_wrappermode=yes
|
||||||
@@ -50,6 +48,7 @@ smtps inet n - y - - smtpd
|
|||||||
-o smtpd_client_connection_count_limit=1000
|
-o smtpd_client_connection_count_limit=1000
|
||||||
-o milter_macro_daemon_name=ORIGINATING
|
-o milter_macro_daemon_name=ORIGINATING
|
||||||
-o smtpd_proxy_filter=127.0.0.1:{{ config.filtermail_smtp_port }}
|
-o smtpd_proxy_filter=127.0.0.1:{{ config.filtermail_smtp_port }}
|
||||||
|
-o cleanup_service_name=authclean
|
||||||
#628 inet n - y - - qmqpd
|
#628 inet n - y - - qmqpd
|
||||||
pickup unix n - y 60 1 pickup
|
pickup unix n - y 60 1 pickup
|
||||||
cleanup unix n - y - 0 cleanup
|
cleanup unix n - y - 0 cleanup
|
||||||
@@ -80,3 +79,14 @@ filter unix - n n - - lmtp
|
|||||||
# Local SMTP server for reinjecting filered mail.
|
# Local SMTP server for reinjecting filered mail.
|
||||||
localhost:{{ config.postfix_reinject_port }} inet n - n - 10 smtpd
|
localhost:{{ config.postfix_reinject_port }} inet n - n - 10 smtpd
|
||||||
-o syslog_name=postfix/reinject
|
-o syslog_name=postfix/reinject
|
||||||
|
-o smtpd_milters=unix:opendkim/opendkim.sock
|
||||||
|
-o cleanup_service_name=authclean
|
||||||
|
|
||||||
|
# Cleanup `Received` headers for authenticated mail
|
||||||
|
# to avoid leaking client IP.
|
||||||
|
#
|
||||||
|
# We do not do this for received mails
|
||||||
|
# as this will break DKIM signatures
|
||||||
|
# if `Received` header is signed.
|
||||||
|
authclean unix n - - - 0 cleanup
|
||||||
|
-o header_checks=regexp:/etc/postfix/submission_header_cleanup
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
enabled = false;
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
selector = {{ config.dkim_selector }}
|
|
||||||
use_esld = false # don't cut c1.testrun.org down to testrun.org
|
|
||||||
domain = {
|
|
||||||
{{ config.mail_domain }} {
|
|
||||||
selectors [
|
|
||||||
selector = {{ config.dkim_selector }}
|
|
||||||
path = {{ config.dkim_key_path }}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
rules {
|
|
||||||
REJECT_DKIM_SPF {
|
|
||||||
action = "reject";
|
|
||||||
# Reject if
|
|
||||||
# - R_DKIM_RJECT: DKIM reject inserted by `dkim` module.
|
|
||||||
# - R_DKIM_PERMFAIL: permanent failure inserted by `dkim` module e.g. no DKIM DNS record found.
|
|
||||||
# - No DKIM signing (R_DKIM_NA symbol inserted by `dkim` module)
|
|
||||||
#
|
|
||||||
# - SPF failure (R_SPF_FAIL)
|
|
||||||
# - SPF permanent failure, e.g. failed to resolve DNS record referenced from SPF (R_SPF_PERMFAIL)
|
|
||||||
#
|
|
||||||
# - DMARC policy failure (DMARC_POLICY_REJECT)
|
|
||||||
#
|
|
||||||
# Do not reject if:
|
|
||||||
# - R_DKIM_TEMPFAIL, it is a DNS resolution failure
|
|
||||||
# and we do not want to lose messages because of faulty network.
|
|
||||||
#
|
|
||||||
# - R_SPF_SOFTFAIL
|
|
||||||
# - R_SPF_NEUTRAL
|
|
||||||
# - R_SPF_DNSFAIL
|
|
||||||
# - R_SPF_NA
|
|
||||||
#
|
|
||||||
# - DMARC_DNSFAIL
|
|
||||||
# - DMARC_NA
|
|
||||||
# - DMARC_POLICY_SOFTFAIL
|
|
||||||
# - DMARC_POLICY_QUARANTINE
|
|
||||||
# - DMARC_BAD_POLICY
|
|
||||||
expression = "R_DKIM_REJECT | R_DKIM_PERMFAIL | R_DKIM_NA | R_SPF_FAIL | R_SPF_PERMFAIL | DMARC_POLICY_REJECT";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
filters = "dkim";
|
|
||||||
@@ -9,7 +9,7 @@ def test_gen_qr_png_data(maildomain):
|
|||||||
|
|
||||||
|
|
||||||
def test_fastcgi_working(maildomain, chatmail_config):
|
def test_fastcgi_working(maildomain, chatmail_config):
|
||||||
url = f"https://{maildomain}/cgi-bin/newemail.py"
|
url = f"https://{maildomain}/new"
|
||||||
print(url)
|
print(url)
|
||||||
res = requests.post(url)
|
res = requests.post(url)
|
||||||
assert maildomain in res.json().get("email")
|
assert maildomain in res.json().get("email")
|
||||||
@@ -18,7 +18,7 @@ def test_fastcgi_working(maildomain, chatmail_config):
|
|||||||
|
|
||||||
def test_newemail_configure(maildomain, rpc):
|
def test_newemail_configure(maildomain, rpc):
|
||||||
"""Test configuring accounts by scanning a QR code works."""
|
"""Test configuring accounts by scanning a QR code works."""
|
||||||
url = f"DCACCOUNT:https://{maildomain}/cgi-bin/newemail.py"
|
url = f"DCACCOUNT:https://{maildomain}/new"
|
||||||
for i in range(3):
|
for i in range(3):
|
||||||
account_id = rpc.add_account()
|
account_id = rpc.add_account()
|
||||||
rpc.set_config_from_qr(account_id, url)
|
rpc.set_config_from_qr(account_id, url)
|
||||||
|
|||||||
@@ -42,13 +42,25 @@ def test_reject_forged_from(cmsetup, maildata, gencreds, lp, forgeaddr):
|
|||||||
assert "500" in str(e.value)
|
assert "500" in str(e.value)
|
||||||
|
|
||||||
|
|
||||||
|
def test_authenticated_from(cmsetup, maildata):
|
||||||
|
"""Test that envelope FROM must be the same as login."""
|
||||||
|
user1, user2, user3 = cmsetup.gen_users(3)
|
||||||
|
|
||||||
|
msg = maildata("encrypted.eml", from_addr=user2.addr, to_addr=user3.addr)
|
||||||
|
with pytest.raises(smtplib.SMTPException) as e:
|
||||||
|
user1.smtp.sendmail(
|
||||||
|
from_addr=user2.addr, to_addrs=[user3.addr], msg=msg.as_string()
|
||||||
|
)
|
||||||
|
assert e.value.recipients[user3.addr][0] == 553
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"])
|
@pytest.mark.parametrize("from_addr", ["fake@example.org", "fake@testrun.org"])
|
||||||
def test_reject_missing_dkim(cmsetup, maildata, from_addr):
|
def test_reject_missing_dkim(cmsetup, maildata, from_addr):
|
||||||
"""Test that emails with missing or wrong DMARC, DKIM, and SPF entries are rejected."""
|
"""Test that emails with missing or wrong DMARC, DKIM, and SPF entries are rejected."""
|
||||||
recipient = cmsetup.gen_users(1)[0]
|
recipient = cmsetup.gen_users(1)[0]
|
||||||
msg = maildata("plain.eml", from_addr=from_addr, to_addr=recipient.addr).as_string()
|
msg = maildata("plain.eml", from_addr=from_addr, to_addr=recipient.addr).as_string()
|
||||||
with smtplib.SMTP(cmsetup.maildomain, 25) as s:
|
with smtplib.SMTP(cmsetup.maildomain, 25) as s:
|
||||||
with pytest.raises(smtplib.SMTPDataError, match="Spam message rejected"):
|
with pytest.raises(smtplib.SMTPDataError, match="No valid DKIM signature"):
|
||||||
s.sendmail(from_addr=from_addr, to_addrs=recipient.addr, msg=msg)
|
s.sendmail(from_addr=from_addr, to_addrs=recipient.addr, msg=msg)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -136,3 +136,15 @@ def test_hide_senders_ip_address(cmfactory):
|
|||||||
user2.direct_imap.select_folder("Inbox")
|
user2.direct_imap.select_folder("Inbox")
|
||||||
msg = user2.direct_imap.get_all_messages()[0]
|
msg = user2.direct_imap.get_all_messages()[0]
|
||||||
assert public_ip not in msg.obj.as_string()
|
assert public_ip not in msg.obj.as_string()
|
||||||
|
|
||||||
|
|
||||||
|
def test_echobot(cmfactory, chatmail_config, lp):
|
||||||
|
ac = cmfactory.get_online_accounts(1)[0]
|
||||||
|
|
||||||
|
lp.sec(f"Send message to echo@{chatmail_config.mail_domain}")
|
||||||
|
chat = ac.create_chat(f'echo@{chatmail_config.mail_domain}')
|
||||||
|
text = "hi, I hope you text me back"
|
||||||
|
chat.send_text(text)
|
||||||
|
lp.sec("Wait for reply from echobot")
|
||||||
|
reply = ac.wait_next_incoming_message()
|
||||||
|
assert reply.text == text
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
python3 -m venv venv
|
python3 -m venv --upgrade-deps venv
|
||||||
|
|
||||||
venv/bin/pip install -e chatmaild
|
if [ -z ${SOCKS5_PROXY+x} ]; then
|
||||||
venv/bin/pip install -e cmdeploy
|
venv/bin/pip install -e chatmaild
|
||||||
|
venv/bin/pip install -e cmdeploy
|
||||||
|
else
|
||||||
|
venv/bin/pip install --proxy socks5://$SOCKS5_PROXY -e chatmaild
|
||||||
|
venv/bin/pip install --proxy socks5://$SOCKS5_PROXY -e cmdeploy
|
||||||
|
fi
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Welcome to instant, interoperable and [privacy-preserving](privacy.html) messagi
|
|||||||
|
|
||||||
👉 **Tap** or scan this QR code to get a random `@{{config.mail_domain}}` e-mail address
|
👉 **Tap** or scan this QR code to get a random `@{{config.mail_domain}}` e-mail address
|
||||||
|
|
||||||
<a href="DCACCOUNT:https://{{ config.mail_domain }}/cgi-bin/newemail.py">
|
<a href="DCACCOUNT:https://{{ config.mail_domain }}/new">
|
||||||
<img width=300 style="float: none;" src="qr-chatmail-invite-{{config.mail_domain}}.png" /></a>
|
<img width=300 style="float: none;" src="qr-chatmail-invite-{{config.mail_domain}}.png" /></a>
|
||||||
|
|
||||||
🐣 **Choose** your Avatar and Name
|
🐣 **Choose** your Avatar and Name
|
||||||
|
|||||||
Reference in New Issue
Block a user