Pound + Letsencrypt for Play 框架和 AWS CloudFront

Pound + Letsencrypt for Play 框架和 AWS CloudFront

背景

我有一個舊的 Play Framework Web 應用程序,它提供來自兩個 CDN(siteassetscourseassets)的資產,這兩個 CDN 使用 AWS CloudFront 實作。與 web 應用程式運行在同一 VM 上,並且僅充當 SSL 端點,因為使用的舊版本 Play Framework 不處理 SSL。 Pound 綁定到連接埠 80 和 443。

之前,我對 CDN 資產和 Web 應用程式使用了 Symantec SSL 通配符憑證。現在 Symantec SSL 憑證只剩下幾天的時間就不再有效,我決定使用 AWS Certificate Manager 為 CDN 預置單域 SSL 證書,並使用 Letsencrypt 為 CDN 提供單域 SSL 憑證。 Letscrypt 憑證的有效期限只有 90 天,因此需要自動刷新。

Pound 想要 PEM 格式的 SSL 證書,但 Letsencrypt 似乎沒有提供 PEM 格式的便利方法。 Letsencrypt 並沒有像 Apache httpd、Tomcat 或其他知名框架那樣為 Play Framework 提供任何特殊規定。

我不想為了更新 Pound 使用的 SSL 憑證而使 Web 應用程式離線。

目前英鎊配置

以下是我目前的/etc/pound/pound.cfg英鎊版本2.7f-0ubuntu1。此配置已有幾年歷史,可能需要更新,Pound 也可能應該更新。

# Global options

User    "root"
Group   "root"

# Logging: (goes to syslog by default)
#  0  no logging
#  1  normal
#  2  extended
#  3  Apache-style (common log format)
#  4 (same as 3 but without the virtual host information)
#  5 (same as 4 but with information about the Service and BackEnd used)
LogLevel 5

# Check backend every X secs:
Alive    30

# Use hardware-accelleration card supported by openssl(1):
#SSLEngine  "<hw>"

# poundctl control socket
Control "/var/run/poundctl.socket"

# Redirect all http requests on port 80 to https on port 443
# The Play Framework webapp never sees these redirected requests because Pound handles them
ListenHTTP
  Address 0.0.0.0
  Port 80
  Err500 "/usr/local/etc/pound_error_500"
  Err503 "/usr/local/etc/pound_error_500"
  Service
    Redirect 301 "https://www.scalacourses.com"
  End
End

# Redirect all requests on port 443 to the Play Framework webapp on port 9443
ListenHTTPS
  Address 0.0.0.0
  Port 443
  Err500 "/usr/local/etc/pound_error_500"
  Err503 "/usr/local/etc/pound_error_500"
  Cert "/var/work/training/cadenza/conf/ssl/scalacourses.com.pound.pem"
  Disable SSLv3
  Ciphers "EECDH+ECDSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!eNULL:!LOW:!aNULL:!MD5:!DSS"
  SSLAllowClientRenegotiation     0
  SSLHonorCipherOrder 1
  HeadRemove "X-Forwarded-Proto"
  HeadRemove "x-forwarded-proto"
  AddHeader "x-forwarded-proto: https"
  Service
    BackEnd
      #HTTPS
      Address 127.0.0.1
      Port 9000
    End
  End
End

問題

  1. certbot ACME 用戶端版本 0.17.0 是透過以下方式安裝的: sudo apt install certbot

    我看到certbot 版本 0.21.0可用。我應該使用這個較新的版本而不是 Ubuntu 17.10 提供的預設版本嗎?

  2. Debian PPA 中是否有合理的 Pound 版本?以前我必須自己建立 Pound,但我更喜歡使用預先建置的版本。https://launchpad.net/ubuntu/+source/pound有版本 2.7-1.3 ...這是最好的穩定版本嗎?
  3. 中的磅配置需要進行哪些變更/etc/pound/pound.cfg?顯然這一行需要更新: Cert "/var/work/training/cadenza/conf/ssl/scalacourses.com.pound.pem"

    當 Pound 更新時,此行可能需要更新: Ciphers "EECDH+ECDSA+AESGCM:EECDH+ECDSA+SHA384:EECDH+ECDSA+SHA256:ECDH+AESGCM:ECDH+AES256:ECDH+AES128:ECDH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!eNULL:!LOW:!aNULL:!MD5:!DSS"

    還可能需要新增、刪除或修改哪些其他行?我知道 Pound 不應該作為 運行root,但這可以單獨處理。

  4. 需要一個腳本來最初為 Pound 配置 Letsencrypt SSL 憑證。似乎證書機器人Letscrypt 使用的程式想要綁定到端口 80,但 Pound 綁定到此端口,並且我不想為了升級 SSL 憑證而關閉 web 應用程式。有沒有辦法在與 Pound 相同的虛擬機器上運行它,或者我應該在另一個虛擬機器上運行它並在準備好後以 PEM 格式複製生成的憑證?

  5. 需要一個可以每 45 天透過 cron 呼叫的腳本,以便刷新 SSL 憑證。

