DKIMで検証はするけど署名せずにメール送信してしまう問題を解決
自宅サーバーを移行する際に Postfix で DKIM の設定をしました。詳しくは以下の記事に記載しています。
この時はリレーサーバー上で署名するものだと思っていたし、SPF のみでも送信できたので特に問題視していませんでしたが、最近、hotmail.com 宛てにメールが送れないことがあり、調べたら SPF、DKIM、DMARC すべてパスする必要があるとのことで再調査しました。
調査の結果、DKIM の署名(DKIM-Signature ヘッダ)は自宅サーバーで付与し、リレーサーバーではそのままスルーするというのが正しいようです。というのも送信するメールが tyd4.com ドメインのメールアドレスのため、リレーサーバーではそのドメインの秘密鍵を持っていないからです。そらそうやね。
で、なんで自宅サーバーでは署名しないのかを調べました。
基本的には Postfix の main.cf に smtpd_milters などを設定しており、OpenDKIM とのやり取りをやってくれていて、受信メールの検証結果は /etc/mail.log に出力されていました。でも署名はしてくれない、という現象です。
OpenDKIM の設定があやしいと思い、/etc/opendkim.conf を見ました。
# Signing domain, selector, and key (required). For example, perform signing
# for domain "example.com" with selector "2020" (2020._domainkey.example.com),
# using the private key stored in /etc/dkimkeys/example.private. More granular
# setup options can be found in /usr/share/doc/opendkim/README.opendkim.
#Domain example.com
#Selector 2020
#KeyFile /etc/dkimkeys/example.private
こんなかんじで秘密鍵の指定などなく、署名するのに必要な情報がないのは一目瞭然でした。opendkim.conf を旧サーバーからコピーし忘れていたようです。
/etc/opendkim/ は旧サーバーからコピーしたので調べてみます。
$ ls -F
key.table keys/ signing.table trusted.hosts
それっぽいのが残っています。
最初にDKIMを設定したときの記事に、参考にしたサイトが残っていましたので、署名に必要な追加項目をman opendkim.conf で調べてみました。
KeyTable (dataset)
Gives the location of a file mapping key names to signing keys.
:
SigningTable (dataset)
Defines a table used to select one or more signatures to apply to
a message based on the address found in the From: header field.
:
InternalHosts (dataset)
Identifies a set internal hosts whose mail should be signed
rather than verified.
:
ExternalIgnoreList (dataset)
Identifies a set of "external" hosts that may send mail through
the server as one of the signing domains without credentials as
such. This has the effect of suppressing the "external host
(hostname) tried to send mail as (domain)" log messages.
:
ExternalIgnoreList はログの抑制だけで、必須なのは3つだけのようです。
ということで、そのほかにも有効そうなのを /etc/opendkim.conf の最後に追加しました。
Mode sv
SubDomains no
AutoRestart yes
AutoRestartRate 10/1M
Background yes
DNSTimeout 5
SignatureAlgorithm rsa-sha256
KeyTable refile:/etc/opendkim/key.table
SigningTable refile:/etc/opendkim/signing.table
InternalHosts /etc/opendkim/trusted.hosts
ExternalIgnoreList /etc/opendkim/trusted.hosts
OpenDKIM と Postfix を再起動。
$ sudo systemctl restart opendkim
$ sudo systemctl restart postfix
メールを送信したら無事 DKIM の署名付きで hotmail.com に届きました。やれやれ。
