For

2023.2.27

Let’s Encryptでサブドメインをワイルドカードで指定していた場合の更新方法

概要

Let’s Encryptでサブドメインをワイルドカードで指定していた場合は certbot renew で更新できません。
サブドメインをワイルドカードで指定して証明書をインストールしたときと同じコマンドを利用してサイドインストールするような流れで更新します。
ただ、最初のインストール時と少しだけ異なる部分が発生することがあるので備忘録として残しておきます。

手順

サブドメインをワイルドカードで指定してインストール

まずは証明書を新たにインストールするときと同じようにコマンドを入力します。
今回の例では当サイトのドメインをサンプルとします。

bash_____terminal_____$ certbot certonly --manual --preferred-challenges dns-01 -d kobayashiii.dev -d *.kobayashiii.dev

// 実行結果

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Renewing an existing certificate for kobayashiii.dev and *.kobayashiii.dev
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.kobayashiii.dev.

with the following value:

LLGsK6gNCWmwcVmN3YuUnbAjPoNaEoBQmWsbw2AKEAT // <- これは適当に生成したサンプルです
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue


上記コマンドにより表示された文字列を、初回インストール時と同様に _acme-challenge TXTレコードを設定します。
設定完了後にEnterを押すと、今回は初回とは異なり以下のように表示されました。

bash_____terminal_____- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please deploy a DNS TXT record under the name:

_acme-challenge.kobayashiii.dev.

with the following value:

2yxxAb6BiM1xjYEmXfgbvdt523PqTifNHtTtB4MdN4q // <- これは適当に生成したサンプルです

(This must be set up in addition to the previous challenges; do not remove,
replace, or undo the previous challenge tasks yet. Note that you might be
asked to create multiple distinct TXT records with the same name. This is
permitted by DNS standards.)

Before continuing, verify the TXT record has been deployed. Depending on the DNS
provider, this may take some time, from a few seconds to multiple minutes. You can
check if it has finished deploying with aid of online tools, such as the Google
Admin Toolbox: https://toolbox.googleapps.com/apps/dig/#TXT/_acme-challenge.kobayashiii.dev.
Look for one or more bolded line(s) below the line ';ANSWER'. It should show the
value(s) you've just added.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Press Enter to Continue


カッコ内の文章はDeepLで翻訳すると以下のようになります。

これは以前のチャレンジに加えて設定する必要があります。
削除したり、置き換えたり、元に戻したりしないでください。
を削除したり、置き換えたり、以前のチャレンジタスクを元に戻したりしてはいけません。
以下のことに注意してください。
同じ名前で複数の異なるTXTレコードを作成するように要求されるかもしれないことに注意してください。
これはDNSの標準によって許可されています。


_acme-challenge TXTレコードを追加

ということで、現状の _acme-challenge TXTレコードは残しつつ、追加で同名の _acme-challenge TXTレコードを設定します。


このように _acme-challenge TXTレコードが2つ登録されていれば問題ありません。
この状態でターミナルに戻ってEnterキーを押すと以下のように表示されました。

bash_____terminal_____Successfully received certificate.
Certificate is saved at: /etc/letsencrypt/live/kobayashiii.dev/fullchain.pem
Key is saved at:         /etc/letsencrypt/live/kobayashiii.dev/privkey.pem
This certificate expires on 2023-05-28.
These files will be updated when the certificate renews.


問題なく更新が完了しました。

まとめ

サブドメインをワイルドカードで指定する場合はTXTレコードの更新を伴うインタラクティブな更新となるのでcronなどで自動更新の設定ができません。
もし自動更新の設定方法がわかったらまた別の記事で残そうと思います。