matcher.proto 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. syntax = "proto3";
  2. package envoy.config.common.matcher.v3;
  3. import "envoy/config/core/v3/extension.proto";
  4. import "envoy/config/route/v3/route_components.proto";
  5. import "envoy/type/matcher/v3/string.proto";
  6. import "xds/annotations/v3/status.proto";
  7. import "udpa/annotations/status.proto";
  8. import "validate/validate.proto";
  9. option java_package = "io.envoyproxy.envoy.config.common.matcher.v3";
  10. option java_outer_classname = "MatcherProto";
  11. option java_multiple_files = true;
  12. option go_package = "github.com/envoyproxy/go-control-plane/envoy/config/common/matcher/v3;matcherv3";
  13. option (udpa.annotations.file_status).package_version_status = ACTIVE;
  14. // [#protodoc-title: Unified Matcher API]
  15. // A matcher, which may traverse a matching tree in order to result in a match action.
  16. // During matching, the tree will be traversed until a match is found, or if no match
  17. // is found the action specified by the most specific on_no_match will be evaluated.
  18. // As an on_no_match might result in another matching tree being evaluated, this process
  19. // might repeat several times until the final OnMatch (or no match) is decided.
  20. message Matcher {
  21. option (xds.annotations.v3.message_status).work_in_progress = true;
  22. // What to do if a match is successful.
  23. message OnMatch {
  24. oneof on_match {
  25. option (validate.required) = true;
  26. // Nested matcher to evaluate.
  27. // If the nested matcher does not match and does not specify
  28. // on_no_match, then this matcher is considered not to have
  29. // matched, even if a predicate at this level or above returned
  30. // true.
  31. Matcher matcher = 1;
  32. // Protocol-specific action to take.
  33. core.v3.TypedExtensionConfig action = 2;
  34. }
  35. }
  36. // A linear list of field matchers.
  37. // The field matchers are evaluated in order, and the first match
  38. // wins.
  39. message MatcherList {
  40. // Predicate to determine if a match is successful.
  41. message Predicate {
  42. // Predicate for a single input field.
  43. message SinglePredicate {
  44. // Protocol-specific specification of input field to match on.
  45. // [#extension-category: envoy.matching.common_inputs]
  46. core.v3.TypedExtensionConfig input = 1 [(validate.rules).message = {required: true}];
  47. oneof matcher {
  48. option (validate.required) = true;
  49. // Built-in string matcher.
  50. type.matcher.v3.StringMatcher value_match = 2;
  51. // Extension for custom matching logic.
  52. // [#extension-category: envoy.matching.input_matchers]
  53. core.v3.TypedExtensionConfig custom_match = 3;
  54. }
  55. }
  56. // A list of two or more matchers. Used to allow using a list within a oneof.
  57. message PredicateList {
  58. repeated Predicate predicate = 1 [(validate.rules).repeated = {min_items: 2}];
  59. }
  60. oneof match_type {
  61. option (validate.required) = true;
  62. // A single predicate to evaluate.
  63. SinglePredicate single_predicate = 1;
  64. // A list of predicates to be OR-ed together.
  65. PredicateList or_matcher = 2;
  66. // A list of predicates to be AND-ed together.
  67. PredicateList and_matcher = 3;
  68. // The invert of a predicate
  69. Predicate not_matcher = 4;
  70. }
  71. }
  72. // An individual matcher.
  73. message FieldMatcher {
  74. // Determines if the match succeeds.
  75. Predicate predicate = 1 [(validate.rules).message = {required: true}];
  76. // What to do if the match succeeds.
  77. OnMatch on_match = 2 [(validate.rules).message = {required: true}];
  78. }
  79. // A list of matchers. First match wins.
  80. repeated FieldMatcher matchers = 1 [(validate.rules).repeated = {min_items: 1}];
  81. }
  82. message MatcherTree {
  83. // A map of configured matchers. Used to allow using a map within a oneof.
  84. message MatchMap {
  85. map<string, OnMatch> map = 1 [(validate.rules).map = {min_pairs: 1}];
  86. }
  87. // Protocol-specific specification of input field to match on.
  88. core.v3.TypedExtensionConfig input = 1 [(validate.rules).message = {required: true}];
  89. // Exact or prefix match maps in which to look up the input value.
  90. // If the lookup succeeds, the match is considered successful, and
  91. // the corresponding OnMatch is used.
  92. oneof tree_type {
  93. option (validate.required) = true;
  94. MatchMap exact_match_map = 2;
  95. // Longest matching prefix wins.
  96. MatchMap prefix_match_map = 3;
  97. // Extension for custom matching logic.
  98. core.v3.TypedExtensionConfig custom_match = 4;
  99. }
  100. }
  101. oneof matcher_type {
  102. option (validate.required) = true;
  103. // A linear list of matchers to evaluate.
  104. MatcherList matcher_list = 1;
  105. // A match tree to evaluate.
  106. MatcherTree matcher_tree = 2;
  107. }
  108. // Optional OnMatch to use if the matcher failed.
  109. // If specified, the OnMatch is used, and the matcher is considered
  110. // to have matched.
  111. // If not specified, the matcher is considered not to have matched.
  112. OnMatch on_no_match = 3;
  113. }
  114. // Match configuration. This is a recursive structure which allows complex nested match
  115. // configurations to be built using various logical operators.
  116. // [#next-free-field: 11]
  117. message MatchPredicate {
  118. // A set of match configurations used for logical operations.
  119. message MatchSet {
  120. // The list of rules that make up the set.
  121. repeated MatchPredicate rules = 1 [(validate.rules).repeated = {min_items: 2}];
  122. }
  123. oneof rule {
  124. option (validate.required) = true;
  125. // A set that describes a logical OR. If any member of the set matches, the match configuration
  126. // matches.
  127. MatchSet or_match = 1;
  128. // A set that describes a logical AND. If all members of the set match, the match configuration
  129. // matches.
  130. MatchSet and_match = 2;
  131. // A negation match. The match configuration will match if the negated match condition matches.
  132. MatchPredicate not_match = 3;
  133. // The match configuration will always match.
  134. bool any_match = 4 [(validate.rules).bool = {const: true}];
  135. // HTTP request headers match configuration.
  136. HttpHeadersMatch http_request_headers_match = 5;
  137. // HTTP request trailers match configuration.
  138. HttpHeadersMatch http_request_trailers_match = 6;
  139. // HTTP response headers match configuration.
  140. HttpHeadersMatch http_response_headers_match = 7;
  141. // HTTP response trailers match configuration.
  142. HttpHeadersMatch http_response_trailers_match = 8;
  143. // HTTP request generic body match configuration.
  144. HttpGenericBodyMatch http_request_generic_body_match = 9;
  145. // HTTP response generic body match configuration.
  146. HttpGenericBodyMatch http_response_generic_body_match = 10;
  147. }
  148. }
  149. // HTTP headers match configuration.
  150. message HttpHeadersMatch {
  151. // HTTP headers to match.
  152. repeated route.v3.HeaderMatcher headers = 1;
  153. }
  154. // HTTP generic body match configuration.
  155. // List of text strings and hex strings to be located in HTTP body.
  156. // All specified strings must be found in the HTTP body for positive match.
  157. // The search may be limited to specified number of bytes from the body start.
  158. //
  159. // .. attention::
  160. //
  161. // Searching for patterns in HTTP body is potentially cpu intensive. For each specified pattern, http body is scanned byte by byte to find a match.
  162. // If multiple patterns are specified, the process is repeated for each pattern. If location of a pattern is known, ``bytes_limit`` should be specified
  163. // to scan only part of the http body.
  164. message HttpGenericBodyMatch {
  165. message GenericTextMatch {
  166. oneof rule {
  167. option (validate.required) = true;
  168. // Text string to be located in HTTP body.
  169. string string_match = 1 [(validate.rules).string = {min_len: 1}];
  170. // Sequence of bytes to be located in HTTP body.
  171. bytes binary_match = 2 [(validate.rules).bytes = {min_len: 1}];
  172. }
  173. }
  174. // Limits search to specified number of bytes - default zero (no limit - match entire captured buffer).
  175. uint32 bytes_limit = 1;
  176. // List of patterns to match.
  177. repeated GenericTextMatch patterns = 2 [(validate.rules).repeated = {min_items: 1}];
  178. }