Skip to content

Conversation

pugmajere
Copy link
Contributor

This adds two things:

  • A new RouteConfiguration option that specifies an alternative header to be used instead of :authority/Host when selecting a virtual host
  • A new early header mutation action that provides for regular expression substituion into a different header.

Together, these allow for a "simplification" or "canonicalization" step to be run on :authority, to reduce high cardinality portions of the hostname to be replaced with a static string, without impacting that :authority header that is sent upstream. This provides a way to support multiple wildcards in a URL in a clean way.

Commit Message: router: Allow using another header for virtual host matching
Additional Description:
This adds two things:

  • A new RouteConfiguration option that specifies an alternative header to be used instead of :authority/Host when selecting a virtual host
  • A new early header mutation action that provides for regular expression substituion into a different header.

Together, these allow for a "simplification" or "canonicalization" step to be run on :authority, to reduce high cardinality portions of the hostname to be replaced with a static string, without impacting that :authority header that is sent upstream. This provides a way to support multiple wildcards in a URL in a clean way.

Risk Level:
Testing: added new tests
Docs Changes:
Release Notes:
Platform Specific Features:
[Optional Runtime guard:]
[Optional Fixes #Issue]
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

This adds two things:

- A new RouteConfiguration option that specifies an alternative header
to be used instead of :authority/Host when selecting a virtual host
- A new early header mutation action that provides for regular
expression substituion into a different header.

Together, these allow for a "simplification" or "canonicalization"
step to be run on :authority, to reduce high cardinality portions of
the hostname to be replaced with a static string, without impacting
that :authority header that is sent upstream. This provides a way to
support multiple wildcards in a URL in a clean way.

Signed-off-by: Ryan Anderson <[email protected]>
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @mattklein123
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #41280 was opened by pugmajere.

see: more, trace.

@pugmajere
Copy link
Contributor Author

@wbpcode - here's the alternate idea that you suggested.

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution. And sorry for the delayed response. I am still OOO and cannot review code in time.

Comment on lines +100 to +109
message RegexCopy {
string source_header = 1
[(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

string target_header = 2
[(validate.rules).string = {well_known_regex: HTTP_HEADER_VALUE strict: false}];

type.matcher.v3.RegexMatchAndSubstitute expression = 3;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may needn't this. We have provided regex support in the CEL, you can use CEL substitution formatter to extract something from specific attributes (like request header) as new header value. For simple example:

mutations
- append:
    key: something
    value: '%CEL(re.extract(request.host, '(.+?)\\\\:(\\\\d+)', '\\\\2'))%'

If the cel's support is not enough for you, you may could create a custom early mutation extension for this if possible.

Comment on lines +136 to +141
// Normally, virtual host matching is done using the :authority (or
// Host: in HTTP < 2) HTTP header. Setting this will instead, use a
// different HTTP header for this purpose. This is intended to be
// combined with an "early_header_mutation" extension to allow
// alternate or simplified host values to be used for host matching.
string alternate_header_for_host_matching = 18;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vhost_header is enough. Because most users could get it is header name that will be used for vhost searching from the simple vhost_header.

The comments also could be simplified and needn't to refer the early header mutation. The new feature self should be a general/common feature and needn't be bound to early header mutation

@wbpcode wbpcode added the waiting label Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants