0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Let's Encryptの証明書をMyDNS.jpとGoogle Cloud DNSで更新する方法(Macユーザー向け)

Posted at

はじめに

この記事では、Let's Encryptの無料SSL/TLS証明書をMyDNS.jpで手動更新する方法と、Google Cloud DNSを使用して自動更新する方法をMacユーザー向けに紹介します。

MyDNS.jpを使用した手動での証明書更新

ステップ 1: Certbotのインストール

CertbotをHomebrewを使用してMacにインストールします。

brew install certbot
ステップ 2: 証明書の取得

DNS-01チャレンジを使用して証明書を手動で取得します。

sudo certbot certonly --manual --preferred-challenges dns -d "XXX.mydns.jp" -d "*.XXX.mydns.jp"
ステップ 3: DNS TXTレコードの設定

Certbotが生成するTXTレコードをMyDNS.jpに設定します。Certbotはフルネーム_acme-challenge.XXX.mydns.jp.を表示しますが、MyDNS.jpではレコード名として_acme-challengeのみを入力します。

ステップ 4: DNS設定の確認

設定したTXTレコードが正しくDNSに反映されているかを確認するために、Google Admin Toolbox - DIGを使用します。

Google Cloud DNSを使用した自動更新

ステップ 1: Google Cloudプロジェクトのセットアップ

Google Cloud Consoleにアクセスし、新しいプロジェクトを作成してDNS APIを有効にします。

ステップ 2: サービスアカウントの作成

サービスアカウントを作成し、DNS管理者権限を付与し、JSON形式のキーをダウンロードします。

ステップ 3: DNSゾーンの作成

Google Cloud DNSで新しいDNSゾーンを作成し、ドメイン名を設定します。

ステップ 4: 自動更新スクリプトの設定

manual-auth-hook.shmanual-cleanup-hook.shを作成します。以下はmanual-auth-hook.shの例です。

#!/bin/bash
gcloud auth activate-service-account --key-file=/path/to/your-service-account-key.json
gcloud dns record-sets transaction start --zone="your-zone-name" --project="your-gcp-project-id"
gcloud dns record-sets transaction add --name="_acme-challenge.${CERTBOT_DOMAIN}." --type=TXT --ttl=300 --zone="your-zone-name" --project="your-gcp-project-id" "${CERTBOT_VALIDATION}"
gcloud dns record-sets transaction execute --zone="your-zone-name" --project="your-gcp-project-id"
ステップ 5: Certbotの自動更新の実行
certbot renew --manual-auth-hook "/path/to/manual-auth-hook.sh" --manual-cleanup-hook "/path/to/manual-cleanup-hook.sh"

まとめ

この記事では、MyDNS.jpとGoogle Cloud DNSを使用して、Let's Encryptの証明書の手動更新と自動更新の方法を紹介しました。MacユーザーはHomebrewを利用してCertbotを簡単にインストールできます。自動更新の設定にはGoogle Cloudの設定とスクリプトが必要であり、一度設定すれば以後の更新が楽になります。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?