docker-mailserver/docs/content/config/best-practices/dkim.md

103 lines
4.3 KiB
Markdown
Raw Normal View History

2021-01-27 22:10:26 +01:00
DKIM is a security measure targeting email spoofing. It is greatly recommended one activates it. See [the Wikipedia page](https://en.wikipedia.org/wiki/DomainKeys_Identified_Mail) for more details on DKIM.
2016-04-24 17:20:18 +02:00
2021-02-08 12:21:12 +01:00
#### Enabling DKIM signature
2016-04-24 17:20:18 +02:00
2021-02-08 12:21:12 +01:00
To enable DKIM signature, **you must have created at least one email account**. Once its done, just run the following command to generate the signature:
2020-05-31 05:10:32 +02:00
2021-02-08 12:21:12 +01:00
``` BASH
2021-01-27 22:17:07 +01:00
./setup.sh config dkim
2021-01-27 22:10:26 +01:00
```
2021-02-08 12:21:12 +01:00
After generating DKIM keys, you should restart the mail server. DNS edits may take a few minutes to hours to propagate. The script assumes you're being in the directory where the `config/` directory is located. The default keysize when generating the signature is 4096 bits for now. If you need to change it (e.g. your DNS provider limits the size), then provide the size as the first parameter of the command:
2018-03-03 07:39:24 +01:00
2021-02-08 12:21:12 +01:00
``` BASH
2021-01-27 22:17:07 +01:00
./setup.sh config dkim <keysize>
2021-01-27 22:10:26 +01:00
```
2016-04-24 17:49:08 +02:00
2021-01-26 17:28:40 +01:00
For LDAP systems that do not have any directly created user account you can run the following command (since `8.0.0`) to generate the signature by additionally providing the desired domain name (if you have multiple domains use the command multiple times or provide a comma-separated list of domains):
2021-02-08 12:21:12 +01:00
``` BASH
2021-01-27 22:17:07 +01:00
./setup.sh config dkim <key-size> <domain.tld>[,<domain2.tld>]
2021-01-27 22:10:26 +01:00
```
2021-01-26 17:28:40 +01:00
2021-02-08 12:21:12 +01:00
Now the keys are generated, you can configure your DNS server with DKIM signature, simply by adding a TXT record. If you have direct access to your DNS zone file, then it's only a matter of pasting the content of `config/opendkim/keys/domain.tld/mail.txt` in your `domain.tld.hosts` zone.
2018-02-06 19:57:16 +01:00
2021-02-08 12:21:12 +01:00
``` BASH
2021-01-27 22:17:07 +01:00
$ dig mail._domainkey.domain.tld TXT
---
;; ANSWER SECTION
mail._domainkey.<DOMAIN> 300 IN TXT "v=DKIM1; k=rsa; p=AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN/AZERTYUIOPQSDFGHJKLMWXCVBN"
2016-06-01 04:16:51 +02:00
```
2021-02-08 12:21:12 +01:00
#### Configuration using a web interface
1. Generate a new record of the type `TXT`.
2016-09-07 19:36:40 +02:00
2. Paste `mail._domainkey` the `Name` txt field.
2016-09-07 19:38:50 +02:00
3. In the `Target` or `Value` field fill in `v=DKIM1; k=rsa; p=AZERTYUGHJKLMWX...`.
4. In `TTL` (time to live): Time span in seconds. How long the DNS server should cache the `TXT` record.
5. Save.
2021-02-08 12:21:12 +01:00
**Note**: Sometimes the key in `config/opendkim/keys/domain.tld/mail.txt` can be on multiple lines. If so then you need to concatenate the values in the TXT record:
2020-05-31 05:10:32 +02:00
2021-02-08 12:21:12 +01:00
``` BASH
2021-01-27 22:17:07 +01:00
$ dig mail._domainkey.domain.tld TXT
---
;; ANSWER SECTION
2021-02-08 12:21:12 +01:00
mail._domainkey.<DOMAIN> 300 IN TXT "v=DKIM1; k=rsa; "
"p=AZERTYUIOPQSDF..."
2021-02-08 12:21:12 +01:00
"asdfQWERTYUIOPQSDF..."
```
2021-02-08 12:21:12 +01:00
The target (or value) field must then have all the parts together: `v=DKIM1; k=rsa; p=AZERTYUIOPQSDF...asdfQWERTYUIOPQSDF...`
2021-02-08 12:21:12 +01:00
#### Verify-only
2016-06-01 04:16:51 +02:00
2020-05-31 05:10:32 +02:00
If you want DKIM to only _verify_ incoming emails, the following version of /etc/opendkim.conf may be useful (right now there is no easy mechanism for installing it other than forking the repo):
2021-01-27 22:17:07 +01:00
``` TXT
2016-06-01 04:16:51 +02:00
# This is a simple config file verifying messages only
#LogWhy yes
Syslog yes
SyslogSuccess yes
Socket inet:12301@localhost
2016-06-01 16:00:02 +02:00
PidFile /var/run/opendkim/opendkim.pid
2016-06-01 04:16:51 +02:00
2016-06-01 15:59:50 +02:00
ReportAddress postmaster@my-domain.com
2016-06-01 04:16:51 +02:00
SendReports yes
Mode v
2016-09-07 18:37:43 +02:00
```
2021-02-08 12:21:12 +01:00
#### Debugging
2016-09-07 19:24:38 +02:00
2021-02-08 12:21:12 +01:00
- [DKIM-verifer](https://addons.mozilla.org/en-US/thunderbird/addon/dkim-verifier): A add-on for the mail client Thunderbird.
- You can debug your TXT records with the `dig` tool.
2016-09-07 19:24:38 +02:00
2021-02-08 12:21:12 +01:00
``` BASH
$ dig TXT mail._domainkey.domain.tld
---
2016-09-07 18:37:43 +02:00
; <<>> DiG 9.10.3-P4-Debian <<>> TXT mail._domainkey.domain.tld
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 39669
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;mail._domainkey.domain.tld. IN TXT
;; ANSWER SECTION:
mail._domainkey.domain.tld. 3600 IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxBSjG6RnWAdU3oOlqsdf2WC0FOUmU8uHVrzxPLW2R3yRBPGLrGO1++yy3tv6kMieWZwEBHVOdefM6uQOQsZ4brahu9lhG8sFLPX4MaKYN/NR6RK4gdjrZu+MYSdfk3THgSbNwIDAQAB"
;; Query time: 50 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Wed Sep 07 18:22:57 CEST 2016
;; MSG SIZE rcvd: 310
2018-04-12 23:25:12 +02:00
```
2021-02-08 12:21:12 +01:00
#### Switch off DKIM
2020-05-15 18:45:33 +02:00
2020-05-31 05:11:06 +02:00
Simply remove the DKIM key by recreating (not just relaunching) the mailserver container.