Skip to content

Applying L7 filters after TCP tunneling #24724

Open

Description

@ohadvano

I am upgrading a TCP stream to HTTP/2 using the TCP tunneling feature. Is there any way to support applying a L7 filter to the output of the tunneling, without creating another listener?
Currently it seems like the only way to do this, is routing the output of the first listener (that has the tcp_proxy filter) to a second listener where there's the HTTP connection manager filter.

Activity

  1. added
    triage
    on Jan 2, 2023
  2. soulxu commented on Jan 3, 2023

    @soulxu
    Member

    there is no way to do that today. I remember there is another issue about nest filter chain #18035, I thought that can do the thing you asked. cc @kyessenov may know the background.

  3. added
    question
    and removed
    triage
    on Jan 3, 2023
  4. kyessenov commented on Jan 3, 2023

    @kyessenov
    Contributor

    I think upstream HTTP filters would work better here? This is a new feature, but seems like the right fit to avoid another listener.

  5. ohadvano commented on Jan 5, 2023

    @ohadvano
    ContributorAuthor

    @kyessenov I tried adding an upstream HTTP filter, for some reason it doesn't hit any of the callbacks. I saw that this feature is in alpha. Does it need to be enabled with some runtime flag?

  6. kyessenov commented on Jan 5, 2023

    @kyessenov
    Contributor

    cc @alyssawilk

    The feature should be enabled via xDS config. L7 filter needs to be registered as an upstream HTTP filter internally in the code, and not every HTTP filter has been registered. Do you have some trace log to share?

  7. ohadvano commented on Jan 5, 2023

    @ohadvano
    ContributorAuthor

    @kyessenov I tried using the buffer filter which is also registered as an upstream filter (modified it by printing some stuff in the filter callbacks and none of them were printed). The trace log does not show anything about the buffer filter. What do you mean enabling it by the xDS config? Can you give me an example? This is possibly what makes it not work..

  8. kyessenov commented on Jan 5, 2023

    @kyessenov
    Contributor

    By xDS config I mean the config file that you use to run Envoy, the sample here.

  9. ohadvano commented on Jan 5, 2023

    @ohadvano
    ContributorAuthor

    @kyessenov I tried it exactly as in the example you sent. I added prints in the "buffer" filter constructor and in "decodeHeaders". None of them were printed. It might have something to do with me using the TCP proxy filter with tunneling feature? Looking at its code, seems like it has a custom upstream.

  10. ohadvano commented on Jan 9, 2023

    @ohadvano
    ContributorAuthor

    @kyessenov pinging again about this. Would appreciate your advice on how to proceed here, I am trying to understand whether I have configured something incorrectly or can you confirm that this should work even if using the TCP tunneling feature?

  11. kyessenov commented on Jan 9, 2023

    @kyessenov
    Contributor

    You might be right that the upstream filters only work for HCM. @alyssawilk probably knows best. We can treat this issue as a feature request to support other proxies on the downstream for HTTP upstreams with filters.

  12. alyssawilk commented on Jan 9, 2023

    @alyssawilk
    Contributor

    yeah I think it's not yet implemented yet for tunneled sessions.

  13. ohadvano commented on Jan 10, 2023

    @ohadvano
    ContributorAuthor

    @alyssawilk would it be possible to support it for tunneled sessions? I can try implementing this myself, but would appreciate hints on where should I start. What bothers me is that it seems like the tcp_proxy uses a custom upstream to manage tunneled sessions

  14. alyssawilk commented on Jan 10, 2023

    @alyssawilk
    Contributor

    If you're game to write the code I'm game to review but it's going to be a pretty complicated project.

    Largely I think we'd want the HttpUpstream class in source/common/tcp_proxy/upstream.* to move towards code sharing or code reuse of UpstreamRequest in source/common/router/upstream_request.*
    If I were doing it I'd probably start by prototyping having HttpUpstream implement RouterFilterInterface and own a HttpUpstream (with no filters - just trying to get the data flow working), then possibly split that into a few PRs of cleaning up interfaces and existing code, and the submitting the new functionality as flag guarded feature. Once that's all hanging together, you could add in the complexity of filters and all the e2e tests to make sure resets and buffering work as expected.

  15. ohadvano commented on Jan 10, 2023

    @ohadvano
    ContributorAuthor

    This seems like a major change. I don't have enough capacity for this at the moment, but I'll keep this in mind. Thanks :)

  16. github-actions commented on Feb 10, 2023

    @github-actions

    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.

  17. added
    stale
    on Feb 10, 2023
  18. ohadvano commented on Feb 10, 2023

    @ohadvano
    ContributorAuthor

    @alyssawilk can you please mark this as help-wanted?

  19. removed
    stale
    on Feb 10, 2023
  20. added
    help wanted
    enhancement
    and removed
    question
    on Feb 10, 2023
  21. ohadvano commented on Mar 4, 2023

    @ohadvano
    ContributorAuthor

    @alyssawilk @kyessenov as I see it there are two options to support this feature for tunneled session, either supporting upstream filters as per alyssa suggestion, or supporting "http_filters: []" field in tunneling_config, so it would be part of the upstream implementation itself. Is there a preferred way to support this from your perspective?

  22. alyssawilk commented on Mar 6, 2023

    @alyssawilk
    Contributor

    Sorry I don't understand how adding filters to the tunneling config would help. something still has to instantiate the filters and run the filter chain.

  23. ohadvano commented on Mar 6, 2023

    @ohadvano
    ContributorAuthor

    I meant, adding filters to the tunneling config and supporting this by code, meaning that tcp_proxy could also support L7 filters in the filter config, in case tunneling is applied, same as HCM is defined as a L4 filter, but has a config for the L7 filters. I guess this would require a lot more coding to support, but I'm asking which method should be more user-approaching?

  24. alyssawilk commented on Mar 6, 2023

    @alyssawilk
    Contributor

    I think by default tunneled traffic to a cluster would use the filter chain of the cluster, but there should be some mechanism for override in case originally-L7 traffic ought to have a different filter chain from newly-encapped traffic. I don't have strong feelings about where the override config should live - I leave that up to API shepherds :-)

  25. ohadvano commented on Mar 6, 2023

    @ohadvano
    ContributorAuthor

    I think I confused with my answer, let me rephrase.
    Putting tcp_proxy aside, for HTTP case there are two places where you could use HTTP filters:

    1. In the downstream filter chain (attached to the HCM filter).
    2. In the upstream filters.

    For tcp_proxy with tunneling, however, currently there's no support for HTTP filters, even though on the downstream filters, we have upgraded the stream to HTTP. Therefore, what I tried to suggest is:

    1. Supporting HTTP filters in the tunneling config for tcp_proxy - this way, we can apply L7 filters for tunneled traffic, similar to how HCM is applying L7 filters for HTTP traffic (this needs to be backed by code of course, but I'm trying to layout the user experience)
    2. Supporting upstream filters for tcp_proxy that was upgraded using tunneling config, by the approach you suggested in one of your previous comments here, quoting it here:

    If you're game to write the code I'm game to review but it's going to be a pretty complicated project.

    Largely I think we'd want the HttpUpstream class in source/common/tcp_proxy/upstream.* to move towards code sharing or code reuse of UpstreamRequest in source/common/router/upstream_request.* If I were doing it I'd probably start by prototyping having HttpUpstream implement RouterFilterInterface and own a HttpUpstream (with no filters - just trying to get the data flow working), then possibly split that into a few PRs of cleaning up interfaces and existing code, and the submitting the new functionality as flag guarded feature. Once that's all hanging together, you could add in the complexity of filters and all the e2e tests to make sure resets and buffering work as expected.

    WDYT?

  26. alyssawilk commented on Mar 6, 2023

    @alyssawilk
    Contributor

    "For tcp_proxy with tunneling, currently there's no support for HTTP filters, even though on the downstream filters, we have upgraded the stream to HTTP. Therefore, what I tried to suggest is:"

    For TCP proxy with tunneling, the main processing engine is TCP. We only do L7 upstream. So there's no way to do the moral equivalent of downstream filters, we can only do upstream filters.

    We can configure the filter chain based on downstream, or upstream, but they're always going to be upstream filters.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/http_filterenhancementhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions