Skip to content

Conversation

bplotnick
Copy link
Contributor

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

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]>
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #41275 was opened by bplotnick.

see: more, trace.

Signed-off-by: Ben Plotnick <[email protected]>
Signed-off-by: Ben Plotnick <[email protected]>
Copy link
Member

@wbpcode wbpcode left a 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. :)

Comment on lines +20 to +53
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}];
}
Copy link
Member

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;
Copy link
Member

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. :)

@wbpcode
Copy link
Member

wbpcode commented Oct 5, 2025

/wait

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sni_to_metadata filter
2 participants