How to apply forwardauth middleward on some operation (update and delete)

Hello, How can apply it to delete and post operations and do not apply it to the get.
Currently any action requires authentication

labels:
     - "traefik.http.middlewares.service-auth.forwardauth.address=http://auth_service.localhost/authService"
     - "traefik.http.routers.crud_service.middlewares=service-auth"
     - "traefik.http.routers.crud_service.entrypoints=web" 
     - "traefik.http.routers.crud_service.rule=Host(`crud_service.localhost`)"
     - "traefik.http.services.crud_service.loadbalancer.server.port=3010"

I don't think that is possible with Traefik. You could use different URLs with different services. But in my opinion it's either all or nothing. If you need to differentiate, this should probably be done inside your application.

You can create two routers.

labels:
     - "traefik.http.routers.r_service.rule=Host(`crud_service.localhost`)"
     - "traefik.http.routers.cud_service.rule=Host(`crud_service.localhost`) && Method(`DELETE`, `POST`)"
     - "traefik.http.routers.cud_service.middlewares=service-auth"
2 Likes

Thank you for your answer.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.