envoy icon indicating copy to clipboard operation
envoy copied to clipboard

Behavior of Ext Authz with gRPC bidi stream

Open mipsel64 opened this issue 2 years ago • 5 comments

Hi everyone,

I'm wondering about the behavior of ext_authz with gRPC bidirectional streams. When I tested it with a normal gRPC request, everything was fine. However, with the bidi stream, it seems like Envoy doesn't forward it to the ext_authz. Additionally, the stream is also not forwarded to my upstream.

I'm using Envoy version 1.26.6.

Has anyone encountered this issue or have any insights on how to address it?

My `ext_authz` config
  {
    "name": "envoy.filters.http.ext_authz",
    "typed_config": {
      "@type": "type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthz",
      "grpc_service": {
        "envoy_grpc": {
          "cluster_name": "waf-grpc"
        },
        "timeout": "0.100s"
      },
      "failure_mode_allow": true,
      "with_request_body": {
        "max_request_bytes": 512000,
        "allow_partial_message": true
      },
      "transport_api_version": "V3",
      "stat_prefix": "waf_stats",
      "bootstrap_metadata_labels_key": "PILOT_METADATA"
    }
  }
  
  ---
  # waf-grpc cluster
  {
    "@type": "type.googleapis.com/envoy.admin.v3.ClustersConfigDump.StaticCluster",
    "cluster": {
      "@type": "type.googleapis.com/envoy.config.cluster.v3.Cluster",
      "name": "waf-grpc",
      "type": "STRICT_DNS",
      "connect_timeout": "1s",
      "max_requests_per_connection": 1,
      "circuit_breakers": {
        "thresholds": [
          {
            "max_connections": 100000,
            "max_pending_requests": 100000,
            "max_requests": 100000
          },
          {
            "priority": "HIGH",
            "max_connections": 100000,
            "max_pending_requests": 100000,
            "max_requests": 100000
          }
        ]
      },
      "upstream_connection_options": {
        "tcp_keepalive": {
          "keepalive_time": 300
        }
      },
      "load_assignment": {
        "cluster_name": "waf-grpc",
        "endpoints": [
          {
            "lb_endpoints": [
              {
                "endpoint": {
                  "address": {
                    "socket_address": {
                      "address": "waf.test.svc.cluster.local",
                      "port_value": 18050
                    }
                  }
                }
              }
            ]
          }
        ]
      },
      "typed_extension_protocol_options": {
        "envoy.extensions.upstreams.http.v3.HttpProtocolOptions": {
          "@type": "type.googleapis.com/envoy.extensions.upstreams.http.v3.HttpProtocolOptions",
          "explicit_http_config": {
            "http2_protocol_options": {}
          }
        }
      }
    },
  }

mipsel64 avatar Jul 10 '24 08:07 mipsel64

After a few hours of investigation, I found the issue, which is the with_request_body setting. Since the request is a bidi stream, it seems that Envoy waits to read the request body when this setting is enabled.

mipsel64 avatar Jul 10 '24 11:07 mipsel64

cc @tyxia @yanavlasov

nezdolik avatar Jul 10 '24 12:07 nezdolik

Ok, I worked around this issue by applying a lua filter before the ext_authz filter. The lua filter extracts the request body and sets it into the dynamic metadata, and then ext_authz uses it for the check request.

However, it would be better if we had a way to make this configurable, as I am concerned that the lua filter might increase request latency.

mipsel64 avatar Jul 10 '24 15:07 mipsel64

This issue has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in the next 7 days unless it is tagged "help wanted" or "no stalebot" or other activity occurs. Thank you for your contributions.

github-actions[bot] avatar Aug 09 '24 16:08 github-actions[bot]

This issue has been automatically closed because it has not had activity in the last 37 days. If this issue is still valid, please ping a maintainer and ask them to label it as "help wanted" or "no stalebot". Thank you for your contributions.

github-actions[bot] avatar Aug 16 '24 16:08 github-actions[bot]