LoginSignup
0
1

OCI証明書サービスにインポートした証明書の自動更新スクリプト

Last updated at Posted at 2024-04-26

概要

Let's Encryptで発行した証明書をOCI証明書サービスにインポートした後、自動更新のスクリプトを作成しました。

前提条件

  • OCI CLIがインストールされ、設定済みであること
  • Let's Encryptで発行した証明書がOCI証明書サービスにインポートされていること
  • Let's Encryptで発行した証明書の自動更新用の仕組みが別途構築されていること

スクリプト

#!/bin/bash

file1="/etc/letsencrypt/live/******.***/cert.pem"
file2="/tmp/cert.pem"

if cmp -s "$file1" "$file2"; then
    echo "No need to update certificate."
else
    echo "Start updating the certificate."
    oci certs-mgmt certificate update-certificate-by-importing-config-details \
     --certificate-id ocid1.certificate.oc1.ap-tokyo-1.******* \
     --certificate-pem "$(cat /etc/letsencrypt/live/******.***/cert.pem)" \
     --private-key-pem "$(cat /etc/letsencrypt/live/******.***/privkey.pem)" \
     --cert-chain-pem "$(cat /etc/letsencrypt/live/******.***/chain.pem)" 
    cp "$file1" "$file2"
    echo "Certificate update complete."
fi

説明:
Let's Encryptで発行した証明書とバックアップした証明書を比較します。
差分がなければ、何も行いません。
差分がある場合は、OCIの証明書を更新した後、現行の証明書をバックアップファイルにコピーします。

oci certs-mgmt certificate update-certificate-by-importing-config-details に関する詳細については、公式ドキュメントをご参照ください。

スクリプトの定期自動実行設定は別途構築する必要があります。

参考資料:

0
1
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
0
1