アレコレ調べている途中で certbot-dns-google という certbot
のプラグインを見つけたので試してみた。
インストール
以下は Ubuntu 16.04 LTS
での例 (仕事で使ってる端末をまだ更新してない(;^ω^))
$ sudo apt-get python3-pip $ sudo pip3 install certbot-dns-google $ sudo pip3 install --upgrade pyasn1 #<-自分の環境だと pyasn1 が古いと言われたので更新 $ sudo certbot plugins ------------------------------------------------------------------------------- * dns-google #<-dns-goodle がいてる Description: Obtain certificates using a DNS TXT record (if you are using Google Cloud DNS for DNS). Interfaces: IAuthenticator, IPlugin Entry point: dns-google = certbot_dns_google.dns_google:Authenticator ...
実行
- GCPサービスアカウントの作成と、JSONの取得はすでに済ませている前提
dns-google-credentials
で、JSONへのパスを指定- せっかくだから
--server
で acme-v02 を指定してワイルドカードにしてみた
$ sudo certbot certonly \ --server https://acme-v02.api.letsencrypt.org/directory \ --dns-google \ --dns-google-credentials SERVICE_ACCOUNT_JSON \ --email EMAIL@ADDRESS \ --agree-tos \ -d *.DOMAIN
これだけで Cloud DNS に登録していたドメインのレコードに _acme-challenge.〜
が作成され、ドメイン所有者としての認証、証明書の発行、レコードの削除まで実行された(楽だ。。
ちなみに certonly
ではなく renew
で実行したら、下記メッセージが表示された。
Currently, the renew verb is capable of either renewing all installed certificates that are due to be renewed or renewing a single certificate specified by its name. If you would like to renew specific certificates by their domains, use the certonly command instead. The renew verb may provide other options for selecting certificates to renew in the future.
今は certonly だけで回すだけで更新もいけるのかな。 更新するときは -n とか付けとけば良いのかも。
参考URL
追記
証明書の更新をトリガーに、Cloud Storage に証明書をおいて、CloudFunctions で GCE に配るとかできるのかな?って思ったけど、そもそもGCE(GAE)に対しては外からしかアクセスできないみたいだ (実際に更新するならLBに対してだろうけど)
Google Issue Tracker > CloudFunctions > Question: Connecting to Google Compute Engine
結局証明書を取得して Terraform で更新するのが良い気がするけど、3ヶ月毎に自動更新するのはどうするのがええやろかーとちょと考えるなぁ。
以上