Full Set Of Changes For Pattern Match and Rewrite (#22207)

This PR will implement issue detailed here and described below: #7763

Match Patterns and Templates

Wildcard support based on match patterns and templates.

A match pattern matches an incoming URL path.
Match patterns support glob operators to match URL text and variable definitions to bind matched text to names.

Template patterns are used to re-write URLs.
Template patterns build new URLs and may reference variables bound by a match pattern.

Match Examples
/**.m3u8 would match /foo.m3u8 and /foo/bar.m3u8.
/{dir_name}/*.ts would match /example/file.ts and bind dir_name="example" for a later template match to use.
/{dir_name}/**.ts would match /example/path/file.ts and bind dir_name="example" for a later template match to use. This would also match /example/.ts, which may or may not be a desired behavior.
/{path=v1/*}/{file=*.ts} would match /v1/example/movie.ts (binding path="v1/example" and file="movie"), but would not match /v0/example/movie.ts.
See post for full details and example:
#7763 (comment)

Risk Level:
Testing:
Unit tests. Both both internal matching/rewrite library and config/data plane changes.

Signed-off-by: silverstar195 <seanmaloney@google.com>

Mirrored from https://github.com/envoyproxy/envoy @ 8cfc61f916cf52ce8bce6710686e9d4fca2c06bd
pull/626/head
data-plane-api(Azure Pipelines) 2 years ago
parent 3c63f5aca1
commit cd75a08b73
  1. 4
      BUILD
  2. 18
      envoy/config/route/v3/route_components.proto
  3. 0
      envoy/extensions/path/match/uri_template/v3/BUILD
  4. 14
      envoy/extensions/path/match/uri_template/v3/uri_template_match.proto
  5. 0
      envoy/extensions/path/rewrite/uri_template/v3/BUILD
  6. 14
      envoy/extensions/path/rewrite/uri_template/v3/uri_template_rewrite.proto
  7. 4
      versioning/BUILD

@ -243,8 +243,8 @@ proto_library(
"//envoy/extensions/network/dns_resolver/cares/v3:pkg",
"//envoy/extensions/network/dns_resolver/getaddrinfo/v3:pkg",
"//envoy/extensions/network/socket_interface/v3:pkg",
"//envoy/extensions/path/match/pattern_template/v3:pkg",
"//envoy/extensions/path/rewrite/pattern_template/v3:pkg",
"//envoy/extensions/path/match/uri_template/v3:pkg",
"//envoy/extensions/path/rewrite/uri_template/v3:pkg",
"//envoy/extensions/quic/crypto_stream/v3:pkg",
"//envoy/extensions/quic/proof_source/v3:pkg",
"//envoy/extensions/rate_limit_descriptors/expr/v3:pkg",

@ -572,8 +572,7 @@ message RouteMatch {
// Expect the value to not contain ``?`` or ``#`` and not to end in ``/``
string path_separated_prefix = 14 [(validate.rules).string = {pattern: "^[^?#]+[^?#/]$"}];
// [#not-implemented-hide:]
// [#comment: TODO(silverstar195): Hook into extension once added]
// [#extension-category: envoy.path.match]
core.v3.TypedExtensionConfig path_match_policy = 15;
}
@ -1030,9 +1029,9 @@ message RouteAction {
// place the original path before rewrite into the :ref:`x-envoy-original-path
// <config_http_filters_router_x-envoy-original-path>` header.
//
// Only one of :ref:`regex_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.regex_rewrite>` or
// [#comment:TODO(silverstar194) add the following once implemented: :ref:`path_rewrite_policy <envoy_v3_api_field_config.route.v3.RouteAction.path_rewrite_policy>`]
// :ref:`prefix_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.prefix_rewrite>` may be specified.
// Only one of :ref:`regex_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.regex_rewrite>`
// :ref:`path_rewrite_policy <envoy_v3_api_field_config.route.v3.RouteAction.path_rewrite_policy>`,
// or :ref:`prefix_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.prefix_rewrite>` may be specified.
//
// .. attention::
//
@ -1067,9 +1066,9 @@ message RouteAction {
// before the rewrite into the :ref:`x-envoy-original-path
// <config_http_filters_router_x-envoy-original-path>` header.
//
// Only one of :ref:`regex_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.regex_rewrite>`
// or :ref:`prefix_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.prefix_rewrite>`
// [#comment:TODO(silverstar194) add the following once implemented: :ref:`path_rewrite_policy <envoy_v3_api_field_config.route.v3.RouteAction.path_rewrite_policy>`]
// Only one of :ref:`regex_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.regex_rewrite>`,
// :ref:`prefix_rewrite <envoy_v3_api_field_config.route.v3.RouteAction.prefix_rewrite>`, or
// :ref:`path_rewrite_policy <envoy_v3_api_field_config.route.v3.RouteAction.path_rewrite_policy>`]
// may be specified.
//
// Examples using Google's `RE2 <https://github.com/google/re2>`_ engine:
@ -1090,8 +1089,7 @@ message RouteAction {
// ``/aaa/yyy/bbb``.
type.matcher.v3.RegexMatchAndSubstitute regex_rewrite = 32;
// [#not-implemented-hide:]
// [#comment: TODO(silverstar195): Hook into extension once added]
// [#extension-category: envoy.path.rewrite]
core.v3.TypedExtensionConfig path_rewrite_policy = 41;
oneof host_rewrite_specifier {

@ -1,17 +1,18 @@
syntax = "proto3";
package envoy.extensions.path.match.pattern_template.v3;
package envoy.extensions.path.match.uri_template.v3;
import "udpa/annotations/status.proto";
import "validate/validate.proto";
option java_package = "io.envoyproxy.envoy.extensions.path.match.pattern_template.v3";
option java_outer_classname = "PatternTemplateMatchProto";
option java_package = "io.envoyproxy.envoy.extensions.path.match.uri_template.v3";
option java_outer_classname = "UriTemplateMatchProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/match/pattern_template/v3;pattern_templatev3";
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/match/uri_template/v3;uri_templatev3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;
// [#protodoc-title: Pattern Template Match Config]
// [#protodoc-title: Uri Template Match Config]
// [#extension: envoy.path.match.uri_template.uri_template_matcher]
// If specified, the route is a template match rule meaning that the
// ``:path`` header (without the query string) must match the given
@ -38,7 +39,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// * ``/videos/{file}`` would match ``/videos/1080p5000_00001.m4s``
//
// * ``/**.mpd`` would match ``/content/123/india/dash/55/manifest.mpd``
// [#not-implemented-hide:]
message PatternTemplateMatchConfig {
message UriTemplateMatchConfig {
string path_template = 1 [(validate.rules).string = {min_len: 1 max_len: 256}];
}

@ -1,17 +1,18 @@
syntax = "proto3";
package envoy.extensions.path.rewrite.pattern_template.v3;
package envoy.extensions.path.rewrite.uri_template.v3;
import "udpa/annotations/status.proto";
import "validate/validate.proto";
option java_package = "io.envoyproxy.envoy.extensions.path.rewrite.pattern_template.v3";
option java_outer_classname = "PatternTemplateRewriteProto";
option java_package = "io.envoyproxy.envoy.extensions.path.rewrite.uri_template.v3";
option java_outer_classname = "UriTemplateRewriteProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/rewrite/pattern_template/v3;pattern_templatev3";
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/path/rewrite/uri_template/v3;uri_templatev3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;
// [#protodoc-title: Pattern Template Rewrite Config]
// [#protodoc-title: Uri Template Rewrite Config]
// [#extension: envoy.path.rewrite.uri_template.uri_template_rewriter]
// Indicates that during forwarding, portions of the path that match the
// pattern should be rewritten, even allowing the substitution of variables
@ -52,7 +53,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;
// * The path pattern ``/content/{format}/{lang}/{id}/{file}.vtt`` paired with a substitution
// string of ``/{lang}/{format}/{file}.vtt`` would transform ``/content/hls/en-us/12345/en_193913.vtt``
// into ``/en-us/hls/en_193913.vtt``.
// [#not-implemented-hide:]
message PatternTemplateRewriteConfig {
message UriTemplateRewriteConfig {
string path_template_rewrite = 1 [(validate.rules).string = {min_len: 1 max_len: 256}];
}

@ -186,8 +186,8 @@ proto_library(
"//envoy/extensions/network/dns_resolver/cares/v3:pkg",
"//envoy/extensions/network/dns_resolver/getaddrinfo/v3:pkg",
"//envoy/extensions/network/socket_interface/v3:pkg",
"//envoy/extensions/path/match/pattern_template/v3:pkg",
"//envoy/extensions/path/rewrite/pattern_template/v3:pkg",
"//envoy/extensions/path/match/uri_template/v3:pkg",
"//envoy/extensions/path/rewrite/uri_template/v3:pkg",
"//envoy/extensions/quic/crypto_stream/v3:pkg",
"//envoy/extensions/quic/proof_source/v3:pkg",
"//envoy/extensions/rate_limit_descriptors/expr/v3:pkg",

Loading…
Cancel
Save