Skip to content

sni: Add logic to allow pattern prefix match#1242

Merged
jrajahalme merged 1 commit intomainfrom
pr/tammach/sni-hacking
Apr 1, 2025
Merged

sni: Add logic to allow pattern prefix match#1242
jrajahalme merged 1 commit intomainfrom
pr/tammach/sni-hacking

Conversation

@sayboras
Copy link
Member

This commit is to support domain matching logic for SNI.

Examples of valid matches:

"*.example.com" matches:

  • "foo.example.com"
  • "bar.example.com"
  • "sub.example.com"
    but not:
  • "example.com" as wildcard requires exactly one label
  • "foo.bar.example.com" due to too many labels
  • "notexample.com" due to different domain

@sayboras sayboras force-pushed the pr/tammach/sni-hacking branch 4 times, most recently from b7e63c3 to 8e14edb Compare March 30, 2025 08:04
@sayboras sayboras marked this pull request as ready for review March 30, 2025 08:07
@sayboras sayboras requested a review from a team as a code owner March 30, 2025 08:07
@sayboras sayboras requested a review from jrajahalme March 30, 2025 08:07
@sayboras sayboras changed the title sni: Add logic to allow pattern match sni: Add logic to allow pattern prefix match Mar 31, 2025
@sayboras sayboras force-pushed the pr/tammach/sni-hacking branch from 8e14edb to 4bdbc38 Compare March 31, 2025 05:32
Copy link
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove the partial subdomain match, it is dangerous.

This commit is to support domain matching logic for SNI.

Examples of valid matches:

"*.example.com" matches:
  - "foo.example.com"
  - "bar.example.com"
  - "sub.example.com"

but not:
  - "example.com" as wildcard requires exactly one label
  - "foo.bar.example.com" due to too many labels
  - "notexample.com" due to different domain

Signed-off-by: Tam Mach <tam.mach@cilium.io>
@sayboras sayboras force-pushed the pr/tammach/sni-hacking branch from 4bdbc38 to ce4b1c6 Compare March 31, 2025 12:29
@sayboras sayboras requested a review from jrajahalme March 31, 2025 12:30
Copy link
Member

@jrajahalme jrajahalme left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, thank you :-)

@jrajahalme jrajahalme added this pull request to the merge queue Apr 1, 2025
Merged via the queue into main with commit f38edd1 Apr 1, 2025
5 checks passed
@jrajahalme jrajahalme deleted the pr/tammach/sni-hacking branch April 1, 2025 12:44
fristonio added a commit to fristonio/cilium-proxy that referenced this pull request Jan 11, 2026
This commit adds support for specifying wildcard('*') anywhere in the
server names match pattern. This allow users to write more compressed
network policies and is inline with what cilium/cilium supports for FQDN
match patterns.
With this change users can now write allowed server names as:

- '**.cilium.io': Existing behavior which matches any number of
  subdomain levels in the prefix. "test.cilium.io" and
  "test.app.cilium.io" matches but "cilium.io" does not.

- '*.cilium.io': Existing behavior which matches all subdomains of
  cilium.io on a single level. "test.cilium.io" matches but
  "test.app.cilium.io" and "cilium.io" do not.

- 'sub*.cilium.io': Matches subdomains of cilium.io where the subdomain
  component begins with "sub"(only one level). "sub.cilium.io" and
  "subdomain.cilium.io" matches wile "www.cilium.io", "cilium.io" and
  "test.subdomain.cilium.io" do not.

SNI match patterns are now implemented using regular expressions. The
required regex is derived and compiled once during xDS configuration
update.
If the match pattern doesn't contain any wildcard specifier the
implementation relies on explicit full string match.

Extends: cilium#1242
Related to: cilium/cilium#43597

Signed-off-by: Deepesh Pathak <deepesh.pathak@isovalent.com>
fristonio added a commit to fristonio/cilium-proxy that referenced this pull request Jan 11, 2026
This commit adds support for specifying wildcard('*') anywhere in the
server names match pattern. This allow users to write more compressed
network policies and is inline with what cilium/cilium supports for FQDN
match patterns.
With this change users can now write allowed server names as:

- '**.cilium.io': Existing behavior which matches any number of
  subdomain levels in the prefix. "test.cilium.io" and
  "test.app.cilium.io" matches but "cilium.io" does not.

- '*.cilium.io': Existing behavior which matches all subdomains of
  cilium.io on a single level. "test.cilium.io" matches but
  "test.app.cilium.io" and "cilium.io" do not.

- 'sub*.cilium.io': Matches subdomains of cilium.io where the subdomain
  component begins with "sub"(only one level). "sub.cilium.io" and
  "subdomain.cilium.io" matches wile "www.cilium.io", "cilium.io" and
  "test.subdomain.cilium.io" do not.

SNI match patterns are now implemented using regular expressions. The
required regex is derived and compiled once during xDS configuration
update.
If the match pattern doesn't contain any wildcard specifier the
implementation relies on explicit full string match.

Extends: cilium#1242
Related to: cilium/cilium#43597

Signed-off-by: Deepesh Pathak <deepesh.pathak@isovalent.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants