Skip to content

router: add support for inverse header matching - #3443

Merged
mattklein123 merged 14 commits into
envoyproxy:masterfrom
gumpt:master
May 25, 2018
Merged

mattklein123 merged 14 commits into
envoyproxy:masterfrom
gumpt:master

Conversation

@gumpt

@gumpt gumpt commented May 19, 2018 •

Copy link
Copy Markdown
Member

Description:
This adds an invert_match config option for header matching to invert the behavior of all other header match specifiers, and a present_match config 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

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for working on this! High level API comment to get started.

Comment thread api/envoy/api/v2/route/route.proto Outdated

// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think that's simpler to use and much more useful. 👍

@gumpt
gumpt force-pushed the master branch 2 times, most recently from ba3ef05 to 00fc2e8 Compare May 21, 2018 04:56
@zuercher zuercher self-assigned this May 21, 2018
Comment thread api/envoy/api/v2/route/route.proto Outdated

// 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;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

quick nit: This can be a primitive bool type since it defaults to false.

Comment thread api/envoy/api/v2/route/route.proto Outdated
}

// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: 1 space after period (@alyssawilk @htuch did our format checker somehow stop working for the proto comments or did it never work)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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
alyssawilk previously approved these changes May 22, 2018

@alyssawilk alyssawilk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. Matt, any final requests?

Comment thread api/envoy/api/v2/route/route.proto Outdated
envoy.type.Int64Range range_match = 6;
}

// If specified, header match will be performed based on if the header value is *not* the value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread api/envoy/api/v2/route/route.proto Outdated
}

// 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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

@gumpt gumpt May 22, 2018 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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]>
gumpt added 4 commits May 22, 2018 17:43
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;

@zuercher zuercher May 23, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

@zuercher zuercher May 24, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

gumpt added 4 commits May 23, 2018 17:10
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;

@zuercher zuercher May 24, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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();
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the clarification. This makes sense to me.

Signed-off-by: Matthew Gumport <[email protected]>

@zuercher zuercher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks great. Thanks!

@mattklein123 mattklein123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is great, thanks. Thanks @zuercher for the detailed code reviews!

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants