-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add MTA-STS verification #1556
Closed
Closed
Add MTA-STS verification #1556
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
aaaa92e
Add MTA-STS verification
ctrl-i 5af89a2
Restart postfix after edits
ctrl-i 4968f3d
Use get_mail_domains instead of get_dns_zones
ctrl-i 752cf70
Move MTA-STS setup from web.sh to mail-postfix.sh
ctrl-i 0397c3f
Ensure /var/lib/mailinabox/ exists before writing into it
ctrl-i f71bd61
Fixed nologin location
ctrl-i 15a827d
Fixed hostname in MTA-STS policy creation
ctrl-i bbeb083
Fixed missing = in smtp_tls_policy_maps
ctrl-i dbec391
Use hide_output on commands that may output to stdout
ctrl-i 67c084c
Check if mta-sts user exists before adding
ctrl-i 5cb6fcc
Altered wording on the MTA-STS description
ctrl-i 6f05788
Removed hide_output from mkdir
ctrl-i f7de8eb
Altered text about the policy creation
ctrl-i 3c3bc5a
Added decription as to what postfix-mta-sts-resolver does
ctrl-i 661f820
Increased max_age to 10368000 (120 days)
ctrl-i 3089210
Added check for MTA-STS service
ctrl-i File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,7 +102,7 @@ tools/editconf.py /etc/postfix/master.cf -s -w \ | |
# Install the `outgoing_mail_header_filters` file required by the new 'authclean' service. | ||
cp conf/postfix_outgoing_mail_header_filters /etc/postfix/outgoing_mail_header_filters | ||
|
||
# Modify the `outgoing_mail_header_filters` file to use the local machine name and ip | ||
# Modify the `outgoing_mail_header_filters` file to use the local machine name and ip | ||
# on the first received header line. This may help reduce the spam score of email by | ||
# removing the 127.0.0.1 reference. | ||
sed -i "s/PRIMARY_HOSTNAME/$PRIMARY_HOSTNAME/" /etc/postfix/outgoing_mail_header_filters | ||
|
@@ -215,6 +215,88 @@ tools/editconf.py /etc/default/postgrey \ | |
tools/editconf.py /etc/postfix/main.cf \ | ||
message_size_limit=134217728 | ||
|
||
# ### MTA-STS - SMTP Mail Transfer Agent Strict Transport Security - SETUP | ||
# See: https://github.com/mail-in-a-box/mailinabox/pull/1556 | ||
# | ||
# create the MTA-STS policy; this is used to announce the local MTA-STS | ||
# policy to senders and the file is served by nginx on mta-sts subdomains at | ||
# https://example.com/.well-known/mta-sts.txt | ||
mkdir -p /var/lib/mailinabox/ | ||
cat > /var/lib/mailinabox/mta-sts.txt << EOF | ||
version: STSv1 | ||
mode: enforce | ||
mx: $PRIMARY_HOSTNAME | ||
max_age: 10368000 | ||
EOF | ||
chmod a+r /var/lib/mailinabox/mta-sts.txt | ||
|
||
# install the postfix MTA-STS resolver. the MTA-STS resolver service is | ||
# used by Postfix to ensure outgoing mail uses TLS when the recipient | ||
# announces MTA-STS. | ||
hide_output /usr/bin/pip3 install postfix-mta-sts-resolver | ||
# add a user to use solely for MTA-STS resolution | ||
id -u mta-sts &>/dev/null || useradd -c "Daemon for MTA-STS policy checks" mta-sts -s /usr/sbin/nologin | ||
# create systemd services for MTA-STS | ||
cat > /etc/systemd/system/[email protected] << EOF | ||
[Unit] | ||
Description=Postfix MTA STS daemon instance | ||
After=syslog.target network.target | ||
|
||
[Service] | ||
Type=notify | ||
User=mta-sts | ||
Group=mta-sts | ||
ExecStart=/usr/local/bin/mta-sts-daemon | ||
Restart=always | ||
KillMode=process | ||
TimeoutStartSec=10 | ||
TimeoutStopSec=30 | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
cat > /etc/systemd/system/postfix-mta-sts.service << EOF | ||
[Unit] | ||
Description=Postfix MTA STS daemon | ||
After=syslog.target network.target | ||
|
||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=yes | ||
ExecStart=/bin/systemctl start [email protected] | ||
ExecReload=/bin/systemctl start [email protected] ; /bin/systemctl restart [email protected] ; /bin/systemctl stop [email protected] | ||
ExecStop=/bin/systemctl stop [email protected] | ||
|
||
[Install] | ||
WantedBy=multi-user.target | ||
EOF | ||
|
||
# configure the MTA-STS daemon for postfix | ||
cat > /etc/postfix/mta-sts-daemon.yml << EOF | ||
host: 127.0.0.1 | ||
ctrl-i marked this conversation as resolved.
Show resolved
Hide resolved
|
||
port: 8461 | ||
cache: | ||
type: internal | ||
options: | ||
cache_size: 10000 | ||
default_zone: | ||
strict_testing: true | ||
timeout: 4 | ||
zones: | ||
myzone: | ||
strict_testing: false | ||
timeout: 4 | ||
EOF | ||
|
||
# add postfix configuration | ||
tools/editconf.py /etc/postfix/main.cf \ | ||
smtp_tls_policy_maps=socketmap:inet:127.0.0.1:8461:postfix | ||
|
||
# enable and start the MTA-STS service | ||
hide_output /bin/systemctl enable postfix-mta-sts.service | ||
hide_output /bin/systemctl start postfix-mta-sts.service | ||
|
||
# Allow the two SMTP ports in the firewall. | ||
|
||
ufw_allow smtp | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be altered to include an upgrade parameter if postfix-mta-sts-resolver is already installed?
hide_output /usr/bin/pip3 install -U postfix-mta-sts-resolver