「CertStorageError: expected /etc/letsencrypt/live/xxx/cert.pem to be a symlink」の対処法

カテゴリ:SSL証明書

/usr/bin/certbot/certbot-auto renewを実行したら以下のエラーが表示された場合の対処法です。
Traceback (most recent call last):
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot/renewal.py", line 64, in _reconstitute
    renewal_candidate = storage.RenewableCert(full_path, config)
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot/storage.py", line 465, in __init__
    self._check_symlinks()
  File "/opt/eff.org/certbot/venv/lib/python2.7/site-packages/certbot/storage.py", line 523, in _check_symlinks
    "expected {0} to be a symlink".format(link))
CertStorageError: expected /etc/letsencrypt/live/example.com/cert.pem to be a symlink
Renewal configuration file /etc/letsencrypt/renewal/example.com.conf is broken. Skipping.

/etc/letsencrypt/archive配下には実体ファイルがあります。これは問題ありません。

# ls -1 archive/example.com/* | xargs md5sum
5aa21eebad10566b62e202b76fc6d9bc  archive/example.com/cert1.pem
6a18b35b02d0b252d9342098265599c5  archive/example.com/chain1.pem
b48587016f3522fb48bf7f355e29622a  archive/example.com/fullchain1.pem
2cdfadf35eb4724aa98868eeb1338209  archive/example.com/privkey1.pem

このエラーが発生する場合、/etc/letsencrypt/live配下には上記と同一の実体ファイルが存在するはずです。

# ls -1 live/example.com/* | xargs md5sum
7697b2660f805a0358bf4b1637764736  live/example.com/README
5aa21eebad10566b62e202b76fc6d9bc  live/example.com/cert.pem
6a18b35b02d0b252d9342098265599c5  live/example.com/chain.pem
b48587016f3522fb48bf7f355e29622a  live/example.com/fullchain.pem
2cdfadf35eb4724aa98868eeb1338209  live/example.com/privkey.pem

しかし、本来は以下のようにarchive配下のファイルに対するシンボリックリンクでなければなりません

# ls -la live/example.com/*
-rw-r--r-- 1 root root 692  6月  1 19:34 live/example.com/README
lrwxrwxrwx 1 root root  39  6月  1 19:34 live/example.com/cert.pem -> ../../archive/example.com/cert1.pem
lrwxrwxrwx 1 root root  40  6月  1 19:34 live/example.com/chain.pem -> ../../archive/example.com/chain1.pem
lrwxrwxrwx 1 root root  44  6月  1 19:34 live/example.com/fullchain.pem -> ../../archive/example.com/fullchain1.pem
lrwxrwxrwx 1 root root  42  6月  1 19:34 live/example.com/privkey.pem -> ../../archive/example.com/privkey1.pem

これは該当ディレクトリのバックアップ・復元時に実体ファイルをバックアップしてしまい、そのまま戻してしまった場合などに発生します。(cpコマンドでシンボリックリンクをシンボリックリンクのまま再帰的にコピーするには-rではなく-Rオプションを使用する必要があります)

修正するためには、以下のコマンドを実行して実体ファイルをシンボリックリンクと置き換えます
※example.comは実際のディレクトリ名と置き換えて実行してください。

# mv /etc/letsencrypt/live/example.com/* /tmp/
# cd /etc/letsencrypt/archive/example.com/
# ln -s /etc/letsencrypt/archive/example.com/cert1.pem cert.pem
# ln -s /etc/letsencrypt/archive/example.com/chain1.pem chain.pem
# ln -s /etc/letsencrypt/archive/example.com/fullchain1.pem fullchain.pem
# ln -s /etc/letsencrypt/archive/example.com/privkey1.pem privkey.pem

再度証明書の更新に問題がないかを試してみましょう。

# /usr/bin/certbot/certbot-auto renew --dry-run

公開日時:2019年06月01日 19:58:11

なお、VPS選びで迷ったらこちらの記事で主要VPSのメモリ容量ごとの月額、年額料金を比較していますので、是非参考にしてみてください。

SSL証明書に戻る

「SSL証明書」に関する他のTips

このページのトップに戻る