-
Notifications
You must be signed in to change notification settings - Fork 5.1k
router: Allow using another header for virtual host matching #41280
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
base: main
Are you sure you want to change the base?
Conversation
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]>
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
@wbpcode - here's the alternate idea that you suggested. |
There was a problem hiding this 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.
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; | ||
} | ||
|
There was a problem hiding this comment.
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.
// 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; |
There was a problem hiding this comment.
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
This adds two things:
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:
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:]