それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

certbot でステージング(テスト環境)用に証明書を作る

certbot で同一ドメインの証明書を複数作る

ステージングや、certbot のコマンドであれこれ実験していると、証明書の発行上限に達してしまいます。

そこで、 ステージング用の証明書を使うと良さそうなので試してみた。ステージングやテスト用にドメインを作って管理するのも面倒な話ですし。

ステージングの使用

testing:
  The following flags are meant for testing and integration purposes only.

  --test-cert, --staging
                        Use the staging server to obtain or revoke test
                        (invalid) certificates; equivalent to --server https
                        ://acme-staging-v02.api.letsencrypt.org/directory
                        (default: False)

ステージングを使うと、閾値による制限にかからなくなるので、コマンドや.gitlab-ci.yml や .circle-ci.yaml に組み込むとき実験で使える。重宝する

使い方

いつもの、certbot のコマンドにオプションを付けるだけ。

  --staging \   を追加しています。

certbot で証明書作るサンプル

mydomain=example.com \
sudo ./certbot-test/bin/certbot  \
  certonly \
  --staging \ 
  --cert-name ${mydomain}-staging \
  --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/cloudflareapi.cfg \
   -d "*.${mydomain}" \
   -d ${mydomain}

わたしは、ドメイン所持のチェックにcloudflare プラグインを使うのでオプションが入っていますね。

実際にアクセスしてみる

証明書のの検証には失敗する。自己証明書よりは簡便でマシかな程度のステージング証明書になる。 f:id:takuya_1st:20190327162607p:plain

削除したり 更新したり

削除したり、更新したり、いろんなcertbot のコマンドを試せたり、また検証サーバーやテスト用に作れるので便利かもしれない。

追記:revoke

--staging / --test-cert で作った証明書は、当然ですが、そのままでは通常運用出来ない代物なので、 revoke する必要がなく、revoke コマンドは通りません。

不要になったら delete します。

その他の方法

dry-run の利用

dry-run でも似たような効果は得られる。

--dry-run             Perform a test run of the client, obtaining test
                        (invalid) certificates but not saving them to disk.
                        This can currently only be used with the 'certonly'
                        and 'renew' subcommands. Note: Although --dry-run
                        tries to avoid making any persistent changes on a
                        system, it is not completely side-effect free: if used
                        with webserver authenticator plugins like apache and
                        nginx, it makes and then reverts temporary config
                        changes in order to obtain test certificates, and
                        reloads webservers to deploy and then roll back those
                        changes. It also calls --pre-hook and --post-hook
                        commands if they are defined because they may be
                        necessary to accurately simulate renewal. --deploy-
                        hook commands are not called. (default: False)

参考資料

https://certbot.eff.org/docs/using.html?highlight=staging