mirror of
https://github.com/chatmail/relay.git
synced 2026-05-10 16:04:37 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d5c3fb1eca | ||
|
|
bcf2fdb5d0 | ||
|
|
77a6f49c9b | ||
|
|
99630e4d1b | ||
|
|
2f8199a7c6 | ||
|
|
4eeead2826 | ||
|
|
0d890274fd |
@@ -19,13 +19,8 @@ jobs:
|
|||||||
environment:
|
environment:
|
||||||
name: staging-ipv4.testrun.org
|
name: staging-ipv4.testrun.org
|
||||||
url: https://staging-ipv4.testrun.org/
|
url: https://staging-ipv4.testrun.org/
|
||||||
concurrency:
|
concurrency: staging-ipv4.testrun.org
|
||||||
group: ci-ipv4-${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: ${{ !contains(github.ref, '$GITHUB_REF') }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: jsok/serialize-workflow-action@515cd04c46d7ea7435c4a22a3b4419127afdefe9
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare SSH
|
- name: prepare SSH
|
||||||
|
|||||||
7
.github/workflows/test-and-deploy.yaml
vendored
7
.github/workflows/test-and-deploy.yaml
vendored
@@ -19,13 +19,8 @@ jobs:
|
|||||||
environment:
|
environment:
|
||||||
name: staging2.testrun.org
|
name: staging2.testrun.org
|
||||||
url: https://staging2.testrun.org/
|
url: https://staging2.testrun.org/
|
||||||
concurrency:
|
concurrency: staging2.testrun.org
|
||||||
group: ci-${{ github.workflow }}-${{ github.ref }}
|
|
||||||
cancel-in-progress: ${{ !contains(github.ref, '$GITHUB_REF') }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: jsok/serialize-workflow-action@515cd04c46d7ea7435c4a22a3b4419127afdefe9
|
|
||||||
with:
|
|
||||||
github-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: prepare SSH
|
- name: prepare SSH
|
||||||
|
|||||||
@@ -307,12 +307,9 @@ class IncomingBeforeQueueHandler:
|
|||||||
return error
|
return error
|
||||||
log_info("re-injecting the mail that passed checks")
|
log_info("re-injecting the mail that passed checks")
|
||||||
|
|
||||||
# the smtp daemon on reinject_port_incoming gives it to dkim milter
|
|
||||||
# which looks at source address to determine whether to verify or sign
|
|
||||||
client = SMTPClient(
|
client = SMTPClient(
|
||||||
"localhost",
|
"localhost",
|
||||||
self.config.postfix_reinject_port_incoming,
|
self.config.postfix_reinject_port_incoming,
|
||||||
source_address=("127.0.0.2", 0),
|
|
||||||
)
|
)
|
||||||
client.sendmail(
|
client.sendmail(
|
||||||
envelope.mail_from, envelope.rcpt_tos, envelope.original_content
|
envelope.mail_from, envelope.rcpt_tos, envelope.original_content
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ mail_domain = {mail_domain}
|
|||||||
max_user_send_per_minute = 60
|
max_user_send_per_minute = 60
|
||||||
|
|
||||||
# maximum mailbox size of a chatmail address
|
# maximum mailbox size of a chatmail address
|
||||||
max_mailbox_size = 100M
|
max_mailbox_size = 500M
|
||||||
|
|
||||||
# maximum message size for an e-mail in bytes
|
# maximum message size for an e-mail in bytes
|
||||||
max_message_size = 31457280
|
max_message_size = 31457280
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ def test_read_config_testrun(make_config):
|
|||||||
assert config.filtermail_smtp_port == 10080
|
assert config.filtermail_smtp_port == 10080
|
||||||
assert config.postfix_reinject_port == 10025
|
assert config.postfix_reinject_port == 10025
|
||||||
assert config.max_user_send_per_minute == 60
|
assert config.max_user_send_per_minute == 60
|
||||||
assert config.max_mailbox_size == "100M"
|
assert config.max_mailbox_size == "500M"
|
||||||
assert config.delete_mails_after == "20"
|
assert config.delete_mails_after == "20"
|
||||||
assert config.delete_large_after == "7"
|
assert config.delete_large_after == "7"
|
||||||
assert config.username_min_length == 9
|
assert config.username_min_length == 9
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ stream {
|
|||||||
default 127.0.0.1:8443;
|
default 127.0.0.1:8443;
|
||||||
~\bsmtp\b 127.0.0.1:465;
|
~\bsmtp\b 127.0.0.1:465;
|
||||||
~\bimap\b 127.0.0.1:993;
|
~\bimap\b 127.0.0.1:993;
|
||||||
|
~\bssh\b 127.0.0.1:22;
|
||||||
}
|
}
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
if odkim.internal_ip(ctx) == 1 then
|
mtaname = odkim.get_mtasymbol(ctx, "{daemon_name}")
|
||||||
|
if mtaname == "ORIGINATING" then
|
||||||
-- Outgoing message will be signed,
|
-- Outgoing message will be signed,
|
||||||
-- no need to look for signatures.
|
-- no need to look for signatures.
|
||||||
return nil
|
return nil
|
||||||
|
|||||||
@@ -65,3 +65,9 @@ PidFile /run/opendkim/opendkim.pid
|
|||||||
# 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
|
||||||
|
|
||||||
|
# Sign messages when `-o milter_macro_daemon_name=ORIGINATING` is set.
|
||||||
|
MTA ORIGINATING
|
||||||
|
|
||||||
|
# No hosts are treated as internal, ORIGINATING daemon name should be set explicitly.
|
||||||
|
InternalHosts -
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ submission inet n - y - 5000 smtpd
|
|||||||
-o smtpd_sender_restrictions=$mua_sender_restrictions
|
-o smtpd_sender_restrictions=$mua_sender_restrictions
|
||||||
-o smtpd_recipient_restrictions=
|
-o smtpd_recipient_restrictions=
|
||||||
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
||||||
-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 }}
|
||||||
smtps inet n - y - 5000 smtpd
|
smtps inet n - y - 5000 smtpd
|
||||||
@@ -49,7 +48,6 @@ smtps inet n - y - 5000 smtpd
|
|||||||
-o smtpd_recipient_restrictions=
|
-o smtpd_recipient_restrictions=
|
||||||
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
||||||
-o smtpd_client_connection_count_limit=1000
|
-o smtpd_client_connection_count_limit=1000
|
||||||
-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 }}
|
||||||
#628 inet n - y - - qmqpd
|
#628 inet n - y - - qmqpd
|
||||||
pickup unix n - y 60 1 pickup
|
pickup unix n - y 60 1 pickup
|
||||||
@@ -81,6 +79,7 @@ filter unix - n n - - lmtp
|
|||||||
# Local SMTP server for reinjecting outgoing filtered mail.
|
# Local SMTP server for reinjecting outgoing filtered mail.
|
||||||
127.0.0.1:{{ config.postfix_reinject_port }} inet n - n - 100 smtpd
|
127.0.0.1:{{ config.postfix_reinject_port }} inet n - n - 100 smtpd
|
||||||
-o syslog_name=postfix/reinject
|
-o syslog_name=postfix/reinject
|
||||||
|
-o milter_macro_daemon_name=ORIGINATING
|
||||||
-o smtpd_milters=unix:opendkim/opendkim.sock
|
-o smtpd_milters=unix:opendkim/opendkim.sock
|
||||||
-o cleanup_service_name=authclean
|
-o cleanup_service_name=authclean
|
||||||
|
|
||||||
|
|||||||
@@ -40,10 +40,10 @@ steps. Please substitute it with your own domain.
|
|||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
chat.example.com. 3600 IN A 198.51.100.5
|
chat.example.org. 3600 IN A 198.51.100.5
|
||||||
chat.example.com. 3600 IN AAAA 2001:db8::5
|
chat.example.org. 3600 IN AAAA 2001:db8::5
|
||||||
www.chat.example.com. 3600 IN CNAME chat.example.com.
|
www.chat.example.org. 3600 IN CNAME chat.example.org.
|
||||||
mta-sts.chat.example.com. 3600 IN CNAME chat.example.com.
|
mta-sts.chat.example.org. 3600 IN CNAME chat.example.org.
|
||||||
|
|
||||||
2. On your local PC, clone the repository and bootstrap the Python
|
2. On your local PC, clone the repository and bootstrap the Python
|
||||||
virtualenv.
|
virtualenv.
|
||||||
|
|||||||
@@ -1,72 +1,98 @@
|
|||||||
|
|
||||||
Migrating to a new host
|
Migrating to a new machine
|
||||||
-----------------------
|
===========================
|
||||||
|
|
||||||
If you want to migrate chatmail relay from an old machine to a new
|
This migration tutorial provides a step-wise approach
|
||||||
machine, you can use these steps. They were tested with a Linux laptop;
|
to safely migrate a chatmail relay from one remote machine to another.
|
||||||
you might need to adjust some of the steps to your environment.
|
|
||||||
|
|
||||||
Let’s assume that your ``mail_domain`` is ``mail.example.org``, all
|
Preliminary notes and assumptions
|
||||||
involved machines run Debian 12, your old site’s IP address is
|
---------------------------------
|
||||||
``13.37.13.37``, and your new site’s IP address is ``13.12.23.42``.
|
|
||||||
|
|
||||||
Note, you should lower the TTLs of your DNS records to a value such as
|
- If the migration is a planned move,
|
||||||
300 (5 minutes) so the migration happens as smoothly as possible.
|
it's recommended to lower the Time To Live (TTL) of your DNS records to a value such as 300 (5 minutes),
|
||||||
|
at best much earlier than the actual planned migration.
|
||||||
|
This speeds up propagation of DNS changes in the Internet after the migration is complete.
|
||||||
|
|
||||||
During the guide you might get a warning about changed SSH Host keys; in
|
- The migration steps were tested with a Linux laptop; you might need to adjust some of the steps to your local environment.
|
||||||
this case, just run ``ssh-keygen -R "mail.example.org"`` as recommended.
|
|
||||||
|
|
||||||
1. First, disable mail services on the old site.
|
- Your ``mail_domain`` is ``mail.example.org``.
|
||||||
|
|
||||||
|
- All remote machines run Debian 12.
|
||||||
|
|
||||||
|
- The old site’s IP version 4 address is ``$OLD_IP4``.
|
||||||
|
|
||||||
|
- The new site’s IP addresses are ``$NEW_IP4`` and ``$NEW_IPV6``.
|
||||||
|
|
||||||
|
|
||||||
|
The six steps to migrate
|
||||||
|
------------------------
|
||||||
|
|
||||||
|
Note that during some of the following steps you might get a warning about changed SSH Host keys;
|
||||||
|
in this case, just run ``ssh-keygen -R "mail.example.org"`` as recommended.
|
||||||
|
|
||||||
|
|
||||||
|
1. **Initially transfer mailboxes from old to new site.**
|
||||||
|
|
||||||
|
Login to old site, forwarding your ssh-agent with ``ssh -A``
|
||||||
|
to allow using ssh to directly copy files from old to new site.
|
||||||
|
::
|
||||||
|
|
||||||
|
ssh -A root@$OLD_IP4
|
||||||
|
tar c /home/vmail/mail | ssh root@$NEW_IP4 "tar x -C /"
|
||||||
|
|
||||||
|
|
||||||
|
2. **Pre-configure the new site but keep it inactive until step 6**
|
||||||
|
::
|
||||||
|
|
||||||
|
CMDEPLOY_STAGES=install,configure scripts/cmdeploy run --ssh-host $NEW_IP4
|
||||||
|
|
||||||
|
|
||||||
|
3. **It's getting serious: disable mail services on the old site.**
|
||||||
|
Users will not be able to send or receive messages until all steps are completed.
|
||||||
|
Other relays and mail servers will retry delivering messages from time to time,
|
||||||
|
so nothing is lost for users.
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
cmdeploy run --disable-mail --ssh-host 13.37.13.37
|
scripts/cmdeploy run --disable-mail --ssh-host $OLD_IP4
|
||||||
|
|
||||||
Now your users will notice the migration and will not be able to send
|
|
||||||
or receive messages until the migration is completed.
|
|
||||||
|
|
||||||
2. Now we want to copy ``/home/vmail``, ``/var/lib/acme``,
|
4. **Final synchronization of TLS/DKIM secrets, mail queues and mailboxes.**
|
||||||
``/etc/dkimkeys``, and ``/var/spool/postfix`` to
|
Again we use ssh-agent forwarding (``-A``) to allow transfering all important data directly
|
||||||
the new site. Login to the old site while forwarding your SSH agent
|
from the old to the new site.
|
||||||
so you can copy directly from the old to the new site with your SSH
|
::
|
||||||
key:
|
|
||||||
|
ssh -A root@$OLD_IP4
|
||||||
::
|
tar c /var/lib/acme /etc/dkimkeys /var/spool/postfix | ssh root@$NEW_IP4 "tar x -C /"
|
||||||
|
rsync -azH /home/vmail/mail root@$NEW_IP4:/home/vmail/
|
||||||
ssh -A root@13.37.13.37
|
|
||||||
tar c - /home/vmail/mail /var/lib/acme /etc/dkimkeys /var/spool/postfix | ssh root@13.12.23.42 "tar x -C /"
|
Login to the new site and ensure file ownerships are correctly set:
|
||||||
|
|
||||||
This transfers all addresses, the TLS certificate,
|
|
||||||
and DKIM keys (so DKIM DNS record remains valid).
|
|
||||||
It also preserves the Postfix mail spool so any messages
|
|
||||||
pending delivery will still be delivered.
|
|
||||||
|
|
||||||
3. Install chatmail on the new machine:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
cmdeploy run --disable-mail --ssh-host 13.12.23.42
|
|
||||||
|
|
||||||
Postfix and Dovecot are disabled for now; we will enable them later.
|
|
||||||
We first need to make the new site fully operational.
|
|
||||||
|
|
||||||
4. On the new site, run the following to ensure the ownership is correct
|
|
||||||
in case UIDs/GIDs changed:
|
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
|
ssh root@$NEW_IP4
|
||||||
chown root: -R /var/lib/acme
|
chown root: -R /var/lib/acme
|
||||||
chown opendkim: -R /etc/dkimkeys
|
chown opendkim: -R /etc/dkimkeys
|
||||||
chown vmail: -R /home/vmail/mail
|
chown vmail: -R /home/vmail/mail
|
||||||
|
|
||||||
5. Now, update DNS entries.
|
|
||||||
|
|
||||||
If other MTAs try to deliver messages to your chatmail domain they
|
5. **Update the DNS entries to point to the new site.**
|
||||||
may fail intermittently, as DNS catches up with the new site settings
|
You only need to change the ``A`` and ``AAAA`` records, for example:
|
||||||
but normally will retry delivering messages for at least a week, so
|
|
||||||
messages will not be lost.
|
|
||||||
|
|
||||||
6. Finally, you can execute ``cmdeploy run --ssh-host 13.12.23.42`` to
|
::
|
||||||
turn on chatmail on the new relay. Your users will be able to use the
|
|
||||||
chatmail relay as soon as the DNS changes have propagated. Voilà!
|
mail.example.org. IN A $NEW_IP4
|
||||||
|
mail.example.org. IN AAAA $NEW_IP6
|
||||||
|
|
||||||
|
|
||||||
|
6. **Activate chatmail relay on new site.**
|
||||||
|
|
||||||
|
::
|
||||||
|
|
||||||
|
CMDEPLOY_STAGES=activate scripts/cmdeploy run --ssh-host $NEW_IP4
|
||||||
|
|
||||||
|
Voilà!
|
||||||
|
Users will be able to use the relay as soon as the DNS changes have propagated.
|
||||||
|
If you have lowered the Time-to-Live for DNS records in step 1,
|
||||||
|
better use a higher value again (between 14400 and 86400 seconds) once you are sure everything works.
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user