Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct response/Redirect with ext_authz #14984

Closed
artificial-aidan opened this issue Feb 8, 2021 · 7 comments
Closed

Direct response/Redirect with ext_authz #14984

artificial-aidan opened this issue Feb 8, 2021 · 7 comments
Assignees

Comments

@artificial-aidan
Copy link

artificial-aidan commented Feb 8, 2021

Title: Unable to run ext_authz filter with direct response and redirect.

Description:
From how I read #8436 I should be able to set up a direct response and have it handled by the authorization filter. But when I set it up as follows no call is made to the ext_authz filter, and it just responds as specified

- name: envoy.filters.network.http_connection_manager
  typed_config:
    "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
    codec_type: auto
    stat_prefix: ingress_http
    route_config:
      name: local_route
      virtual_hosts:
        - name: local_service
          domains: ["*"]
          typed_per_filter_config:
            envoy.filters.http.ext_authz:
              "@type": type.googleapis.com/envoy.extensions.filters.http.ext_authz.v3.ExtAuthzPerRoute
              check_settings:
                context_extensions:
                  virtual_host: local_service
          routes:
            - match: { path: "/auth-check" }
              direct_response:
                status: 200
            - match: { prefix: "/old-path" }
              redirect:
                path_redirect: "/new-path"
            - match: { prefix: "/" }
              route:
                cluster: upstream
    http_filters:
      - 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: ext_authz-grpc-service
            timeout: 0.250s
          failure_mode_allow: false
          transport_api_version: V3
@artificial-aidan artificial-aidan added bug triage Issue requires triage labels Feb 8, 2021
@esmet
Copy link
Contributor

esmet commented Feb 9, 2021

I took a look at this and figured out that the ext_authz filter is invoked in this case, but it does nothing because it cannot find a route entry:

Filter::PerRouteFlags Filter::getPerRouteFlags(const Router::RouteConstSharedPtr& route) const {
  if (route == nullptr || route->routeEntry() == nullptr) {
    return PerRouteFlags{true /*skip_check_*/, false /*skip_request_body_buffering_*/};
  }
...

To support direct replies, we'd need to also check for route->directResponseEntry(). I can't think of a reason why direct entries shouldn't work here so I think this is just a bug that should be fixed. Operators can still configure direct response entries that skip ext_authz by providing a per-route config that disables the filter.

@esmet
Copy link
Contributor

esmet commented Feb 9, 2021

/assign

@esmet
Copy link
Contributor

esmet commented Feb 9, 2021

This bit in the ext_authz.cc filter seems to do the trick:

 Filter::PerRouteFlags Filter::getPerRouteFlags(const Router::RouteConstSharedPtr& route) const {
-  if (route == nullptr || route->routeEntry() == nullptr) {
-    return PerRouteFlags{true /*skip_check_*/, false /*skip_request_body_buffering_*/};
+  if (route == nullptr) {
+    // If there's no route, skip authorization checks. This is an optimization to avoid work
+    // if we know the request won't be forwarded upstream anyway.
+    return PerRouteFlags::SkipCheckFlags();
+  }
+
+  if (route->routeEntry() == nullptr && route->directResponseEntry() == nullptr) {
+    // If there's a route, but no route entry nor direct response entry, then skip authorization
+    // checks. This is another optimization.
+    return PerRouteFlags::SkipCheckFlags();
   }

@mattklein123 mattklein123 removed the triage Issue requires triage label Feb 12, 2021
@github-actions
Copy link

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 github-actions bot added the stale stalebot believes this issue/PR has not been touched recently label Mar 14, 2021
@github-actions
Copy link

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.

@esmet
Copy link
Contributor

esmet commented Mar 22, 2021

Can we unstale this and associate it with a work in progress #14989?

@mattklein123 mattklein123 reopened this Mar 22, 2021
@mattklein123 mattklein123 added the help wanted Needs help! label Mar 22, 2021
@github-actions github-actions bot removed the stale stalebot believes this issue/PR has not been touched recently label Jun 11, 2021
@soulxu
Copy link
Member

soulxu commented Aug 17, 2021

This is fixed by #17546

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants