Skip to content

feat(dynamicpathdetector): wildcards in exec arg vectors (CompareExecArgs matcher)#23

Closed
entlein wants to merge 1 commit intomainfrom
feat/exec-arg-wildcards
Closed

feat(dynamicpathdetector): wildcards in exec arg vectors (CompareExecArgs matcher)#23
entlein wants to merge 1 commit intomainfrom
feat/exec-arg-wildcards

Conversation

@entlein
Copy link
Copy Markdown

@entlein entlein commented Apr 29, 2026

Summary

Adds `CompareExecArgs(profileArgs, runtimeArgs []string) bool` to the
`dynamicpathdetector` package. The matcher honours two wildcard tokens
inside a profile's argument vector:

Token Constant Matches
`⋯` (U+22EF) `DynamicIdentifier` exactly one argument position
`*` `WildcardIdentifier` zero or more consecutive arguments

Anything else is literal-equality. Both ends are anchored — every runtime arg
must be consumed by the profile vector (either by a literal, a single-position
`⋯`, or absorbed into a `*` run). This is what enables user-defined
ApplicationProfile entries like `[--user, ⋯]` for `/usr/bin/curl` or
`[-c, *]` for `/bin/sh` to match arbitrary runtime arguments without
listing every variant.

Recursive backtracking — short profile/runtime vectors keep worst-case below
a regex compile and avoid the ReDoS surface a regex would introduce.

Why now

Sibling work to the wildcard-port endpoint fix (#21). Node-agent will route
its CEL `ap.was_executed_with_args(...)` rule through this matcher in a
separate PR; this storage PR is the consumer-ready primitive.

Tests

  • 40 unit subtests across 5 buckets:
    `literal` / `dynamic` / `wildcard` / `mixed-tokens` / `realistic`.
  • Covers empty/empty, length-mismatch, adjacent `⋯⋯`, leading/trailing/middle ``,
    `⋯` followed by `
    ` (and vice versa), and concrete realistic patterns
    (curl with any URL, sh -c with any command, ls -l with any directory).
  • `go vet ./pkg/registry/file/dynamicpathdetector/...` clean.
  • Wider `pkg/registry/file/...` suite green (no consumer broken).

Test plan

  • Component Tests CI green on the matching node-agent branch
  • No allocation regression on the unrelated path/endpoint benches

@github-actions
Copy link
Copy Markdown

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

@entlein entlein force-pushed the feat/exec-arg-wildcards branch from 3fc2872 to 0de34eb Compare April 30, 2026 09:41
@github-actions
Copy link
Copy Markdown

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

2 similar comments
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 1, 2026

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

…in exec arg vectors

User-defined ApplicationProfile entries can now express argument-vector
patterns containing two wildcard tokens, exposed via the existing
constants:

  DynamicIdentifier  ("⋯") — matches exactly one argument position.
  WildcardIdentifier ("*") — matches zero or more consecutive args.

Anything else is a literal-equality match. The match is anchored at
both ends — every runtime arg must be consumed by the profile vector,
either by a literal, a single-position ⋯, or a *-absorbing run.

Implementation is recursive backtracking. Real exec arg vectors are
short (typically ≤ a dozen entries) with at most a handful of
wildcards, so the worst case stays well below a regex compile and we
avoid the ReDoS surface that comes with regex.

40 unit subtests cover empty/literal/dynamic/wildcard/mixed/realistic
patterns; matcher is consumer-ready for node-agent's CEL exec rule.
@entlein entlein force-pushed the feat/exec-arg-wildcards branch from 4ab95fb to 43795bb Compare May 3, 2026 18:48
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 3, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 27fada00-efba-41b2-a557-4f525a834876

📥 Commits

Reviewing files that changed from the base of the PR and between aaed917 and 43795bb.

📒 Files selected for processing (2)
  • pkg/registry/file/dynamicpathdetector/compare_exec_args.go
  • pkg/registry/file/dynamicpathdetector/tests/compare_exec_args_test.go

📝 Walkthrough

Walkthrough

A new function CompareExecArgs is introduced to match runtime argument slices against profile argument slices using anchored pattern matching with support for (exactly one argument) and * (zero or more consecutive arguments) wildcard tokens. The implementation uses recursive backtracking to resolve wildcard absorption lengths.

Changes

Argument Pattern Matching Implementation

Layer / File(s) Summary
Core Implementation
pkg/registry/file/dynamicpathdetector/compare_exec_args.go
CompareExecArgs function implements recursive backtracking to match a runtime argument vector against a profile pattern containing literals, (single-position wildcard), and * (multi-position wildcard), with both-ends anchoring.
Tests & Documentation
pkg/registry/file/dynamicpathdetector/tests/compare_exec_args_test.go
Comprehensive test suite with five test functions (TestCompareExecArgs_LiteralMatch, TestCompareExecArgs_DynamicIdentifier, TestCompareExecArgs_WildcardIdentifier, TestCompareExecArgs_MixedTokens, TestCompareExecArgs_RealisticPatterns) validating literal matching, token semantics, adjacency behavior, and realistic command patterns via table-driven test cases.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding wildcard support in exec argument vectors with the CompareExecArgs matcher function.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the purpose, implementation details, test coverage, and rationale for the new CompareExecArgs function.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/exec-arg-wildcards

Review rate limit: 9/10 reviews remaining, refill in 6 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 3, 2026

Summary:

  • License scan: failure
  • Credentials scan: skipped
  • Vulnerabilities scan: skipped
  • Unit test: success
  • Go linting: failure

entlein pushed a commit to k8sstormcenter/node-agent that referenced this pull request May 4, 2026
…ompareExecArgs

Routes ap.was_executed_with_args(...) through the new
dynamicpathdetector.CompareExecArgs matcher so user-defined
ApplicationProfile entries can express argument-vector patterns:

  '⋯' (DynamicIdentifier)  — matches exactly one arg position.
  '*' (WildcardIdentifier) — matches zero or more consecutive args.

Previously the function used slices.Compare for exact equality, which
silently ignored wildcard tokens in the profile (a profile entry of
[--user, ⋯] would not match runtime args [--user, alice]). The new
matcher anchors both ends, treats '⋯' / '*' as wildcards, and falls
back to literal-equality otherwise.

13 new unit subtests under TestExecWithArgsWildcardInProfile cover
curl-with-any-URL, sh -c with arbitrary payload, ls -l with any
directory, and echo with arbitrary trailing args, plus negative cases
(literal-anchor mismatch, ⋯ over- and under-consumed, * mid-profile
that fails to re-anchor on a literal).

Storage dep bumped to k8sstormcenter/storage@3fc287210729 which adds
the matcher (k8sstormcenter/storage#23).

Note: default-rules.yaml R0001 'Unexpected process launched' currently
uses path-only ap.was_executed. End-to-end exercise of the wildcard
path requires either a rule update or a custom RuleSet — deferred to
a follow-up so this PR stays scoped to the matcher wiring.
@entlein entlein closed this May 4, 2026
@entlein entlein deleted the feat/exec-arg-wildcards branch May 4, 2026 09:20
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.

1 participant