LoginSignup
4
0

More than 1 year has passed since last update.

Gitlabでletsencryptの証明書の更新に失敗した時にやること

Last updated at Posted at 2022-04-09

はじめに

Gitlabをセルフホスティングしていると、どこかのタイミングでletsencryptの証明書の有効期限が切れることがあると思います。
本来は自動更新設定しておくべきですが、自分の場合は設定していたけどうまくいかなかったので期限が切れてから更新する羽目に。。

やること

gitlabをreconfigureする

公式の解説に沿って、
以下のどちらかを実行します

sudo gitlab-ctl reconfigure
sudo gitlab-ctl renew-le-certs

上記を行なっても解決せず、Acme::Clinet::Error::AccountDoesNotExist と言われた時

エラー例
image.png

一旦、acmeの証明書ファイルを消します。ただ、本当に消してしまうのは怖いのでmvファイルでbackupを取る形でデフォルト名のファイル(account_private_key.pem)を存在しない状態にします。
その後、設定の際読み込みを行います。

sudo mv /etc/acme/account_private_key.pem /etc/acme/account_private_key.pem.backup
sudo gitlab-ctl reconfigure

参考:
GitLab – ACME AccountDoesNotExist

ここまでやっても解決せず、以下のように Timeout during connect (likely firewall problem)と表示された場合

エラー例

letsencrypt_certificate[xxxxxxxxx.japaneast.cloudapp.azure.com] (letsencrypt::http_authorization line 6) had an error: RuntimeError: acme_certificate[staging] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/letsencrypt/resources/certificate.rb line 41) had an error: RuntimeError: ruby_block[create certificate for xxxxx.japaneast.cloudapp.azure.com] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/acme/resources/certificate.rb line 110) had an error: RuntimeError: [xxxxxxxxjapaneast.cloudapp.azure.com] Validation failed, unable to request certificate, Errors: [{url: https://acme-staging-v02.api.letsencrypt.org/acme/chall-v3/2125788808/DrHubA, status: invalid, error: {"type"=>"urn:ietf:params:acme:error:connection", "detail"=>"Fetching http://xxxxxxxxxxxxxx.japaneast.cloudapp.azure.com/.well-known/acme-challenge/xxxxxxxxxxxxxxxx: Timeout during connect (likely firewall problem)", "status"=>400}} ]

エラー文言からわかるように、firewall関連の問題と推察できます。
自分の場合は、AzureVMのネットワーク設定でIP制限をかけていたので、それが更新を邪魔していたようです。
エラーに表示されているhttp://xxxxxxxxxxxxxx.japaneast.cloudapp.azure.comへのリクエストが通るように,port80に対してのインバウンドIP制限を一時的に取っ払ってから、再度sudo gitlab-ctl reconfigureしたところ、証明書を更新できました

おそらく、このIP制限によって自動更新もうまくいかなかったのでは?と考えています。今後検証予定。

おわりに

いかがでしたでしょうか。あまりドンピシャなトラブルシューティング記事が見つからなかったので記事にまとめてみましたが、どなたかのお役に立てれば幸いです。

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0