Squidで立てたHTTPSプロキシをLet's Encryptする
Squidで立てたHTTPSプロキシサーバーのために、Let's Encryptで証明書を作りました。
なお、squidでオレオレHTTPSプロキシを立てた記事は以下です。
SquidでBasic認証つきオレオレHTTPSプロキシ立てる
準備
あらかじめ、どこかしらでドメイン名を取得してきます。ここでは mydomain.piyo
とします。
また、ドメイン名で名前解決できるように、ネームサーバーとかDNSレコードをちゃんとしておきます。
Certbotクライアントをダウンロード
以下サイト様の手順に従って行います。Amazon LinuxはRHEL 6ベースなので、『CentOS 6 / RHEL 6』の手順です。
Let's Encrypt の使い方 - Let's Encrypt 総合ポータル
EPELを有効にします。
sudo yum install epel-release
Certbotクライアントをダウンロードして、全ユーザーで実行可能な権限を与えておきます。
wget https://dl.eff.org/certbot-auto
chmod a+x certbot-auto
certbot-auto 実行
次の記事を参考にさせていただきました。
Let's Encrypt で Nginx にSSLを設定する - Qiita
Let's Encryptを利用してApache 2.4サーバをHTTPS化する - Qiita
certbot-auto
を実行していきます。
Apacheが動いてるサーバーなら ./certbot-auto
で起動すればインタラクティブに証明書発行→設定までやってくれますが、今回はApacheで使うわけではないので、certonly
をつけて証明書の発行だけ行います。
また、Amazon Linuxではオプション --debug
をつけないと動きません。つけましょう。
./certbot-auto certonly --debug
起動すると、以下のように色々聞かれます。
認証方法
How would you like to authenticate with the ACME CA?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: Spin up a temporary webserver (standalone)
2: Place files in webroot directory (webroot)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel):
Webサーバーではないので 1 (standalone) を選択しました。
standaloneでは一時的にWebサーバーが上がるので、ポート80と443あたりが空いてないとダメらしいです。
なお、Apacheが入ってると 1: Apache Web Server plugin (apache)
が、Nginxが入ってると 1: Nginx Web Server plugin (nginx)
が出てきました。その場合はstandaloneの番号が違うかもしれません。
メールアドレス
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel):
期限切れとセキュリティのお知らせを受け取るためのものなので、入力しないと進めません。
規約
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel:
同意して A を入力します。
メルマガ
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o:
Certbotの開発をしてるElectronic Frontierというとこにメールアドレスを共有してよいか聞かれてます。
いるなら Y、いらなければ N を入力します。
ドメイン名
Please enter in your domain name(s) (comma and/or space separated) (Enter 'c'
to cancel):
あらかじめ用意しておいたドメイン名を入力します。ドメイン名が無いとLet's Encryptできません。
もし何かのエラーが出たら、当ブログの以下記事を参照してみてください。
Amazon EC2でLet's Encryptするときに出たエラーと対処法 - キリウ君が読まないノート
正常に完了すると、以下のようなメッセージが表示されます。
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mydomain.piyo/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mydomain.piyo/privkey.pem
Your cert will expire on 2019-05-05. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again. To non-interactively renew *all* of your certificates, run
"certbot-auto renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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
これで、
/etc/letsencrypt/live/mydomain.piyo/cert.pem
にサーバー証明書/etc/letsencrypt/live/mydomain.piyo/chain.pem
に中間CA証明書/etc/letsencrypt/live/mydomain.piyo/fullchain.pem
にサーバー証明書と中間CA証明書がくっついたもの/etc/letsencrypt/live/mydomain.piyo/privkey.pem
に秘密鍵
が作成されました。
Squidに証明書設定
HTTPSプロキシなら、すでにsquidの設定ファイルで https_port
を設定してると思います。
作成した証明書と秘密鍵のパスで cert
と key
を書き換えます。
https_port 8081 cert=/etc/letsencrypt/live/mydomain.piyo/fullchain.pem key=/etc/letsencrypt/live/mydomain.piyo/privkey.pem
終わったらサービス再起動します。
sudo service squid restart
動作確認
ここではプロキシのポートは 8081
とします。
cURLでプロキシ挿してどこかにアクセスしてみます。
curl -x https://mydomain.piyo:8081 https://note.kiriukun.com
オレオレ証明書ではないので、オプション --proxy-insecure
をつけなくてもアクセスできるはずです。