答案1

設定一個在本機(127.0.0.1:80)上偵聽的小型httpd(Nginx、Apache...),並使目錄[DOCUMENT_ROOT]/.well-known/acme-challenge/ 對執行此目錄的使用者可寫httpd。比在磅配置中創建

服務“letcrypt”
    HeadRequire“主機:.*”
    URL“/.well-known/acme-challenge/.*”
    後端
        地址 127.0.0.1
        80埠
    結尾
結尾

優先於所有其他規則。現在你應該能夠做類似的事情

certbot-auto certonly --email [email protected] -d www.example.com -d example.com --verbose --agree-tos --webroot --webroot-path /var/www/localhost/htdocs/

請將“/var/www/localhost”更改為本地httpd 的Document_root。您只需執行一次此操作。稍後你可以做類似的事情

# add --dry-run to test it certbot-auto renew --post-hook "/etc/init.d/pound restart" for i in ls /etc/letsencrypt/live/; do cp /etc/letsencrypt/live/$i/privkey.pem /opt/pound_certs/$i.pem ; cat /etc/letsencrypt/live/$i/fullchain.pem >> /opt/pound_certs/$i.pem ; done

當然,不要忘記稍後在磅配置中添加 pem 文件;-) 我知道後掛鉤來得太晚了。但是 Letscrypt 將在舊證書到期前 10 天頒發新證書。因此,如果你每天都讓它做一個計時任務,那就完全沒有問題了。

答案2

  1. 目前版本certbot運作正常,無需最新版本。
  2. 仍然不知道最近來源的 Pound 的預建版本。
  3. 我只需要更改線路Cert,這是有道理的,因為我還沒有升級 Pound。
  4. 該腳本可以在任何虛擬機器上運行,因為在使用 DNS 質詢時它不會綁定到連接埠 80 或連接埠 443。

以下是certbot53我編寫的使用腳本jed/certbot-route53透過 DNS 質詢進行身份驗證。該腳本依賴於公關我提交的certbot-route53文件修復了兩個錯誤。

#!/bin/bash

#STAGING=--staging
CERT_DIR=/etc/pound/certbot
DOMAIN=scalacourses.com
MAIL_ADDR='[email protected]'
SCRIPT_NAME=certbot-route53.sh

if [ ! -d "$CERT_DIR/letsencrypt" ]; then sudo mkdir -p $CERT_DIR/letsencrypt; fi
sudo chmod 777 "$CERT_DIR/letsencrypt"

cd $CERT_DIR

if [ ! -f "$CERT_DIR/$SCRIPT_NAME" ]; then
  sudo curl -sL https://git.io/vylLx -o $SCRIPT_NAME
  sudo chmod a+x certbot-route53.sh
fi

./$SCRIPT_NAME \
  --agree-tos \
  --manual-public-ip-logging-ok \
  --domains $DOMAIN,www.$DOMAIN \
  --renew-by-default \
  --email $MAIL_ADDR $STAGING

PRIV_KEY="$CERT_DIR/letsencrypt/live/$DOMAIN/privkey.pem"
FULL_CHAIN="$CERT_DIR/letsencrypt/live/$DOMAIN/fullchain.pem"
COMBINED="$CERT_DIR/combined-for-pound.pem"
cat "$PRIV_KEY" "$FULL_CHAIN" | sudo tee "$COMBINED" > /dev/null
  1. 目前我正在透過 cron 作業重新運行相同的腳本。這意味著我不是升級證書,而是替換它們。不清楚升級憑證的好處是什麼。這是cron條目,它每 2 個月以我的用戶 ID 運行一次腳本;我輸入後輸入sudo crontab -e

    0 0 1 */2 * su mslinn /usr/local/bin/certbot53
    

相關內容