Google Trust Services でSSL証明書を発行しよう
About
# はじめに
GoogleCloudサービスのSSL証明書が無料で、かつワイルドカードにも対応しているというので、発行してみます。
もともと、「Let's Encrypt」でしたが、相互運用チェーンがどうのこうのっていうのがあるみたいなので、お試しでやってみます。
→ CloudflareからのLet's Encrypt証明書変更の通知
# gloud CLIをインストールする
Rootで作業します。Root権限がなければ sudo を頭につけてください。
Debianで作業しています。Ubuntuは同じコマンドでできますが、Centosなど別のディストリビューションの場合はGoogleCloudのドキュメントを参考にしてください。
パッケージ更新しておきましょう。
# apt-get update
apt-transport-httpsとcurlがインストールしている必要があります。
されてなければ、
# apt-get install apt-transport-https ca-certificates gnupg curl
を実行してください。
公開鍵のインストール
# curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo gpg --dearmor -o /usr/share/keyrings/cloud.google.gpg
次に配布 URI をパッケージ ソースとして追加します
# echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
パッケージの更新をしてインストールします。
# apt-get update # apt-get install google-cloud-cli
これでインストール完了です。
# gcloudの初期設定をする
初期化やってきます。
# gcloud init
ネットワークのチェックが行われて、ログインするか聞かれます。
You must log in to continue. Would you like to log in (Y/n)? Y Go to the following link in your browser: https://accounts.google.com/o/oauth2/<ログイン用URL> Enter authorization code:
ログイン用URLが発行されるので、このURLをコピーしてブラウザで開きます。
アクセスすると、許可とか色々出てくるので、次へとか許可とかを選んで進めていきます。
最終的に確認コードが発行されるので、Enter authorization codeに貼り付けます。
この黒字で隠してるやつがコードです。
プロジェクトを選択します。
今回は事前に作っていた[2]のgts1020を選択します。なければ、「Create a new project」で作れると思うので作りましょう。
Enter authorization code: <確認コード> You are logged in as: [GMail]. Pick cloud project to use: [1] freetier0000 [2] gts1020 [3] Enter a project ID [4] Create a new project Please enter numeric choice or text value (must exactly match list item): 2
これで初期設定が完了です。
Public CA APIを有効にします
# gcloud services enable publicca.googleapis.com
EAB鍵IDとHMACをリクエスする
# gcloud publicca external-account-keys create
コピーしておいてください。後で使います。
ACMEアカウントを登録する
# certbot register \ --email "EMAIL_ADDRESS" \ --no-eff-email \ --server "https://dv.acme-v02.api.pki.goog/directory" \ --eab-kid "EAB_KID" \ --eab-hmac-key "EAB_HMAC_KEY"
書き換えてコピペしてください。
こちらは本番環境の公的に信頼できる証明書を取得します。
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please read the Terms of Service at https://pki.goog/GTS-SA.pdf. You must agree in order to register with the ACME server. Do you agree? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y Account registered.
これで設定関連は完了です。
# SSL証明書を発行する
# certbot certonly \ --manual \ --preferred-challenges "dns-01" \ --server "https://dv.acme-v02.api.pki.goog/directory" \ --domains "DOMAINS"
ドメインはワイルドカード対応です。
# certbot certonly \ --manual \ --preferred-challenges "dns-01" \ --server "https://dv.acme-v02.api.pki.goog/directory" \ --domains "*.yama2211.jp" \ --domain "yama2211.jp"
DNSにTXTレコードを追加するやつが出るので、TXTレコードを追加してください。
反映に時間がかかることがありますが、Cloudflareの場合は割とすぐに反映されてました。
Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/yama2211.jp/fullchain.pem Key is saved at: /etc/letsencrypt/live/yama2211.jp/privkey.pem This certificate expires on 2024-06-16. These files will be updated when the certificate renews. NEXT STEPS: - This certificate will not be renewed automatically. Autorenewal of --manual certificates requires the use of an authentication hook script (--manual-auth-hook) but one was not provided. To renew this certificate, repeat this same certbot command before the certificate's expiry date. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - If you like Certbot, please consider supporting our work by: * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate * Donating to EFF: https://eff.org/donate-le - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
証明書の発行が完了です。
あとは、/etc/letsencrypt/live/yama2211.jp/fullchain.pemと/etc/letsencrypt/live/yama2211.jp/privkey.pemをApacheやNginxなどに設定すればOKです。
ちゃんと、Goole Trust Service LLCの証明書ですね。