【问题标题】:ForwardAuth Middleware is not working in Traefik as API GatewayForwardAuth 中间件在 Traefik 中不能作为 API 网关工作
【发布时间】:2019-09-30 19:32:36
【问题描述】:

我正在尝试将 Traefik 作为 API 网关运行,并希望通过使用以下 docker compose 文件触发 ForwardAuth 中间件,但未命中身份验证端点的中间件。我在 localhost 中使用它。

version: '3'

services:
  reverse-proxy:
    image: traefik # The official Traefik docker image
    command: --api --docker # Enables the web UI and tells Traefik to listen to docker
    ports:
      - "80:80"     # The HTTP port
      - "8080:8080" # The Web UI (enabled by --api)
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # So that Traefik can listen to the Docker events
      - $PWD/traefik.toml:/traefik.toml     

  whoami:
    image: emilevauge/whoami
    labels:
      - traefik.enable=true
      - "traefik.frontend.rule=Host:whoami.docker.localhost"
      - "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
      - "traefik.http.middlewares.test-replacepath.replacepath.path=/foo"
      - "traefik.http.middlewares.testauth.ForwardAuth.Address=http://localhost:55391/api/Auth"

【问题讨论】:

    标签: docker traefik api-gateway


    【解决方案1】:

    我也为此苦苦挣扎了一段时间,除了在 Traefik 文档中相当隐藏之外,找不到任何答案。 ForwardAuth docs实际上并没有提到这个,但是看着middlewares overview configuration example我突然注意到你不仅要指定中间件,还要将它应用到路由器上。

    将此标签添加到whoami 服务应该可以解决问题:

    - "traefik.http.routers.whoami.middlewares=testauth"
    

    请注意,您还可以在此处指定多个中间件,用逗号分隔它们,这样您就可以像这样添加您定义的其他中间件:

    - "traefik.http.routers.whoami.middlewares=testauth,test-redirectscheme,test-replacepath"
    

    【讨论】:

      猜你喜欢
      • 2022-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 2016-11-20
      • 1970-01-01
      • 2022-06-17
      相关资源
      最近更新 更多