【问题标题】:Certbot command in docker-compose issues SSL certificate with invalid CAdocker-compose 中的 Certbot 命令发出带有无效 CA 的 SSL 证书
【发布时间】:2020-10-16 11:39:27
【问题描述】:

问题

我正在尝试使用certbot 在我的多容器 Docker 配置中为 Nginx 自动生成 TLS 证书。除了证书颁发机构 (CA) 无效外,一切都按预期工作。

当我访问我的网站时,我看到 Fake LE Intermediate X1,一个无效的授权机构,颁发了证书:

我的设置

这里是 docker-compose.yml 文件,我在其中调用certbot 来生成证书:

version: '2'
services:
  apollo:
    restart: always
    networks:
      - app-network
    build: .
    ports:
      - '1337:1337'
  certbot:
    image: certbot/certbot
    container_name: certbot
    volumes:
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
      - web-root:/var/www/html
    depends_on:
      - webserver
    command: certonly --noninteractive --keep-until-expiring --webroot --webroot-path=/var/www/html --email myemail@example.com --agree-tos --no-eff-email -d mydomain.com
  webserver:
    image: nginx:latest
    container_name: webserver
    restart: unless-stopped
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - web-root:/var/www/html
      - ./nginx.conf:/etc/nginx/nginx.conf
      - certbot-etc:/etc/letsencrypt
      - certbot-var:/var/lib/letsencrypt
      - dhparam:/etc/ssl/certs
    depends_on:
      - apollo
    networks:
      - app-network

volumes:
  postgres: ~
  certbot-etc:
  certbot-var:
  dhparam:
    driver: local
    driver_opts:
      type: none
      device: /home/user/project_name/dhparam/
      o: bind
  web-root:

networks:
  app-network:

我不认为 Nginx 是问题,因为 HTTP -> HTTPS 重定向有效,并且浏览器收到证书。但以防万一:这是 nginx.conf,我在其中引用证书并配置 HTTP -> HTTPS 重定向。

events {}
http {
  server {
    listen 80;
    listen [::]:80;
    server_name mydomain.com;

    location ~ /.well-known/acme-challenge {
      allow all;
      root /var/www/html;
    }

    location / {
      rewrite ^ https://$host$request_uri? permanent;
    }
  }

  server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;        
    server_name mydomain.com;

    server_tokens off;

    ssl_certificate /etc/letsencrypt/live/mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mydomain.com/privkey.pem;

    ssl_buffer_size 8k;

    ssl_dhparam /etc/ssl/certs/dhparam-2048.pem;

    ssl_protocols TLSv1.2 TLSv1.1 TLSv1;
    ssl_prefer_server_ciphers on;

    ssl_ciphers ECDH+AESGCM:ECDH+AES256:ECDH+AES128:DH+3DES:!ADH:!AECDH:!MD5;

    ssl_ecdh_curve secp384r1;
    ssl_session_tickets off;

    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8;

    location / {
      try_files $uri @apollo;
    }

    location @apollo {
      proxy_pass http://apollo:1337;
      add_header X-Frame-Options "SAMEORIGIN" always;
      add_header X-XSS-Protection "1; mode=block" always;
      add_header X-Content-Type-Options "nosniff" always;
      add_header Referrer-Policy "no-referrer-when-downgrade" always;
      add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
    }

    root /var/www/html;
    index index.html index.htm index.nginx-debian.html;
  }
}

我尝试过的

  1. 最初,我在docker-compose.ymlcerbot 容器定义中使用--staging 参数调用certonly。这肯定会导致无效的 CA 问题。但是,我已经尝试撤销 CA 并多次重新运行该命令,但没有成功。

  2. 我已尝试删除docker-compose.ymlcerbot 容器定义中的--keep-until-expiring 标志。这会导致cerbot 生成新证书,但它没有解决 CA 问题。

  3. 访问crt.sh,我可以看到 certbot 确实为我的域颁发了有效证书:

所以,问题似乎不在于这些证书的生成,而在于我的 docker-compose/cerbot 配置引用它们的方式。

【问题讨论】:

    标签: docker ssl docker-compose certbot


    【解决方案1】:

    您可以尝试添加--force-renewal 标志:

    command: >-
      certonly
      --webroot
      --webroot-path=/var/www/html
      --email myemail@example.com
      --agree-tos
      --no-eff-email
      --force-renewal
      -d mydomain.com
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2016-04-02
      • 1970-01-01
      相关资源
      最近更新 更多