[AWS]ACMのACME証明書によるSSLサーバ証明書自動更新
AWS ACMのACME証明書で取得したSSLサーバ証明書をAWS以外の外部WEBサーバで自動更新します。
1. SSLサーバ証明書の構成
(1) 仕様
| 対象ドメイン名 |
www.example.jp / example.jp(1枚のSAN証明書として発行) |
| 認証種別 |
DV認証 |
| クライアント |
acme.sh |
| 認証方式 |
DNS認証 |
(2) 証明書ファイル構成
| ファイル名 |
用途 |
| /etc/httpd/certs/www.example.jp/www.example.jp.privkey_nopwd.pem |
秘密鍵(パスフレーズなし) |
| /etc/httpd/certs/www.example.jp/www.example.jp.inca.pem |
中間CA証明書 |
| /etc/httpd/certs/www.example.jp/www.example.jp.cert.pem |
サーバ証明書 |
| /etc/httpd/certs/www.example.jp/www.example.jp.full_cert.pem |
サーバ証明書 + 中間CA証明書 |
2. AWS CLI v2の導入
(1) インストール
AWS CLI v2のインストールを行います。
# cd /usr/local/src
# curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
# unzip awscliv2.zip
# ./aws/install
# /usr/local/bin/aws --version
(2) 初期設定
ASW Access Key ID: (アクセスキー)
ASW Secret Access Key: (シークレットアクセスキー)
Default region name:ap-northeast-1
Default output format:json
3. ACM ACME証明書の設定
(1) ACMEエンドポイントの作成
- 「AWS Certificate Manager (ACM)」-「エンドポイント」をクリックします。
- 「ACME エンドポイントを作成」をクリックします。
[a] エンドポイント設定
| エンドポイント名 |
www-example-jp-acm-acme-endpoint |
| エンドポイントのタイプ |
パブリック |
| アカウントメール登録 – オプション |
|
[b] 証明書の設定
| 証明書タイプ |
パブリック |
| 証明書キーのタイプ |
RSA 2048 |
[c] ドメイン
| ドメイン名 |
example.jp |
| ドメインのスコープ |
サブドメイン(ドメインの使用目的に応じてチェックを付けて下さい) |
| ホストゾーン ID – オプション |
example.jp(自動DNS検証レコード管理自動をRoute 53で行う場合) |
| タグ – オプション |
(任意) |
| 証明書タグ – オプション |
(任意) |
- 「ACME エンドポイントを作成」をクリックします。
(2) ドメインの検証
Route 53を使用している場合は「Route 53 でレコードを作成」をクリック、その他の場合はDNSレコードにCNAMEで登録します。
(3) EAB情報の作成
[a] IAMロールの権限ポリシーの作成
- 「IAM」-「ポリシー」
- 「ポリシーの作成」をクリックします。
- ポリシーエディタを「JSON」にします。
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowIssueAndRevokeOnlyTargetDomains",
"Effect": "Allow",
"Action": [
"acm:RequestCertificate",
"acm:RevokeCertificate"
],
"Resource": "*",
"Condition": {
"ForAllValues:StringEquals": {
"acm:DomainNames": [
"example.jp",
"www.example.jp"
]
}
}
}
]
}
※「acm:DomainNames」には実際のドメインを入力して下さい。
| ポリシー名 |
AcmeIssuancePolicyForExampleJp |
| 説明 – オプション |
Policy for ACM ACME Certificates |
[b] ロールの作成
- 「IAM」-「ロール」
- 「ロールを作成」をクリックします。
- 「信頼されたエンティティタイプ」で「カスタム信頼ポリシー」を選択
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "TrustAcmAcmeService",
"Effect": "Allow",
"Principal": {
"Service": "acm-acme.amazonaws.com"
},
"Action": [
"sts:AssumeRole",
"sts:TagSession",
"sts:SetSourceIdentity"
]
}
]
}
- 「次へ」をクリック
- 「許可ポリシー」で「AcmeIssuancePolicyForExampleJp」にチェック
- 「次へ」をクリック
| ロール名 |
AcmeIssuanceRoleForExampleJp |
| 説明 |
Role for ACM ACME certificates |
[c] EAB情報の作成
- 「AWS Certificate Manager (ACM)」-「エンドポイント」をクリックします。
- 該当のエンドポイントで「外部アカウントバインディング」
- 「EAB を作成」をクリックします。
| 認証情報の名前 – オプション |
www-example-jp-acm-acme-eab |
| 有効期限 – オプション |
7日 |
| IAM アクセス許可 |
AcmeIssuanceRoleForExampleJp |
[d] EAB情報の取得
EAB情報が取得されたら、以下の値を取得します。
| ACME_ENDPOINT_URL |
エンドポイントURL |
| EAB_KID |
Key ID |
| EAB_HMAC_KEY |
HMAC Key |
4. acme.shの導入
(1) acme.shのインストール
# cd ~
# curl https://get.acme.sh | sh -s email=(メールアドレス)
# source ~/.bashrc
# /root/.acme.sh/acme.sh --version
(2) EAB情報の登録
# vi /root/.acme.sh/.acm_acme_eab.env
ACME_ENDPOINT_URL='https://acm-acme-enroll.ap-northeast-1.api.aws/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/directory'
EAB_KID='Key ID'
EAB_HMAC_KEY='HMAC Key'
ACME_CONTACT_EMAIL='(連絡先メールアドレス)'
# source /root/.acme.sh/.acm_acme_eab.env
(3) acme.shのACMEアカウント登録
# /root/.acme.sh/acme.sh --register-account \
--server "${ACME_ENDPOINT_URL}" \
--eab-kid "${EAB_KID}" \
--eab-hmac-key "${EAB_HMAC_KEY}" \
-m webmaster@example.jp
5. SSLサーバ証明書の発行
(1) standalone方式
一度Apacheを停止してから、SSLサーバ証明書を発行します。
# systemctl stop httpd.service
# /root/.acme.sh/acme.sh --issue \
--server "${ACME_ENDPOINT_URL}" \
--standalone \
-d example.jp \
-d www.example.jp \
--keylength 2048
# systemctl start httpd.service
(2) webroot方式
Apacheを停止したくない場合はwebroot方式でSSLサーバ証明書を発行します。
# /root/.acme.sh/acme.sh --issue \
--server "${ACME_ENDPOINT_URL}" \
--webroot /var/www/html \
-d example.jp \
-d www.example.jp \
--keylength 2048
6. SSLサーバ証明書の設定
(1) SSLサーバ証明書ファイルの配置
以下のように配置します。
| SSLサーバ証明書ディレクトリ |
/etc/httpd/certs/www.example.jp/acme |
| 秘密鍵ファイル(パスフレーズなし) |
www.example.jp.privkey_nopwd.pem |
| 証明書ファイル |
www.example.jp.cert.pem |
| 中間CA証明書ファイル |
www.example.jp.inca.pem |
| 証明書+中間CA証明書ファイル |
www.example.jp.full_cert.pem |
# mkdir -p /etc/httpd/certs/www.example.jp/acme
# /root/.acme.sh/acme.sh --install-cert -d www.example.jp \
--key-file /etc/httpd/certs/www.example.jp/acme/www.example.jp.privkey_nopwd.pem \
--cert-file /etc/httpd/certs/www.example.jp/acme/www.example.jp.cert.pem \
--ca-file /etc/httpd/certs/www.example.jp/acme/www.example.jp.inca.pem \
--fullchain-file /etc/httpd/certs/www.example.jp/acme/www.example.jp.full_cert.pem
(2) Apacheでの設定
ssl.confで以下のように記載します。
SSLCertificateFile /etc/httpd/certs/www.example.jp/acme/www.example.jp.full_cert.pem
SSLCertificateKeyFile /etc/httpd/certs/www.example.jp/acme/www.example.jp.privkey_nopwd.pem
最終更新:2026年07月07日 13:16