Keycloak 自动更改证书

Keycloak 自动更改证书

我在 Nginx 反向代理后面使用带有 docker-compose 的 Keycloak Quay 22.0.3,但由于使用 certbot 生成的证书自动替换,我遇到了一些麻烦。

我使用 certbot 生成的证书完全没问题,它显示它将在 3 个月后过期,(颁发者)它的 CN 是 R3,它的组织是 Let's Encrypt(与其他域一样)。

一旦我启动docker-compose它可能使用正确的证书时间并且它使用 HTTPS,然后,突然间,它被一个我没有生成的证书替换,(颁发者)CN Cisco Umbrella Secondary SubCA ams-SG 和组织 Cisco 和(颁发给)组织 Cisco Systems, Inc.,而之前它是空白的,当然,连接不再是私密的了(NET::ERR_CERT_AUTHORITY_INVALID)。

这是我的 docker-compose 文件:

version: "3.9"

services:
  keycloak:
    container_name: "keycloak"
    image: quay.io/keycloak/keycloak:22.0.3
    environment:
      KC_DB: mysql
      KC_DB_URL: jdbc:mysql://database_container:3306/keycloak
      KC_DB_USERNAME: username
      KC_DB_PASSWORD: password
      KEYCLOAK_ADMIN: kc_admin
      KEYCLOAK_ADMIN_PASSWORD: kc_admin_password
      KC_HOSTNAME: keycloak.hostname.com
      KC_HOSTNAME_STRICT_HTTPS: "false"
    ports:
      - "8443:8443"
    volumes:
      - /keycloak/certs/fullchain.pem:/etc/x509/https/tls.crt
      - /keycloak/certs/privkey.pem:/etc/x509/https/tls.key
    command:
      start --https-certificate-file=/etc/x509/https/tls.crt --https-certificate-key-file=/etc/x509/https/tls.key --hostname-strict=false
    networks:
      - my_network

networks:
  my_network:
    name: my_network
    external: true

这是我的 Nginx 配置:

server {
    server_name www.keycloak.hostname.com keycloak.hostname.com;

    location / {
        proxy_pass https://ip_address:8443/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP \$remote_addr;
        proxy_buffer_size 256k;
        proxy_buffers 4 512k;
        proxy_busy_buffers_size 512k;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/keycloak.hostname.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/keycloak.hostname.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}

server {
    if ($host = www.keycloak.hostname.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = keycloak.hostname.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    server_name www.keycloak.hostname.com keycloak.hostname.com;
    listen 80;
    return 404; # managed by Certbot
}

docker-compose中使用的证书是/etc/letsencrypt/live/keycloak.hostname.com/*,具有655权限。

编辑

我忘了提及,Cisco Umbrella 颁发的证书有效期从 2023 年 9 月 17 日到 2023 年 9 月 22 日。

相关内容