router: implement new regex_rewrite route action#10050
router: implement new regex_rewrite route action#10050lizan merged 16 commits intoenvoyproxy:masterfrom jphx:regex-rewrite
Conversation
Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
…king rules Signed-off-by: James Hennessy <jph@us.ibm.com>
|
xref: #2092 |
|
Actually, it doesn't fix #2092. That issue is asking for a rewrite while redirecting. This change is for rewriting when forwarding. |
|
Assigning @mattklein123 -- I think we should review the API change first and then the code to match. From my point of view, I think we'll want to add My other thought was that it might make sense to consider whether this rewrite should be separate from RouteMatch or not. On the one hand this allows a simple match (say |
|
I thought about whether the regular expression should be the There's also more flexibility in allowing a completely different regular expression, and processing it even if there's a prefix match or a full path match, instead of a regular expression match. Also, the |
mattklein123
left a comment
There was a problem hiding this comment.
At a high level this LGTM and will defer to @zuercher for review. Thank you for working on this!
| XSS | ||
| YAML | ||
| ZXID | ||
| aaa |
There was a problem hiding this comment.
@zuercher we really need to fix this. If you are up for a tech debt item can you potentially add some type of escape hatch to the spell checker that turns it off and on like we have for other format things? I think there is an issue tracking this.
There was a problem hiding this comment.
Would it be feasible to skip the spell check for text inside double back ticks?
There was a problem hiding this comment.
Yes I'm going to work on that next.
This updates the descriptions of prefix_rewrite and regex_rewrite to say that only one should be specified, and that prefix_rewrite takes precedence if both are. It also moved the bullet in version_history.rst to the "router" section, so they're in alphabetical order. Signed-off-by: James Hennessy <jph@us.ibm.com>
Also add an annotation to the v3 proto files indicating that prefix_rewrite and regex_rewrite will be migrated in v4 to a "oneof" choice called path_rewrite. Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
|
Fyi, I merged the |
zuercher
left a comment
There was a problem hiding this comment.
Thanks for bearing with us! Some comments below, but mostly looks good.
There was a problem hiding this comment.
Oops, I guess based on host_rewrite_specifier these should be path_rewrite_specifier. I thought the name in the docs was descriptive.
There was a problem hiding this comment.
Sure. I notice there's already a path_rewrite_specifier in the RedirectAction section.
There was a problem hiding this comment.
I think that's fine for that to be repeated in different types.
It does strike me that someone will eventually want to use RegexRewrite in RedirectAction.
@mattklein123: should we move RegexWrite so that it's not nested within RouteAction? And if so, the name might need to be a little more specific to paths, like RegexPathRewrite.
(@jphx sorry again for this piecemeal approach to the API review -- the maintainer with the best vision for this is currently unavailable.)
There was a problem hiding this comment.
Not a problem. I'm willing to make whatever changes are best for Envoy (within reason!).
There was a problem hiding this comment.
We seem to have stalled on this review. Is there anything I can do to help? Are we waiting for the maintainer with the best vision to be available again?
If desired, I can move the RegexRewrite message out of the RouteAction message so that it can be more easily re-used in the RedirectAction message. Or it could be moved out of the file altogether.
There was a problem hiding this comment.
I don't think we are stalled. @lizan had a comment below. Can you take a look at that and we can move forward?
There was a problem hiding this comment.
His comment was asking if the RegexRewrite message should be moved out of the file altogether and made a generic type. It was my impression he was looking for the opinion of other maintainers, since it is a strategy question. Surely you don't want me to decide the answer to that question.
If you all agree this is what should be done, then I would be happy to make that change.
Signed-off-by: James Hennessy <jph@us.ibm.com>
Signed-off-by: James Hennessy <jph@us.ibm.com>
|
I'm not sure why the command does the same thing to the files in my working copy. Any suggestions? |
|
Hm. I guess that format error means the upda annotation needs to go in the v2 version as well. That doesn't seem logical to me, but I think it might be a corner case of v2/v3 coexisting. Soon v2 will be frozen and we won't allow changes there anymore and the auto-translation will get turned off. |
|
Also, please avoid force-pushes in the future. They make tracking incremental PR changes harder and we squash PRs onto master so the dirty commit history in the PR won't be reflected on master. |
|
Sorry about the forced pushes. I've used them only to amend commit messages to add the signoff. I seem to have trouble remembering the use the |
|
I looked into:
but adding the Earlier, @mattklein123 said:
So maybe this annotation needs to be added sometime later? |
|
I merged again from |
| google.protobuf.BoolValue enabled = 2; | ||
| } | ||
|
|
||
| // Describe how to match the path and rewrite it using a regular expression |
There was a problem hiding this comment.
Shall we extract this type into envoy.type? I think we're likely to reuse it in other places?
There was a problem hiding this comment.
Looking through this again, yes, I think it makes sense to move this to a matcher. How about RegexMatchAndSubstitute or something like that?
There was a problem hiding this comment.
Looking through this again, yes, I think it makes sense to move this to a matcher. How about RegexMatchAndSubstitute or something like that?
There was a problem hiding this comment.
I merged from the master branch again to resolve some conflicts and made the requested change, renaming the RegexRewrite message to RegexMatchAndSubstitute and making it a general type so it can potentially be re-used elsewhere.
Signed-off-by: James Hennessy <jph@us.ibm.com>
…Substitute. Signed-off-by: James Hennessy <jph@us.ibm.com>
|
|
||
| if (route.route().has_regex_rewrite()) { | ||
| if (!prefix_rewrite_.empty()) { | ||
| throw EnvoyException("Cannot specify both prefix_rewrite and regex_rewrite"); |
There was a problem hiding this comment.
Please a test case for this. You can use EXPECT_THROW_WITH_MESSAGE for testing.
There was a problem hiding this comment.
I've added this test case in the latest commit.
…sage. Also add a test that verifies an exception is raised if both prefix_rewrite and regex_rewrite are specified in a route. Signed-off-by: James Hennessy <jph@us.ibm.com>
|
/retest The coverage test failed, but it looks like the process was killed by a signal. Trying again. |
|
🔨 rebuilding |
|
Thank you everybody! |
I'm seeing a failure in OSS-Fuzz build, as well as fuzz CI tool #10289 due to fuzzing build macro FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION. Basically, PR #10050 introduced regex rewrites that are tested in config_impl_test, which is executed to create the corpus for route_fuzz_test. Fuzz builds are built with the FUZZING_BUILD_MODE... macro, and the RE2 library that does the regex rewrites in the test only does single replacements in fuzzing mode rather than the global replacement in the tests, so the test fails, and the fuzz build fails. This change defined FUZZING_BUILD_MODE... only for fuzzing build rules, and explicitly undefines them for the config_impl_test. RE OSS-Fuzz builds, this is odd. Bazel CLI flags take precedence, so I'm not sure what to do when we build in that environment. I can't seem to #undef in the tests, but I need to come up with some solution.I don't like manually removing the CLI flag in our build script, but maybe? https://github.com/google/oss-fuzz/blob/66e0e379395d3a3ee741b08f4d306e1ed71c4003/infra/base-images/base-clang/Dockerfile Testing: bazel build //test/common/router:route_fuzz_test_with_libfuzzer --config=asan-fuzzer Signed-off-by: Asra Ali <asraa@google.com>
Description:
Support path rewriting using regular expressions and optionally capture groups. This PR is like #8462, but using the safe regular expression support.
Risk Level: Medium, since it slightly modifies the existing
prefix_rewritecode.Testing: Unit tests are added to
test/common/router/config_impl_test.cc, runnable withbazel test //test/common/router:config_impl_testDocs Changes: Any doc that references
prefix_rewritehas been changed to referenceregex_rewriteas well, if appropriate.Release Notes: A bullet is added to
docs/root/intro/version_history.rstmentioning the new support.Notes:
I chose to make
regex_rewritean alternative toprefix_rewrite, withan error being recognized if both are specified. It would also be possible to support both route actions at the same time, applying, say,prefix_rewritetaking precedenceprefix_rewritefirst, and thenregex_rewrite. I didn't implement it this way, though.