-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Add envoy.filters.network.sni_to_metadata #41275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution. And some initial comments to the API. :)
message SniToMetadataFilter { | ||
// MetadataTarget defines where to store extracted metadata. | ||
message MetadataTarget { | ||
// The metadata namespace to use when storing the result. | ||
// If empty, defaults to ``envoy.filters.network.sni_to_metadata`` | ||
string metadata_namespace = 1; | ||
|
||
// The metadata key to use when storing the result. | ||
string metadata_key = 2 [(validate.rules).string = {min_len: 1}]; | ||
|
||
// The metadata value to store. If empty, the entire matched SNI value will be used. | ||
// This field supports capture group substitution using numbered groups from the regex pattern. | ||
// For example: ``app-\\1-\\2`` where ``\\1`` and ``\\2`` refer to the first and second capture groups (note escaped backslashes). | ||
string metadata_value = 3; | ||
} | ||
|
||
// ConnectionRule defines a rule for extracting metadata from SNI. | ||
message ConnectionRule { | ||
// The regex pattern to match against the SNI value. | ||
// Supports Google RE2 numbered capture groups. | ||
// Example: ``^([^.]+)\.([^.]+)\.([^.]+)\.example\.com$`` | ||
// If not specified, the rule will always match and use the entire SNI value. | ||
type.matcher.v3.RegexMatcher pattern = 1; | ||
|
||
// List of metadata targets to populate when this rule matches. | ||
// Each target can use capture groups from the regex pattern in its metadata_value. | ||
// If no pattern is specified, metadata_value will be used as-is or default to the full SNI. | ||
repeated MetadataTarget metadata_targets = 2 [(validate.rules).repeated = {min_items: 1}]; | ||
} | ||
|
||
// List of connection rules to evaluate against the SNI. | ||
// Rules are evaluated in order, and the first matching rule will be applied. | ||
repeated ConnectionRule connection_rules = 1 [(validate.rules).repeated = {min_items: 1}]; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you take the HeaderToMetadata as a reference and use the similar API (like the same KeyValuePair
)? So, it would be more friendly for new users.
// Supports Google RE2 numbered capture groups. | ||
// Example: ``^([^.]+)\.([^.]+)\.([^.]+)\.example\.com$`` | ||
// If not specified, the rule will always match and use the entire SNI value. | ||
type.matcher.v3.RegexMatcher pattern = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We prefer StringMatcher rather than single regex matcher. :)
/wait |
This implements a new filter
envoy.filter.network.sni_to_metadata
.Commit Message: Adds a new SNI-to-Metadata filter that extracts the SNI of the client connection and stores it in the connection dynamic metadata.
Additional Description: SNI-to-Metadata filter extracts the SNI of the client connection and stores it in the connection dynamic metadata. It is able to conditionally extract based on regex patters as well as extract fields and format the metadata using regex capture groups.
Risk Level: Low
Testing: unit testing
Docs Changes:
Release Notes:
Platform Specific Features:
Fixes: #41262