Traefik 基本身份验证不适用于 HTTPS

Traefik basic auth does not work with HTTPS

我 运行 在 Docker 暖模式下使用这些标签的服务:

- "traefik.docker.network=proxy"
- "traefik.backend=kibana"
- "traefik.frontend.entryPoints=https,http"
- "traefik.frontend.rule=Host:mydomain"
- "traefik.port=5601"
- "traefik.frontend.auth.basic=test:098f6bcd4621d373cade4e832627b4f6"

使用 HTTPS 时遇到这个问题

curl -u test:test https://my-domain.com
401 Unauthorized

使用 HTTP 一切正常

curl -u test:test http://my-domain.com
Found

我找到了问题的原因,我使用 traefik 变量 "traefik.frontend.auth.basic=test:$$apr1$$EaOXV0L6$DQbzuXBeb6Y8jjI2ZbGsg/" 将服务部署为堆栈。但是这个变量的部署值看起来像 test:/.

手动设置正确的值后 - 身份验证工作正常。

我也尝试过使用命令部署服务 docker 服务创建和变量具有正确的值。

使用 htpassword 为我解决了这个问题。似乎 Traefik 使用相同的算法来解散密码。

apt install apache2-utils

htpasswd -nb your_username "your_password_here"

您将收到相应的哈希值

your_username:khrglahfslgkha345346

将其复制粘贴到您的 .toml 或 docker-compose 脚本中。

在您的前端使用您的密码(不是哈希)登录,一切都会正常。

我最近发现您必须处理结果 hash 中的双美元符号。你必须在不同的场景中逃脱 $....