LoginSignup
2

More than 5 years have passed since last update.

2017/02/03 に heroku certs + Let's Encrypt + Rails で証明書を更新したら意図せぬエラーで悩まされた件

Posted at

heroku certs コマンド

証明書が切れそうなので update することで証明書を最新にしようかなと思って実行していたんですが、意図せぬエラーによって時間がかかってしまったので、似たような事で躓かないように書き残しておきます。

前提

Let's Encrypt による証明書の更新

上記の記事を参考に実行。

$ cd ~/letsencrypt/
$ git pull origin master
$ sudo certbot certonly --manual -d YOURDOMAIN

途中、certbot の指示に従って heroku 上で LETSENCRYPT_REQUESTLETSENCRYPT_RESPONSE を設定。

設定後、

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/YOURDOMAIN/fullchain.pem. Your cert will expire
   on 2017-05-04. To obtain a new or tweaked version of this
   certificate in the future, simply run certbot again. To
   non-interactively renew *all* of your certificates, run "certbot
   renew"
 - 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

と出たので Let's Encrypt での証明書の取得は完了。

heroku certs で証明書をアップロード(問題はここ)

$ sudo heroku certs:update /etc/letsencrypt/live/YOURDOMAIN/fullchain.pem /etc/letsencrypt/live/YOURDOMAIN/privkey.pem -a APPID
▸    Must pass --name when more than one endpoint

このエラーをググっても有効な回答がなく。

エンドポイントが複数ある場合…?

$ sudo heroku certs:update /etc/letsencrypt/live/YOURDOMAIN/fullchain.pem /etc/letsencrypt/live/YOURDOMAIN/privkey.pem --name APPNAME -a APPID
 ▸    Record not found.

何したらわかるんだ…。

$ sudo heroku certs:update /etc/letsencrypt/live/YOURDOMAIN/fullchain.pem /etc/letsencrypt/live/YOURDOMAIN/privkey.pem --help
Usage: heroku certs:update CRT KEY

update an SSL certificate on an app

 -a, --app APP       # app to run command against
 -r, --remote REMOTE # git remote of app to run command against
 --bypass            # bypass the trust chain completion step
 --endpoint ENDPOINT # endpoint to update
 --name NAME         # name to update

Example:

 $ heroku certs:update example.com.crt example.com.key

ここで、「ところで certs のリストを見るコマンドって何か無いのかな」と思ったところで。

$ heroku certs -a APPID
Name              Endpoint                       Common Name(s)  Expires               Trusted  Type
────────────────  ─────────────────────────────  ──────────────  ────────────────────  ───────  ────────
hogehogeho-00000  (Not applicable for SNI)       YOURDOMAIN       2017-02-18 13:47 UTC  True     SNI
fugafugafu-00000   fugafugafu-00000.herokussl.com  YOURDOMAIN     2017-02-18 13:47 UTC  True     Endpoint

なるほど、 heroku が新しく SSL をタダで使えるようになった時に試したままだった。
fugafugafu-00000 が名前っぽいのでその名前をつけて再実行。

$ sudo heroku certs:update /etc/letsencrypt/live/YOURDOMAIN/fullchain.pem /etc/letsencrypt/live/YOURDOMAIN/privkey.pem --name fugafugafu-00000 -a APPID
Resolving trust chain... done
 ▸    Potentially Destructive Action
 ▸    This command will change the certicate of endpoint fugafugafu-00000 (fugafugafu-00000.herokussl.com) from ⬢ APPID.
 ▸    To proceed, type APPID or re-run this command with --confirm APPID
> APPID
Updating SSL certificate fugafugafu-00000 for ⬢ APPID... done
Updated certificate details:
Common Name(s): YOURDOMAIN
Expires At:     2017-05-04 05:00 UTC
Issuer:         /C=US/O=Let's Encrypt/CN=Let's Encrypt Authority X3
Starts At:      2017-02-03 05:00 UTC
Subject:        /CN=YOURDOMAIN
SSL certificate is verified by a root authority.

これで良さそう。

確認

実施前の SSL 証明書

Google Chrome の開発者ツール Security タブから。
image

View certificate する。

image

実施後

image

確認してみて OK。

残タスク

  • あとで不要な証明書を削除する

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
2