Let's Encrypt ワイルドカードSSL/TLS証明書のインストールと更新自動化
こんにちは、うぱです。
使用環境
・Azure Virtual Machine(rhel9.3)
・AWS route53 / IAM
AWS手順
使用するドメインのネームサーバーをAWSのroute53にしてください。
ホストゾーンID確認
Route53 > ホストゾーン > 対象ドメインのホストゾーンIDをメモ帳等にコピーしてください
ポリシー作成
IAM > ポリシー > ポリシーの作成
ポリシーエディタをJSONに変更し、コピペースト。
コードの内のホストゾーンIDは、前述の手順でコピーしたホストゾーンIDに変更する。
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"route53:ListHostedZones",
"route53:GetChange"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": "route53:ChangeResourceRecordSets",
"Resource": "arn:aws:route53:::hostedzone/ホストゾーンID"
}
]
}
ポリシー名に「CertbotRoute53Policy」を入力し作成
ユーザー作成とポリシーアタッチ
IAM > ユーザー > ユーザーの作成
ユーザー名「CertbotRoute53User」を入力 > 次へ
ポリシーを直接アタッチする > 「CertbotRoute53Policy」にチェック > 次へ
ユーザーの作成
アクセスキー作成
IAM > ユーザー > CertbotRoute53User > セキュリティ認証情報 > アクセスキーを作成
AWSの外部で実行されるアプリケーション > 次へ
アクセスキーを作成
表示された「アクセスキー」と「シークレットアクセスキー」をメモ帳等にコピーして保存
SSL/TLS証明書インストール
epelリポジトリ追加
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm -y
epelリポジトリ追加確認
yum repolist | grep epel
Certbot・Certbot/Apache用プラグイン・Certbot/Route53プラグインをインストール
yum -y install certbot python-certbot-apache python3-certbot-dns-route53
AWSの資格情報設定
ディレクトリ作成
mkdir -p ~/.aws
ファイル開く
vi ~/.aws/credentials
資格情報設定
[default]
aws_access_key_id = アクセスキー
aws_secret_access_key = シークレットキー
ワイルドカードのSSL/TLS証明書を発行
sudo certbot certonly \
--dns-route53 \
-d example.com \
-d '*.example.com' \
--agree-tos \
--no-eff-email \
--email メールアドレス
証明書期限確認
openssl x509 -enddate -noout -in /etc/letsencrypt/live/example.com/fullchain.pem
SSL/TLS証明書更新
証明書更新が正常に実行可能かテスト
certbot renew --dns-route53 --dry-run
更新自動化
cron設定ファイル開く
crontab -e
月2回更新チェックスケージュール
0 0 1,15 * * sudo certbot renew --pre-hook "systemctl stop httpd" --post-hook "systemctl start httpd"
この記事が気に入ったらサポートをしてみませんか?