マルチドメイン証明書(Let’s Encrypt)

Let's Encrypt

当サイトでは複数のドメインを運用しています(動的IPアドレスはひとつ).サーバ証明書に関してそれぞれのドメインでLet’s Encryptで証明書を取得しています.WebサーバはVirtualサーバ毎に別々の証明書を利用することが可能なのですが,メールサーバとして利用しているpostfixではサーバ証明書を一つしか持てないようです(2022年7月現在).ただし,マルチドメイン証明書(ワイルドカード証明書のようなもの)というものを利用すると一つの証明書で複数ドメインを取り扱うことができそうです.

この記事では,サーバ証明書をマルチドメイン証明書に変更するまでの手順等について記載していきます.(執筆開始時点では完全に置き換えることができるかどうか不明です)

2024/04/06追記 マルチドメイン証明書で問題なく動作している。ただ2022年3月時点でpostfixはTLS SNI対応していたらしい。

マルチドメイン証明書の作成

利用中の証明書の確認

以下のコマンドで現在利用している証明書のコモンネーム(CN)を確認します.

# certbot certificates

証明書の削除

現在利用中の証明書の失効処理と削除を行います.certbot revokeで先ほど確認したCNを指定します.会話型で処理がすすみますので,質問に対してYを答えます.

# certbot revoke --cert-name xxxxxx.xx
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you like to delete the certificate(s) you just revoked, along with all
earlier and later versions of the certificate?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es (recommended)/(N)o: Y

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
The following certificate(s) are selected for deletion:

  * xxxxxx.xx

WARNING: Before continuing, ensure that the listed certificates are not being
used by any installed server software (e.g. Apache, nginx, mail servers).
Deleting a certificate that is still being used will cause the server software
to stop working. See https://certbot.org/deleting-certs for information on
deleting certificates safely.

Are you sure you want to delete the above certificate(s)?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Deleted all files relating to certificate xxxxxx.xx.
Congratulations! You have successfully revoked the certificate that was located at /etc/letsencrypt/live/xxxxxx.xx/cert.pem.
#

certbot certificatesコマンドで削除したCNの情報が表示されないこと,および /etc/letsencrypt/live の下のディレクトリが削除されていることを確認します.これを管理しているドメインすべてについて実施します.

マルチドメイン証明書の作成

マルチドメインでかつワイルドカードの証明書を作成するためには以下のようにcertbotコマンドに複数のドメインを指定するだけです.

--cert-name example1.com \
--domain example1.com \
--domain *.example1.com \
--domain example2.com \
--domain *.example2.com \

上記の例の場合,/etc/letsencrypt/live/example1.com に証明書等が作成されます.

各種アプリケーションへの組み込み

apache

証明書等へのパスがすべて以下のように同一になります.

    SSLCertificateFile /etc/letsencrypt/live/example1.com/cert.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/example1.com/privkey.pem
    SSLCertificateChainFile /etc/letsencrypt/live/example1.com/chain.pem

各バーチャルホストのSSL関係の定義体の修正を行い再起動を行います.

現在のところ,chrome(windows),firefox(windows),safari(iphone)では問題なく利用できています.

postfix

/etc/postfix/main.cf に以下の定義を行います.

### SSL/TLS Settings
smtp_tls_security_level = may
smtpd_tls_cert_file = /etc/letsencrypt/live/example1.com/fullchain.pem
smtpd_tls_key_file = /etc/letsencrypt/live/example1.com/privkey.pem
smtpd_tls_session_cache_database = btree:/var/lib/postfix/smtpd_scache
smtpd_tls_session_cache_timeout = 3600s
smtpd_tls_received_header = yes
smtpd_tls_loglevel = 1

postfixの再起動を行います.

# systemctl restart postfix

dovecot

/etc/dovecot/conf.d/10-ssl.conf に以下の定義を行います.

ssl_cert = </etc/letsencrypt/live/example1.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/example1.com/privkey.pem

/etc/dovecot/conf.d/10-master.conf に以下の定義を行います.

service imap-login {
  inet_listener imap {
    port = 143
  }
  inet_listener imaps {
    port = 993
    ssl = yes
  }

上記の設定ができたら,dovecotを再起動します.

# systemctl restart dovecot

メールの送受信確認

ここでメールの送受信テストを行います.

証明書のバックアップ

他のサーバで利用できるように/etc/letsencrypt/live/example1.com/* を(NFSサーバ上に)バックアップするスクリプトの作成を行いsystemd のtimerに設定します(詳細については省略します).

これでマルチドメイン証明書への置き換えは完了です.

コメント

タイトルとURLをコピーしました