Search code examples
spring-cloudspring-cloud-gateway

Deny access to one particular subpath for spring cloud gateway route


We're using Spring Cloud Gateway in front of our backend services. We have a route similar to the following:

  routes:
    - id: foobar-service
      uri: lb://foobar-service
      predicates:
        - Path=/foobar/**
      filters:
        - StripPrefix=1

We want to deny access to one particular subpath (e.g. /foobar/baz/**) but leave the rest open. Is it possible to do this using the YAML syntax? Perhaps we need to implement the routes using the Fluent API instead?


Solution

  •   routes:
        - id: foobar-baz-service
          uri: no://op
          predicates:
            - Path=/foobar/baz/**
          filters:
            - SetStatus=403
        - id: foobar-service
          uri: lb://foobar-service
          predicates:
            - Path=/foobar/**
          filters:
            - StripPrefix=1