Atlasを利用したCertbot SSL適用

Atlasを利用したCertbotによるSSL証明書の適用およびSSL期間短縮に対応するための設定の記録。

The GlobalSign Atlas Certificate Management API provides high volume certificate issuance and lifecycle management capabilities through state-of-the-art RESTful APIs.A downloadable copy of the API documentation can be found here: https://www.globalsign.com/en/repository/globalsign-atlas-certificate-management-api.pdf.

実行環境の構築 (Python 3.9)

標準の Python 3.6 ではライブラリの不整合が発生するため、Python 3.9 を使用して独立した環境を作成します。

Python 3.9 のインストール

sudo dnf install python39 -y

仮想環境の作成(ディレクトリ名は任意)

sudo rm -rf /opt/certbot-globalsign
sudo python3.9 -m venv /opt/certbot-globalsign

仮想環境内の pip 更新と Certbot のインストール

sudo /opt/certbot-globalsign/bin/pip install --upgrade pip
sudo /opt/certbot-globalsign/bin/pip install certbot

GlobalSign ACME アカウントの登録 (EAB)

GlobalSign から発行された EAB Key ID と HMAC Key を使用して、サーバを登録します。この作業はサーバ一台につき初回の一度だけ必要です。

/opt/certbot-globalsign/bin/certbot register \
--server https://emea.acme.atlas.globalsign.com/directory \
--eab-kid [あなたのKey ID] \
--eab-hmac-key [あなたのHMAC Key] \
--email [email protected]

 規約への同意(Y)を求められるので、画面に従って回答してください。

証明書の取得 (HTTP認証 / Webroot)

DNS レコードをいじる必要はありません。Web サーバの公開ディレクトリを利用して認証を行います。

Bash<br>/opt/certbot-globalsign/bin/certbot certonly \
--server https://emea.acme.atlas.globalsign.com/directory \
--webroot \
-w /var/www/sp.aquila.jp/html \
-d sp.aquila.jp

-w: ドメインのドキュメントルート(公開ディレクトリ)を指定します。
-d: 取得するドメイン名を指定します。

Web サーバへの反映 (Apache 例)

発行された証明書を Apache の設定ファイル(ssl.conf 等)に紐付けます。

証明書: /etc/letsencrypt/live/sp.aquila.jp/fullchain.pem
秘密鍵: /etc/letsencrypt/live/sp.aquila.jp/privkey.pem

SSLCertificateFile /etc/letsencrypt/live/sp.aquila.jp/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/sp.aquila.jp/privkey.pem

設定後、systemctl reload httpd で反映させます。

自動更新の設定 (CRON)

証明書の期限(90日)が切れる前に、自動で更新して Web サーバを再読み込みするよう設定します。

00 03 * * * /opt/certbot-globalsign/bin/certbot renew --quiet --post-hook "systemctl reload httpd"

--post-hook: 更新が成功したときだけ Apache をリロードします。

運用中の確認コマンド
正しく設定できているか不安なときは、以下のコマンドでテストできます。

/opt/certbot-globalsign/bin/certbot renew --dry-run

/opt/certbot-globalsign/bin/certbot certificates

openssl x509 -in /etc/letsencrypt/live/sp.aquila.jp/fullchain.pem -text -noout | grep "Issuer"