envoy icon indicating copy to clipboard operation
envoy copied to clipboard

Multiple http filters don't work

Open hanyu-liu opened this issue 7 years ago • 3 comments

Multiple http filters don't work

Description: I am trying to have multiple filters of http_connection_manager. The first filter doesn't have a http_filter of "envoy.ext_authz", whereas the second one does. In the ideal world, http requests try to match to the the routing configs in the first filter; if nothing found, try the second filter (with ext_authz).

For example, the OPTIONS request can match a routing in the first filter, the GET request should fall through to the second filter and match a routing in the second filter. However the GET for second filter doesn't work. In the document:

(listener.Filter) A list of individual network filters that make up the filter chain for connections established with the listener. Order matters as the filters are processed sequentially as connection events happen. Note: If the filter list is empty, the connection will close by default.

However, it seems only the first filter works, whereas the ones afterwards don't. Or I miss something?

Repro steps:

$ curl -v localhost:34573/service/2 -X OPTIONS TCP_NODELAY set Connected to localhost (::1) port 34573 (#0) OPTIONS /service/2 HTTP/1.1 Host: localhost:34573 User-Agent: curl/7.54.0 Accept: /

HTTP/1.1 200 OK content-type: text/html; charset=utf-8 allow: HEAD, GET, OPTIONS content-length: 0 server: envoy date: Tue, 12 Feb 2019 17:42:31 GMT x-envoy-upstream-service-time: 8

$ curl -v localhost:34573/service/2 -X GET Note: Unnecessary use of -X or --request, GET is already inferred. TCP_NODELAY set Connected to localhost (::1) port 34573 (#0) GET /service/2 HTTP/1.1 Host: localhost:34573 User-Agent: curl/7.54.0 Accept: /

HTTP/1.1 404 Not Found date: Tue, 12 Feb 2019 18:06:55 GMT server: envoy content-length: 0

Config:

$ curl -v localhost:34573/service/2 -X OPTIONS
* TCP_NODELAY set
* Connected to localhost (::1) port 34573 (#0)
> OPTIONS /service/2 HTTP/1.1
> Host: localhost:34573
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 200 OK
< content-type: text/html; charset=utf-8
< allow: HEAD, GET, OPTIONS
< content-length: 0
< server: envoy
< date: Tue, 12 Feb 2019 17:42:31 GMT
< x-envoy-upstream-service-time: 8


$ curl -v localhost:34573/service/2 -X GET
Note: Unnecessary use of -X or --request, GET is already inferred.
* TCP_NODELAY set
* Connected to localhost (::1) port 34573 (#0)
> GET /service/2 HTTP/1.1
> Host: localhost:34573
> User-Agent: curl/7.54.0
> Accept: */*
> 
< HTTP/1.1 404 Not Found
< date: Tue, 12 Feb 2019 18:06:55 GMT
< server: envoy
< content-length: 0




static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 80
    filter_chains:
    - filters:
      - name: envoy.http_connection_manager
        config:
          codec_type: auto
          stat_prefix: test
          route_config:
            name: local_route
            virtual_hosts:
            - name: backend
              domains:
              - "*"
              routes:
              - match:
                  prefix: "/service/"
                  headers:
                  - name: ":method"
                    exact_match: "OPTIONS"
                route:
                  cluster: service2
          http_filters:
          - name: envoy.router
            config: {}
      - name: envoy.http_connection_manager
        config:
          codec_type: auto
          stat_prefix: test
          route_config:
            name: local_route
            virtual_hosts:
            - name: backend
              domains:
              - "*"
              routes:
              - match:
                  prefix: "/service/"
                route:
                  cluster: service2
          http_filters:
          - name: envoy.ext_authz
            config:
              failure_mode_allow: false
              grpc_service:
                envoy_grpc:
                  cluster_name: tolkien-grpc
          - name: envoy.router
            config: {}
  clusters:
  - name: tolkien-grpc
    connect_timeout: 100.0s
    type: logical_dns
    lb_policy: round_robin
    http2_protocol_options: {}
    hosts:
    - socket_address: {address: tolkien, port_value: 51191}
  - name: service2
    connect_timeout: 0.25s
    type: strict_dns
    lb_policy: round_robin
    http2_protocol_options: {}
    hosts:
    - socket_address:
        address: service2
        port_value: 80
admin:
  access_log_path: "/dev/stdout"
  address:
    socket_address:
      address: 0.0.0.0
      port_value: 8001

Logs:

gateway_1 | [2019-02-12 18:52:54.013][000017][debug][http] [source/common/http/conn_manager_impl.cc:887] [C1][S9848289038741076213] request end stream gateway_1 | [2019-02-12 18:52:54.013][000017][debug][http] [source/common/http/conn_manager_impl.cc:514] [C1][S9848289038741076213] request headers complete (end_stream=true): gateway_1 | ':authority', 'localhost:34573' gateway_1 | ':path', '/service/2' gateway_1 | ':method', 'GET' gateway_1 | 'user-agent', 'curl/7.54.0' gateway_1 | 'accept', '/' gateway_1 | gateway_1 | [2019-02-12 18:52:54.013][000017][debug][router] [source/common/router/router.cc:220] [C1][S9848289038741076213] no cluster match for URL '/service/2' gateway_1 | [2019-02-12 18:52:54.013][000017][debug][http] [source/common/http/conn_manager_impl.cc:1095] [C1][S9848289038741076213] encoding headers via codec (end_stream=true): gateway_1 | ':status', '404' gateway_1 | 'date', 'Tue, 12 Feb 2019 18:52:53 GMT' gateway_1 | 'server', 'envoy'

hanyu-liu avatar Feb 12 '19 18:02 hanyu-liu

What you have here are 2 L4 filter chains in a row. All TCP traffic will go into the first HCM, which will translate it into HTTP and send it upstream. Envoy isn't designed so if route match fails in one HCM it will pass it on to the next network filter.

I believe you can achieve what you're trying for with HCM, one HTTP filter chain with ext_authz always present, then use the ExtAuthzPerRoute config to enable / disable authz on specific routes.

alyssawilk avatar Feb 13 '19 14:02 alyssawilk

@alyssawilk if I can't use envoy.http_connection_manager how can I set certain filters to routes. For example is some routes I need use lua filter but as I understood I can't do it through many envoy.http_connection_manager

Kupstas avatar Jul 05 '19 14:07 Kupstas

See https://github.com/envoyproxy/envoy/issues/6824

mattklein123 avatar Jul 05 '19 17:07 mattklein123