
hermanosgecko/authentik一个轻量级的转发认证服务,为Traefik反向代理/负载均衡器提供登录和认证功能,使用Apache基本认证(htpasswd)文件。基于traefik-forward-auth的概念,但使用文件型认证提供者替代了Google/OIDC。
适用于需要为Traefik代理的服务添加简单认证保护的场景,特别是:
以下是使用docker-compose部署authentik与Traefik的示例配置:
yamlversion: '3' services: traefik: image: traefik:1.7 command: [ "--web", "--docker", "--docker.domain=docker.localhost" ] depends_on: - "authentik" ports: - "80:80" volumes: - /var/run/docker.sock:/var/run/docker.sock:ro networks: traefik-net: public-net: labels: - "traefik.port=8080" - "traefik.frontend.rule=Host:traefik.docker.localhost" - "traefik.frontend.auth.forward.address=[***]" - "traefik.frontend.auth.forward.trustForwardHeader=true" - "traefik.frontend.auth.forward.authResponseHeaders=X-Forwarded-User" authentik: image: hermanosgecko/authentik:latest environment: - INSECURE_COOKIE=true # 示例未使用HTTPS,生产环境请勿使用 - COOKIE_DOMAIN=docker.localhost - AUTH_HOST=auth.docker.localhost - SECRET=THIS_IS_A_SECRET networks: traefik-net: aliases: - "authentik" volumes: - ${PWD}/htpasswd:/htpasswd:ro labels: - "traefik.port=4567" - "traefik.frontend.rule=Host:auth.docker.localhost" - "traefik.frontend.auth.forward.address=[***]" - "traefik.frontend.auth.forward.trustForwardHeader=true" - "traefik.frontend.auth.forward.authResponseHeaders=X-Forwarded-User" whoami: image: stefanscherer/whoami:latest networks: traefik-net: labels: - "traefik.port=8080" - "traefik.frontend.rule=Host:whoami.docker.localhost" - "traefik.frontend.auth.forward.address=[***]" - "traefik.frontend.auth.forward.trustForwardHeader=true" - "traefik.frontend.auth.forward.authResponseHeaders=X-Forwarded-User" networks: traefik-net: internal: true public-net:
容器镜像通过运行时参数进行配置,格式为<外部>:<内部>。例如,-p 8080:80表示将容器内的80端口映射到主机的8080端口。
| 参数 | 功能 |
|---|---|
-p 4567 | authentik Web界面的端口 |
-e COOKIE_DOMAIN=mydomain.com | Cookie的作用域域名(必填) |
-e AUTH_HOST=auth.mydomain.com | 登录页面的子域名,必须是COOKIE_DOMAIN的子域,无需包含协议或路径(必填) |
-e SECRET=THIS_IS_A_SECRET | 用于签名认证Cookie的密钥,建议使用随机值(如openssl rand -hex 16生成)(必填) |
-e COOKIE_NAME=tokenname | Cookie名称,默认为authentik.token |
-e INSECURE_COOKIE=true | 当客户端与Traefik之间不使用HTTPS时启用,此时Cookie将不设置Secure属性,默认为False |
-e LIFETIME=86400 | 认证会话有效期(秒),默认为86400(24小时) |
-v /htpasswd | htpasswd文件的挂载路径 |
通过htpasswd文件限制可登录用户。支持的密码格式包括Apache MD5、SHA1、libc crypt或纯文本,同一文件中可混合使用不同加密类型的密码。
认证后的用户信息通过X-Forwarded-User头传递,需在Traefik配置中添加authResponseHeaders=X-Forwarded-User(如示例中的labels配置)。
app10.test.com/home/pagetest.com域下设置认证Cookieapp10.test.com/home/page注意:必须确保
AUTH_HOST是COOKIE_DOMAIN的子域,且指向authentik容器的请求已正确路由(如示例中通过Traefik labels配置)。
Apache 2.0
manifest unknown 错误
TLS 证书验证失败
DNS 解析超时
410 错误:版本过低
402 错误:流量耗尽
身份认证失败错误
429 限流错误
凭证保存错误
来自真实用户的反馈,见证轩辕镜像的优质服务