Repository navigation
router: add support for inverse header matching - #3443
Conversation
Signed-off-by: Matthew Gumport <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
Thanks for working on this! High level API comment to get started.
|
|
||
| // If specified, header match will be performed based on if the header value is *not* the value | ||
| // specified or if the header is not present. | ||
| string inverse_match = 7; |
There was a problem hiding this comment.
Instead of adding a new match type here, I would recommend adding a boolean value outside of the oneof called something like invert_match or something like that. Then you can just negate any of the match types. I think that would be more generally useful. WDYT?
There was a problem hiding this comment.
I think that's simpler to use and much more useful. 👍
ba3ef05 to
00fc2e8
Compare
Signed-off-by: Matthew Gumport <[email protected]>
|
|
||
| // If specified, header match will be performed based on if the header value is *not* the value | ||
| // specified or if the header is not present. Defaults to false. | ||
| google.protobuf.BoolValue invert_match = 7; |
There was a problem hiding this comment.
quick nit: This can be a primitive bool type since it defaults to false.
| } | ||
|
|
||
| // If specified, header match will be performed based on if the header value is *not* the value | ||
| // specified or if the header is not present. Defaults to false. |
There was a problem hiding this comment.
nit: 1 space after period (@alyssawilk @htuch did our format checker somehow stop working for the proto comments or did it never work)?
There was a problem hiding this comment.
SUFFIXES in tools/check_format doesn't currently do protos. I can take a look
Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
alyssawilk
left a comment
There was a problem hiding this comment.
LGTM. Matt, any final requests?
| envoy.type.Int64Range range_match = 6; | ||
| } | ||
|
|
||
| // If specified, header match will be performed based on if the header value is *not* the value |
There was a problem hiding this comment.
nit: I would rephrase this to be a bit more generic as we may add future condition types and for it to better cover regex. For example: "If specified, the match result will be inverted before checking. E.g., does the regex not match, is the header value not present, etc.
| } | ||
|
|
||
| // If specified, header match will be performed based on if the header value is *not* the value | ||
| // specified or if the header is not present. Defaults to false. |
There was a problem hiding this comment.
The fact that the inversion match will match if the header is not present at all might be confusing to people. Thoughts? I wonder if that should be the case or if we should have an explicit match type for "present" or something like that?
There was a problem hiding this comment.
It bothers me, especially when looking at tests for large numbers of routes and seeing how many requests the inverse one matches. The original request was for this behavior, and I didn't want to overthink it on my second PR. :-)
I'll add a "present" match type as well to make this more clear as you suggest.
and invert_match is no longer a guaranteed match on a missing header Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
| envoy.type.Int64Range range_match = 6; | ||
|
|
||
| // If specified, header match will be be performed based on whether the header is in the request. | ||
| bool present_match = 7; |
There was a problem hiding this comment.
The docs read as if the default behavior when header_match_specifier is missing is to act as if present_match is true, but really the behavior is to act as if exact_match is the empty string, which still makes using invert_match confusing: an empty exact_match and invert_match enabled will never match any request (by my reading).
I think we could fix this by changing the default behavior -- no one can be using invert_match now and present_match should behave like empty exact_match. Then going forward invert_match works sensibly. (Changing the default after invert_match is in the wild could break someone.)
There was a problem hiding this comment.
This is tricky because it moves the value field from deprecated to broken.
value was deprecated in 1.6.0 and this would be for 1.7.0, so I think it's okay to break this, but would appreciate anyone confirming.
There was a problem hiding this comment.
I don't think we should break any existing behavior. Sorry, I don't think I fully grok the discussion. Is there a way to fix the concerns without breaking existing routing behavior?
There was a problem hiding this comment.
Late me try to restate my concern: the docs on the proto say the default behavior is to check for header presence when there is no header_match_specifier set (and really it also means when no value is set). That all works fine on master. After this change (setting aside the latest commits that change this behavior), it continues to work as documented unless you also set invert_match at which point no request will ever match: the HeaderMatchType will be Value, so the presence check is done and no header will result in a match failure (though if you set present = true it will work).
So one way to fix this is just make it clear that the default behavior is really exact_match = "" and that it will match any header value, but cannot be inverted. That seems a bit weird to me, but it would be fine.
I think the current changes can work with the docs unchanged if the default case only sets the HeaderMatchType to Present when "value" is the empty string.
Signed-off-by: Matthew Gumport <[email protected]>
Signed-off-by: Matthew Gumport <[email protected]>
"Speculative" because I'm not 100% sure that this is the right thing to do/if this follows the breaking changes policy. Would be worthwhile to go back through and clean up all header tests which use the value matching instead of exact_match if that's going to be deleted. Signed-off-by: Matthew Gumport <[email protected]>
| } else { | ||
| header_match_type_ = HeaderMatchType::Value; | ||
| value_ = config.value(); | ||
| header_match_type_ = HeaderMatchType::Present; |
There was a problem hiding this comment.
To clarify my other comment, I think we want:
if (/* config.regex handling */) {
// ...
} else if (config.value().empty()) {
// e.g. no HeaderMatchSpecifier was set (or an unknown one) and value is ""
header_match_type_ = HeaderMatchType::Present;
} else {
header_match_type_ = HeaderMatchType::Value;
value_ = config.value();
}
There was a problem hiding this comment.
Thanks for the clarification. This makes sense to me.
Signed-off-by: Matthew Gumport <[email protected]>
mattklein123
left a comment
There was a problem hiding this comment.
This is great, thanks. Thanks @zuercher for the detailed code reviews!
Description:
This adds an
invert_matchconfig option for header matching to invert the behavior of all other header match specifiers, and apresent_matchconfig option for header matching clearly on the existence of a header.Risk Level: Medium
Testing:
New unit tests, added to existing tests.
Docs Changes:
Inline with the proto change.
Release Notes:
Noted the new options.
Fixes #2101