Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upPart 1 : OpenSMTPD #3
Comments
wesley974
added
the
help wanted
label
May 28, 2018
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 28, 2018
Contributor
Reading the OpenSMTPD Faq, we need to create a system user named vmail to handle multiple domains.
|
Reading the OpenSMTPD Faq, we need to create a system user named vmail to handle multiple domains. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 28, 2018
Contributor
Should we create some code?
Here on github? Fork and create pull request?
|
Should we create some code? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 29, 2018
Contributor
We can discuss together and share here the following:
- prerequisites
- requirements
- all the steps to configure OpenSMTPD
- make some tests
- write a script
And then suggest a pull request.
|
We can discuss together and share here the following:
And then suggest a pull request. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 29, 2018
Contributor
Because we configure the virtual users in /etc/mail/passwd we need to create only one single system user: vmail.
All virtual deliveries occur under the same user: vmail
This user don´t login, so we give him /sbin/nologin vmail as login shell
So we have to create it like in the FAQ:
# useradd -m -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
I would check for existance first and only run useradd if it not exists:
# getent passwd vmail || useradd -m -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
|
Because we configure the virtual users in So we have to create it like in the FAQ: I would check for existance first and only run useradd if it not exists: |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 29, 2018
Contributor
I think that new created files should not accessible by others, so maybe we need to give the vmail user a umask 007.
So it makes sense to create a loginclass for the vmail user in /etc/login.conf:
# loginclass for vmail
#
vmail:\
:umask=007:\
...
But before create a loginclass it´s better to check if it already exists:
getcap -f /etc/login.conf vmail
and create the user with useradd´s L flag:
# getent passwd vmail || useradd -L vmail -m -g =uid -c "Virtual Mail" -d /var/vmail -s /sbin/nologin vmail
|
I think that new created files should not accessible by others, so maybe we need to give the
But before create a loginclass it´s better to check if it already exists: and create the user with useradd´s |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 29, 2018
Contributor
But before create a loginclass it´s better to check if it already exists:
But wait... maybe someone uses a hashed database and then we need to rehash /etc/login.conf with # cap_mkdb /etc/login.conf after creation of the new loginclass.
So we need to check if there exists a hashed database first: if [ -r /etc/login.conf.db ]; then ....
But wait... maybe someone uses a hashed database and then we need to rehash |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 29, 2018
Contributor
Regarding the prerequisites, you ll need:
- at least a registered domain name with these DNS records set: MX, SPF, DMARC, CAA and DKIM
|
Regarding the prerequisites, you ll need:
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 30, 2018
Contributor
The requirements :
- A vmail user to handle the virtual domains and users
- Install the package opensmtpd-extras to be able to authenticate virtual users with a passwd file
- Configuration file for OpenSMTPD: /etc/mail/smtpd.conf
- Let's Encrypt certificate for SSL/TLS
- Manage the aliases table using the file: /etc/mail/aliases
- Manage the domains table using the file: /etc/mail/domains
- Manage the passwd table using the file: /etc/mail/passwd
- Manage the virtuals table using the file: /etc/mail/virtuals
- Manage the blacklist table using the file: /etc/mail/blacklist
Let's configure all of this, make some tests, and finally write a script opensmtpd located in a folder scripts, configuration file will come into a folder named conf.
|
The requirements :
Let's configure all of this, make some tests, and finally write a script |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 30, 2018
Contributor
at least a registered domain name with these DNS records set: MX, SPF, DMARC, CAA and DKIM
For a mailserver a MX and an A record is needed
MX -> FQDN
A -> maps the name to an ip
for proper smtp one should setup an PTR record additionally
SPF, DMARC, CAA and DKIM records are optionally (nice to have)
For a mailserver a MX and an A record is needed for proper smtp one should setup an PTR record additionally SPF, DMARC, CAA and DKIM records are optionally (nice to have) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
aminb
May 30, 2018
While MX and A records are the bare minimum for a mailserver, I'd say PTR, SPF, and DKIM are very much essential these days if you want to have reliable delivery to insert big corp name mail users.
aminb
commented
May 30, 2018
|
While MX and A records are the bare minimum for a mailserver, I'd say PTR, SPF, and DKIM are very much essential these days if you want to have reliable delivery to |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Clearly you need all of these dns records. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
May 31, 2018
Contributor
I wouldn´t argue against setting al of them for a real world mailserver.
I wanted to document that SPF, DMARC, DKIM and PTR are not required to act as a mailserver.
But definitely we need them :-/
|
I wouldn´t argue against setting al of them for a real world mailserver. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 31, 2018
Contributor
You need to be familiar with these terms :
| Name | Description | Port (tcp) |
|---|---|---|
| SMTP | Simple Mail Transfert Protocol | 25 |
| SMTP | Mail Submission port | 587 |
| MTA | Mail Transfert Agent (OpenSMTPD) | |
| MUA | Mail User Agent (Outlook, Thunderbird ... ) | |
| MDA | Mail Delivery Agent (Dovecot) | |
| Mbox | mail storage format | |
| Maildir | mail storage format | |
| POP3 | mail access protocol (Post Office Protocol) | 110 |
| POP3S | mail access protocol (Post Office Protocol over SSL/TLS) | 995 |
| IMAP | mail access protocol (Internet Mail Access Protocol) | 143 |
| IMAPS | mail access protocol (Internet Mail Access Protocol over SSL/TLS) | 993 |
|
You need to be familiar with these terms :
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
May 31, 2018
Contributor
The main script will be named deploy.
./bin/deploy without parameters will install all the box.
In case of maintenance, It will be possible to reinstall each module like:
./bin/deploy opensmtpd
./bin/deploy letsencrypt
./bin/deploy dovecot
...
with an option -d for debug
./bin/deploy -d
./bin/deploy -d opensmtpd
|
The main script will be named
with an option
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 1, 2018
Contributor
I just pushed bin/deploy and lib/opensmtpd ; work in progress.
Just run ./bin/deploy or ./bin/deploy -d
|
I just pushed |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 5, 2018
Contributor
Installer is now ready.
#!/bin/ksh
# exit immediately if a command exits with a non-zero status
set -e
# set OpenBSD version supported without the dot
readonly VER=63
# handle errors
err()
{
echo "${1}" >&2 && return "${2:-1}"
}
# install all libraries (opensmtpd, dovecot ...)
install_all()
{
for i in ./lib/* ; do
. "$i"
"${i#*/*/}"_lib
done
}
usage()
{
err "Usage: ${0##*/} [-d] [library]"
}
# you need 'root' user for this script!
(($(id -u) != 0)) && err "${0##*/}: need root privileges"
# are you using the good release ?
(($(uname -r | tr -d .) != VER)) && err "${0##*/}: this release is not supported"
# the syntax
while getopts :d opt; do
case ${opt} in
# Debug mode when -d is present
d) set -x && readonly DEBUG=1;;
*) usage;;
esac
done
# we remove an option
shift $((OPTIND - 1))
# only one library allowed, or empty library
(($# > 1)) && usage
# if no library mentioned we install all, otherwise, we just install the library present in $1
if [[ -z $1 ]]; then
install_all
else
# does this library exist ?
[[ ! -f ./lib/$1 ]] && err "${0##*/}: this library doesn't exist"
# install the unique library
. ./lib/$1
$1_lib
fi
You can use it like this : ./bin/deploy [-d] [library]
Let's focus now on the OpenSMTPD part !
|
Installer is now ready.
You can use it like this : Let's focus now on the OpenSMTPD part ! |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
stevelord
Jun 11, 2018
Is there a specific reason for linking python 2.7 to python instead of python 3 in lib/opensmtpd? Also, is this a requirement for OpenSMTPd, or would this be better served elsewhere? (Just thinking about avoiding the presence of magic)
stevelord
commented
Jun 11, 2018
•
|
Is there a specific reason for linking python 2.7 to python instead of python 3 in lib/opensmtpd? Also, is this a requirement for OpenSMTPd, or would this be better served elsewhere? (Just thinking about avoiding the presence of magic) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
I added the linking just for best practice. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
stevelord
Jun 12, 2018
If it's not used it might be better to leave it out. You don't know if someone's going to run python 2 or python 3 only scripts and get compatibility issues.
If a particular python is used we could specify python 3 in the shebang line.
stevelord
commented
Jun 12, 2018
|
If it's not used it might be better to leave it out. You don't know if someone's going to run python 2 or python 3 only scripts and get compatibility issues. If a particular python is used we could specify python 3 in the shebang line. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 13, 2018
Contributor
We are going to start at the beginning.
A first simple configuration of smtpd.conf to handle local mail :
# Tables
table aliases file:/etc/mail/aliases
# Accept only internal mail
listen on lo0 hostname localhost
# Deliver to local mbox
accept for local alias <aliases> deliver to mbox
# Accept to send anywhere
accept from local for any relay
To test :
# Send to local and check you get it
mail -s test01 root
hello
.
mail
# You ll receive this message, root has a .forward* (if you have added a user at installation)
# Send to external address
mail -s test02 your_email_address
hello
.
|
We are going to start at the beginning.
To test :
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 13, 2018
Contributor
Do you think we need that ?
queue compression Enable transparent compression of envelopes and messages. The only supported algorithm at the moment is gzip. Envelopes and messages may be inspected using the smtpctl(8) or gzcat(1) utilities. queue encryption [key key] Enable transparent encryption of envelopes and messages. key must be a 16-byte random key in hexadecimal representation. It can be obtained using the openssl(1) utility as follow:
$ openssl rand -hex 16
|
Do you think we need that ?
|
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
deksar
commented
Jun 13, 2018
|
Compression&encryption always good to use, imho. Safety (y) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mhekeler
Jun 13, 2018
Contributor
Although I basically agree with @deksar I would say that in this sutuation we don´t need to encrypt the queue.
Encrypting (and also compression) will add an extra layer of complexity (but of course also an extra layer of security).
I won´t argue against encryption here but I am not sure if encrypting the queue is a benefit ?!?
|
Although I basically agree with @deksar I would say that in this sutuation we don´t need to encrypt the queue. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
stevelord
Jun 13, 2018
If it works, lets use queue compression and encryption, but if it interferes with debugging problems, perhaps look to add that when we know the complete setup is working?
stevelord
commented
Jun 13, 2018
|
If it works, lets use queue compression and encryption, but if it interferes with debugging problems, perhaps look to add that when we know the complete setup is working? |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 13, 2018
Contributor
I think final user will be able to add this (queue compression & encryption) manually.
|
I think final user will be able to add this (queue compression & encryption) manually. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
wesley974
Jun 13, 2018
Contributor
Some useful commands :
# Check your smtpd.conf
smtpd -n
# Get the stats
doas smtpctl show stats
# View the queue
doas smtpctl show queue # or mailq
# Get details on a specific message in the queue
doas smtpctl show message 025a5c7b6cc771cc
# Force the queue distribution
doas smtpctl schedule all
# Remove all messages in the queue
doas smtpctl remove all
|
Some useful commands :
|
wesley974 commentedMay 28, 2018
•
edited
Edited 1 time
-
wesley974
edited May 28, 2018 (most recent)
Let's start to configure OpenSMTPD!