Skip to content

Enhance supported patterns to include ** matching multilevel of subdomains#42871

Closed
pjablonski123 wants to merge 1 commit intocilium:mainfrom
pjablonski123:pj-fqdn
Closed

Enhance supported patterns to include ** matching multilevel of subdomains#42871
pjablonski123 wants to merge 1 commit intocilium:mainfrom
pjablonski123:pj-fqdn

Conversation

@pjablonski123
Copy link
Copy Markdown

Reopening PR #28690

…mains.

pkg/fqdn: Adding ** matchpattern

The ** in matchpattern allows a short notation of multilevel subdomains

Instead of the rules with listed subdomains:

rules:
  dns:
    - matchPattern: '*.cluster.local'
    - matchPattern: '*.*.cluster.local'
    - matchPattern: '*.*.*.cluster.local'
    - matchPattern: '*.*.*.*.cluster.local'
    - matchPattern: '*.*.*.*.*.cluster.local'
    - matchPattern: '*.*.*.*.*.*.cluster.local'
    - matchPattern: '*.*.*.*.*.*.*.cluster.local'
    - matchPattern: '*.*.*.*.*.*.*.*.cluster.local'

egress:
  - toFQDNs:
    - matchPattern: '*.cilium.io'
    - matchPattern: '*.*.cilium.io'
    - matchPattern: '*.*.*.cilium.io'
    - matchPattern: '*.*.*.*.cilium.io'
    - matchPattern: '*.*.*.*.*.cilium.io'
    - matchPattern: '*.*.*.*.*.*.cilium.io'
    - matchPattern: '*.*.*.*.*.*.*.cilium.io'
    - matchPattern: '*.*.*.*.*.*.*.*.cilium.io'

the following policy can be used in a simpler form:

rules:
  dns:
    - matchPattern: '**.cluster.local'

egress:
  - toFQDNs:
    - matchPattern: '**.cilium.io'

Changelog:
Modified the code and added tests.
Updated language.rst.
Updated matchpattern.go.
Added and updated doc files.
Updated language.rst with a security note.
Double asterisk is allowed at the beginning of the domain only.

Signed-off-by: Piotr Jablonski <[email protected]>

```release-note
The ** in matchpattern allows a short notation of multilevel subdomains,
eg. **.cilium.io matches a.cilium.io, a.b.cilium.io, a.b.c.cilium.io, etc.

This feature can break current configuration if a double asterisk was used inside of FQDN, eg. cil**.io
Before this enhancement two or more directly adjacent asterisks meant the same - a single asterisk, eg. cil**.io == cil*.io
The correct usage of the asterisk before this enhancement should be a single presence between other characters, eg. c*m.io, *.cil*.io
With this enhancement the correct usage of the single asterisk does not change
A double asterisk must be at the beginning of the FQDN string only, eg. **.cilium.io
The single and double asterisk can be present in the same FQDN if they are separated by a dot directly or indirectly, eg. **.*lium.io, **.cili*.io
```
@pjablonski123 pjablonski123 requested review from a team as code owners November 19, 2025 11:41
@pjablonski123 pjablonski123 requested a review from squeed November 19, 2025 11:41
@maintainer-s-little-helper maintainer-s-little-helper bot added the dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. label Nov 19, 2025
@github-actions github-actions bot added sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. kind/community-contribution This was a contribution made by a community member. labels Nov 19, 2025
@pjablonski123
Copy link
Copy Markdown
Author

pjablonski123 commented Nov 19, 2025

Let's review security concerns and address them to push this PR forward.
#22081 (comment)

@TheBeeZee Did you consider potential security flaws of adding ** to the network policy syntax?

Comment on lines +593 to +595
* ``**`` within a domain allows 0 or more valid DNS subdomains and characters, including
``.`` separator. ``**.cilium.io`` will match ``sub1.cilium.io`` as well as ``sub2.sub1.cilium.io``.
* ``**`` alone matches all names, and inserts all cached DNS IPs into this rule.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

non-blocking nit: It's slightly more correct to use the term label here, since each period-separated part of a domain/host name is called that.

Suggested change
* ``**`` within a domain allows 0 or more valid DNS subdomains and characters, including
``.`` separator. ``**.cilium.io`` will match ``sub1.cilium.io`` as well as ``sub2.sub1.cilium.io``.
* ``**`` alone matches all names, and inserts all cached DNS IPs into this rule.
* ``**`` within a domain allows 0 or more valid DNS labels to the left, including
``.`` separator. ``**.cilium.io`` will match ``sub1.cilium.io`` as well as ``sub2.sub1.cilium.io``.
* ``**`` alone matches all names, and inserts all cached DNS IPs into this rule.

@pchaigno
Copy link
Copy Markdown
Member

It looks like this branch is based on a 2 years old main branch so definitely won't pass CI. You'll need to rebase on the latest main.

@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale because it
has not had recent activity. It will be closed if no further activity
occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale. label Dec 25, 2025
@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 8, 2026

This pull request has not seen any activity since it was marked stale.
Closing.

@github-actions github-actions bot closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dont-merge/needs-release-note-label The author needs to describe the release impact of these changes. kind/community-contribution This was a contribution made by a community member. sig/policy Impacts whether traffic is allowed or denied based on user-defined policies. stale The stale bot thinks this issue is old. Add "pinned" label to prevent this from becoming stale.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants