Mailuのサーバ証明書リニューアル方法(要調査)

2023年1月25日

この件は諦めた。詳細は、TraefikとMailuの共存方法にある。

サーバ証明書のメンテナンス

mailuをインストールして動作させるのだが、既にリバースプロキシとしてTraefikを動作させており、80, 443ポートはTraefikが管理している。他のウェブサイト等のサーバ証明書は、Traefikが管理しており、勝手にリニューアルしてくれる。Let’s Encryptの場合、おおよそ三ヶ月ごとにリニューアルが必要になってくる。

しかし、mailuにもサーバ証明書が必要だ。この場合の選択肢としては、以下。

  • Traefikにmailuのサーバ証明書も取得させ、それをmailuの証明書フォルダに放り込む
  • mailu自身にサーバ証明書をメンテナンスさせる

前者の方法はわからない。Traefik上で取得されるサーバ証明書ファイルのフォーマットとmailuのサーバ証明書ファイルフォーマットが違いすぎるからだ。今のところ、どうやって変換すべきかわからない。

ということで、後者の方法をとった。

採用した方法

本来、mailuは、80, 443を自分で外部公開し、専有するようになっている。つまり、「このサーバ」上には、自分しかウェブサービスが起動していないことが前提になっている。これではまずいため、以下のようにした。

  • 80番は、Traefikのみからアクセスできるようにし、外部からmail.example.com:80へのアクセスがあった場合に、それをmailuに振り分ける。
  • 443番は、8443番として外部公開し、管理者には常にhttps://mail.example.com:8443でアクセスさせる。

80番をオープンしておかなければならない理由は、Let’s encryptのリニューアル時に必要だからだ。これは他のポート番号にすることができない。例えば、8001番にして、そこに受け付けられるようにすれば、Traefikを気にせずにMailuだけで完結できるはずだが、そうはできない。

How do I specify a port other than 80 when adding SSL certificate using Certbot?

三ヶ月経っての結果は?

自動的にリニューアルされていないので、そのままの設定で手動でmailuの再起動を行うが、やはりだめだった。以下のようなエラーになり、リニューアルできていない。

front_1     | 2022/12/27 14:22:29 [info] 10#10: *28 client 46.148.40.172:40110 connected to 0.0.0.0:25
front_1     | 2022/12/27 14:22:29 [error] 10#10: *28 46.148.40.172 could not be resolved (3: Host not found) while in resolving client address, client: 46.148.40.172, server: 0.0.0.0:25
front_1     | 
front_1     | Certbot failed to authenticate some domains (authenticator: standalone). The Certificate Authority reported these problems:
front_1     |   Domain: mail.example.com
front_1     |   Type:   unauthorized
front_1     |   Detail: 133.18.**.**: Invalid response from http://mail.example.com/.well-known/acme-challenge/ReVQKOenvJ72Vu5ul7MEgRqAW*******: 404
front_1     | 
front_1     | Hint: The Certificate Authority couldn't exterally verify that the standalone plugin completed the required http-01 challenges. Ensure the plugin is configured correctly and that the changes it makes are accessible from the internet.
front_1     | 

手動でリニューアルする

かなり放置していたのだが、いよいよ不便になったので。以下を行う。

  • traefikをストップする。このサーバ上のすべてのウェブサイトがストップ。
  • mailuのdocker-compose.yml上で80:80として、80番ポートをオープンさせるようにする。
  • mailuを再起動する
  • docker-compose.ymlをもとに戻して、mailuを再起動
  • traefikを起動する。

当然だが、今回はうまく行った。

front_1     | Saving debug log to /var/log/letsencrypt/letsencrypt.log
admin_1     | INFO  [alembic.runtime.migration] Context impl SQLiteImpl.
admin_1     | INFO  [alembic.runtime.migration] Will assume non-transactional DDL.
front_1     | Renewing an existing certificate for mail.no-sheep.org
antispam_1  | 2023-01-22 03:47:15 #10(hs_helper) rspamd_rs_compile_cb: compiled 0 regular expressions to the hyperscan tree, postpone loaded notification for 1 seconds to avoid races
front_1     | 34.210.74.30 - - [22/Jan/2023:03:47:16 +0000] "GET /.well-known/acme-challenge/CJBazqXmdiZ7QVpPrkZszwpyMvuqX******* HTTP/1.1" 200 98 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)"
front_1     | 23.178.112.203 - - [22/Jan/2023:03:47:16 +0000] "GET /.well-known/acme-challenge/CJBazqXmdiZ7QVpPrkZszwpyMvuqX******* HTTP/1.1" 200 98 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)"
front_1     | 18.219.106.132 - - [22/Jan/2023:03:47:16 +0000] "GET /.well-known/acme-challenge/CJBazqXmdiZ7QVpPrkZszwpyMvuqX*******k HTTP/1.1" 200 98 "-" "Mozilla/5.0 (compatible; Let's Encrypt validation server; +https://www.letsencrypt.org)"
admin_1     | [2023-01-22 03:47:17 +0000] [9] [INFO] Starting gunicorn 20.1.0
admin_1     | [2023-01-22 03:47:17 +0000] [9] [INFO] Listening at: http://0.0.0.0:80 (9)
admin_1     | [2023-01-22 03:47:17 +0000] [9] [INFO] Using worker: gthread
admin_1     | [2023-01-22 03:47:17 +0000] [10] [INFO] Booting worker with pid: 10
front_1     | 2023/01/22 03:47:19 [notice] 1#1: signal 1 (SIGHUP) received from 15, reconfiguring
front_1     | 2023/01/22 03:47:19 [notice] 1#1: reconfiguring
front_1     | 
front_1     | Successfully received certificate.
front_1     | Certificate is saved at: /certs/letsencrypt/live/mailu/fullchain.pem
front_1     | Key is saved at:         /certs/letsencrypt/live/mailu/privkey.pem
front_1     | This certificate expires on 2023-04-22.
front_1     | These files will be updated when the certificate renews.
front_1     | 
front_1     | NEXT STEPS:
front_1     | - The certificate will need to be renewed before it expires. Certbot can automatically renew the certificate in the background, but you may need to take steps to enable that functionality. See https://certbot.org/renewal-setup for instructions.
front_1     | 
front_1     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
front_1     | If you like Certbot, please consider supporting our work by:
front_1     |  * Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
front_1     |  * Donating to EFF:                    https://eff.org/donate-le
front_1     | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

まとめ

これでは面倒すぎるので何とか打開策を見出したいものだが。。。

Mailuでは無いが、同様の状況にいる人の書き込みを見つけた。

How do I specify a port other than 80 when adding SSL certificate using Certbot?