From 205935706567da0d6c358e663a47b09372b73cf9 Mon Sep 17 00:00:00 2001 From: "update-envoy[bot]" <135279899+update-envoy[bot]@users.noreply.github.com> Date: Fri, 8 Mar 2024 16:44:59 +0000 Subject: [PATCH] add extension point for custom StringMatcher, and lua implementation (#32586) Risk Level: Low Testing: New tests Signed-off-by: Greg Greenway Mirrored from https://github.com/envoyproxy/envoy @ f9ec5b8e59de6cf5cafdab2a954b03b83b58c64d --- BUILD | 1 + envoy/extensions/string_matcher/lua/v3/BUILD | 12 ++++++ .../string_matcher/lua/v3/lua.proto | 37 +++++++++++++++++++ envoy/type/matcher/v3/BUILD | 1 + envoy/type/matcher/v3/string.proto | 8 +++- versioning/BUILD | 1 + 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 envoy/extensions/string_matcher/lua/v3/BUILD create mode 100644 envoy/extensions/string_matcher/lua/v3/lua.proto diff --git a/BUILD b/BUILD index 33de22a6..e0efeebc 100644 --- a/BUILD +++ b/BUILD @@ -317,6 +317,7 @@ proto_library( "//envoy/extensions/stat_sinks/graphite_statsd/v3:pkg", "//envoy/extensions/stat_sinks/open_telemetry/v3:pkg", "//envoy/extensions/stat_sinks/wasm/v3:pkg", + "//envoy/extensions/string_matcher/lua/v3:pkg", "//envoy/extensions/tracers/opentelemetry/resource_detectors/v3:pkg", "//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg", "//envoy/extensions/transport_sockets/alts/v3:pkg", diff --git a/envoy/extensions/string_matcher/lua/v3/BUILD b/envoy/extensions/string_matcher/lua/v3/BUILD new file mode 100644 index 00000000..09a37ad1 --- /dev/null +++ b/envoy/extensions/string_matcher/lua/v3/BUILD @@ -0,0 +1,12 @@ +# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. + +load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") + +licenses(["notice"]) # Apache 2 + +api_proto_package( + deps = [ + "//envoy/config/core/v3:pkg", + "@com_github_cncf_xds//udpa/annotations:pkg", + ], +) diff --git a/envoy/extensions/string_matcher/lua/v3/lua.proto b/envoy/extensions/string_matcher/lua/v3/lua.proto new file mode 100644 index 00000000..04c5b36f --- /dev/null +++ b/envoy/extensions/string_matcher/lua/v3/lua.proto @@ -0,0 +1,37 @@ +syntax = "proto3"; + +package envoy.extensions.string_matcher.lua.v3; + +import "envoy/config/core/v3/base.proto"; + +import "udpa/annotations/status.proto"; +import "validate/validate.proto"; + +option java_package = "io.envoyproxy.envoy.extensions.string_matcher.lua.v3"; +option java_outer_classname = "LuaProto"; +option java_multiple_files = true; +option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/string_matcher/lua/v3;luav3"; +option (udpa.annotations.file_status).package_version_status = ACTIVE; + +// [#protodoc-title: Lua StringMatcher] +// A Lua StringMatcher allows executing a Lua script to determine if a string is a match. The configured source +// code must define a function named `envoy_match`. If the function returns true, the string is considered a match. +// Any other result, including an execution error, is considered a non-match. +// +// Example: +// +// .. code-block:: yaml +// +// source_code: +// inline_string: | +// function envoy_match(str) +// -- Do something. +// return true +// end +// +// [#extension: envoy.string_matcher.lua] + +message Lua { + // The Lua code that Envoy will execute + config.core.v3.DataSource source_code = 1 [(validate.rules).message = {required: true}]; +} diff --git a/envoy/type/matcher/v3/BUILD b/envoy/type/matcher/v3/BUILD index 320b988b..bdb648a2 100644 --- a/envoy/type/matcher/v3/BUILD +++ b/envoy/type/matcher/v3/BUILD @@ -9,5 +9,6 @@ api_proto_package( "//envoy/annotations:pkg", "//envoy/type/v3:pkg", "@com_github_cncf_xds//udpa/annotations:pkg", + "@com_github_cncf_xds//xds/core/v3:pkg", ], ) diff --git a/envoy/type/matcher/v3/string.proto b/envoy/type/matcher/v3/string.proto index 2df1bd37..10033749 100644 --- a/envoy/type/matcher/v3/string.proto +++ b/envoy/type/matcher/v3/string.proto @@ -4,6 +4,8 @@ package envoy.type.matcher.v3; import "envoy/type/matcher/v3/regex.proto"; +import "xds/core/v3/extension.proto"; + import "udpa/annotations/status.proto"; import "udpa/annotations/versioning.proto"; import "validate/validate.proto"; @@ -17,7 +19,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE; // [#protodoc-title: String matcher] // Specifies the way to match a string. -// [#next-free-field: 8] +// [#next-free-field: 9] message StringMatcher { option (udpa.annotations.versioning).previous_message_type = "envoy.type.matcher.StringMatcher"; @@ -61,6 +63,10 @@ message StringMatcher { // // * ``abc`` matches the value ``xyz.abc.def`` string contains = 7 [(validate.rules).string = {min_len: 1}]; + + // Use an extension as the matcher type. + // [#extension-category: envoy.string_matcher] + xds.core.v3.TypedExtensionConfig custom = 8; } // If true, indicates the exact/prefix/suffix/contains matching should be case insensitive. This diff --git a/versioning/BUILD b/versioning/BUILD index 86061fda..eb456935 100644 --- a/versioning/BUILD +++ b/versioning/BUILD @@ -256,6 +256,7 @@ proto_library( "//envoy/extensions/stat_sinks/graphite_statsd/v3:pkg", "//envoy/extensions/stat_sinks/open_telemetry/v3:pkg", "//envoy/extensions/stat_sinks/wasm/v3:pkg", + "//envoy/extensions/string_matcher/lua/v3:pkg", "//envoy/extensions/tracers/opentelemetry/resource_detectors/v3:pkg", "//envoy/extensions/tracers/opentelemetry/samplers/v3:pkg", "//envoy/extensions/transport_sockets/alts/v3:pkg",