Skip to content

rthooks: add --fail-allow-namespaces-patterns flag#4812

Open
PhilipSchmid wants to merge 4 commits intocilium:mainfrom
PhilipSchmid:pr/philip/rthook_ns_patterns
Open

rthooks: add --fail-allow-namespaces-patterns flag#4812
PhilipSchmid wants to merge 4 commits intocilium:mainfrom
PhilipSchmid:pr/philip/rthook_ns_patterns

Conversation

@PhilipSchmid
Copy link
Copy Markdown
Contributor

@PhilipSchmid PhilipSchmid commented Mar 31, 2026

Description

Add --fail-allow-namespaces-patterns to tetragon-oci-hook, accepting glob patterns for namespaces that should not cause the hook to fail when Tetragon is unreachable.

Patterns support a single * wildcard:

  • kube-* — prefix match
  • *-system — suffix match
  • foo-*-bar — contains match
  • * — matches any namespace

The flag can be used standalone or combined with the existing --fail-allow-namespaces exact-match list. A container is allowed if its namespace matches either an exact entry or any pattern. --fail-cel-expr takes precedence over both flags.

Patterns with more than one * are rejected at startup. If the namespace annotation key is absent from the container annotations the hook always fails (safe default).

Both flags are evaluated through a single CEL program. A custom namespace_matches_glob function is registered into the CEL environment, keeping all fail-check logic within the CEL evaluation path.

Changes

  • cel.go: add namespaceMatchesGlob and register it as a CEL function; implement celAllowNamespacesWithPatterns as a single CEL program covering both exact names and glob patterns
  • main.go: add FailAllowNamespacesPatterns to cliConf; simplify failTestProg to return *celProg directly
  • cel_test.go: table-driven tests covering exact namespaces, all glob wildcard forms (prefix, suffix, contains, bare *, exact without wildcard, empty string, overlapping patterns), combined usage, missing annotation keys, multiple invalid glob forms, and annotation key priority
  • values.yaml + _container_rthooks.tpl: add rthooks.failAllowNamespacesPatterns Helm value; pass each entry as a repeated flag to the hook binary
  • runtime-hooks.md: document the new option, all wildcard forms, usage examples, and precedence rules

Motivation

Previously, the only way to exclude a group of namespaces from hook failures was --fail-cel-expr, which requires users to write a raw CEL expression. While powerful, this is error-prone for common cases like allowing all namespaces with a given prefix. The new flag covers these patterns without requiring any CEL knowledge:

rthooks:
  enabled: true
  failAllowNamespacesPatterns:
    - "kube-*"
    - "prod-*"
    - "*-system"

Release Note

rthooks: add --fail-allow-namespaces-patterns flag

@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for tetragon ready!

Name Link
🔨 Latest commit df027fb
🔍 Latest deploy log https://app.netlify.com/projects/tetragon/deploys/69d60ca90d69f70008ea29a8
😎 Deploy Preview https://deploy-preview-4812--tetragon.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@PhilipSchmid PhilipSchmid force-pushed the pr/philip/rthook_ns_patterns branch from f1ed32a to ab54f6f Compare March 31, 2026 13:41
Copy link
Copy Markdown
Contributor

@kkourt kkourt left a comment

Choose a reason for hiding this comment

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

Thanks!

Can you split the PR into different commits so that it can be easily reviewed?

It feels to me that the PR was generated by an LLM. Please document the influence level (see: https://danielmiessler.com/blog/ai-influence-level-ail) of the PR.

Fix double word "the them" -> "them" in the failure check section.

Signed-off-by: Philip Schmid <phisch@cisco.com>
@PhilipSchmid PhilipSchmid force-pushed the pr/philip/rthook_ns_patterns branch from ab54f6f to 044b086 Compare April 1, 2026 11:49
@kkourt kkourt added the release-note/minor This PR introduces a minor user-visible change label Apr 1, 2026
Copy link
Copy Markdown
Contributor Author

@PhilipSchmid PhilipSchmid 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 feedback and input!

Can you split the PR into different commits so that it can be easily reviewed?

Absolutely, I just did that and force-pushed 4 granular commits.

It feels to me that the PR was generated by an LLM. Please document the influence level (see: https://danielmiessler.com/blog/ai-influence-level-ail) of the PR.

💯, I used an LLM create that. I'd say it's an AIL 3-4. IMO, it's probably obvious that close to no human would have added so many unit tests 😅. Still, stuff like this was all implemented because I gave pretty detailed instructions to the LLM to do so, and I also reviewed them all and they make sense to me (according to me limited golang experience). Is there a specific way you want this AIL being mentioned in the PR and/or git commits? Maybe it's also worth to add a brief section about that in https://tetragon.io/docs/contribution-guide/ as I assume I'm not the first and won't for sure be the last one doing that?

Add a new --fail-allow-namespaces-patterns flag to tetragon-oci-hook
that accepts glob patterns with a single '*' wildcard. Supported forms:
'kube-*' (prefix), '*-system' (suffix), 'foo-*-bar' (contains), or
'*' alone to match any namespace. A container is allowed to start if
its namespace matches any of the provided patterns.

The flag can be combined with the existing --fail-allow-namespaces
exact-match list; either a match on an exact name or a glob pattern is
sufficient to allow the container. Patterns with more than one '*' are
rejected at startup. The --fail-cel-expr flag continues to take
precedence over both namespace options.

Both --fail-allow-namespaces and --fail-allow-namespaces-patterns are
evaluated through a single CEL program. A custom namespace_matches_glob
function is registered into the CEL environment to perform glob
matching in Go, keeping all fail-check logic within the CEL evaluation
path.

Fix a false-match bug in namespaceMatchesGlob for contains patterns
where the prefix and suffix overlap on short namespace strings.

Expand the unit tests to table-driven style covering: exact namespaces,
glob patterns (prefix, suffix, contains, bare wildcard, exact without
wildcard, empty string), combined usage, missing annotation keys,
multiple invalid glob forms, and annotation key priority.

Signed-off-by: Philip Schmid <phisch@cisco.com>
Add rthooks.failAllowNamespacesPatterns as a list value and pass each
entry as a repeated --fail-allow-namespaces-patterns flag to the
tetragon-oci-hook container. Document all supported wildcard forms in
the values comment: prefix ('kube-*'), suffix ('*-system'), contains
('foo-*-bar'), and bare '*' to match any namespace. Regenerate
README.md and helm-chart.md.

Signed-off-by: Philip Schmid <phisch@cisco.com>
Extend the failure check section to cover the new
failAllowNamespacesPatterns option: add exact-match and pattern-match
sub-sections with YAML examples, a combined-usage example, and a note
on precedence when fail-cel-expr is set.

Patterns use glob syntax with a single '*' wildcard. Document all
supported wildcard forms: prefix ('kube-*'), suffix ('*-system'),
contains ('foo-*-bar'), and bare '*' to match any namespace.

Signed-off-by: Philip Schmid <phisch@cisco.com>
@PhilipSchmid PhilipSchmid force-pushed the pr/philip/rthook_ns_patterns branch from 044b086 to df027fb Compare April 8, 2026 08:07
@PhilipSchmid PhilipSchmid requested a review from kkourt April 8, 2026 08:09
@PhilipSchmid PhilipSchmid marked this pull request as ready for review April 8, 2026 08:09
@PhilipSchmid PhilipSchmid requested review from a team and mtardy as code owners April 8, 2026 08:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note/minor This PR introduces a minor user-visible change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants