Gadget 13:証明書と TLS
Cloudflare OS を外部公開するための証明書・TLS・期限切れ対策
証明書と TLS
OAuth 連携や外部公開を安定させるための TLS / 証明書の運用です。
目的
- HTTPS で確実に公開する(OAuth が拒否されない)
- 証明書の期限切れによる停止を防ぐ
前提条件
- ドメイン(DNS 管理権限)
- リバースプロキシ or Tunnel のどちらかを選択済み(12)
手順
1. 方式を選ぶ
| 方式 | 証明書の扱い | おすすめ |
|---|---|---|
| Cloudflare Tunnel | 自動(無料証明書) | 手軽・最初におすすめ |
| Let’s Encrypt + Caddy/nginx | certbot / 自動更新 |
自前プロキシ派 |
| 既存証明書 | 更新管理を自分で | 要件が特殊な場合 |
2. TLS 終端を設定する
# Caddy(自動で Let's Encrypt)
caddy run --config Caddyfile
# Caddyfile:
# cf.example.com {
# reverse_proxy 127.0.0.1:8787
# }Tunnel の場合は cloudflared を起動するだけで TLS は云々不要。
3. 期限切れ対策
- Let’s Encrypt: 90 日 → 自動更新(certbot timer / Caddy 自動)
- 検証コマンドを手動でも実行可能に:
certbot renew --dry-run
openssl s_client -connect cf.example.com:443 -servername cf.example.com 2>/dev/null \
| openssl x509 -noout -enddate4. アクセス先の完全一致を確認
OAuth コールバック URL が https://<hostname>/... と完全一致しているか (03-gatekeeper-integration)。
よくある失敗
| 症状 | 原因 | 対処 |
|---|---|---|
| ブラウザで警告 | 期限切れ・自己署名 | 自動更新を整備、または正規証明書 |
| OAuth が拒否 | http のまま | https で統一 |
| 証明書が更新されない | ポート 80 での challenge 不可 | 80 を開ける / Tunnel に切替 |
| 接続が固まる | 証明書チェーン不全 | openssl s_client で表示確認 |
確認
次に読む
- ネットワーク構成 → 12-networking-basics
- セキュリティ → 11-security-hardening
- 監視・通知 → 18-monitoring-and-alerting