Skip to content

feat: NetworkNeighbor wildcard runtime (v0.0.2)#41

Open
entlein wants to merge 10 commits into
mainfrom
feat/network-wildcards
Open

feat: NetworkNeighbor wildcard runtime (v0.0.2)#41
entlein wants to merge 10 commits into
mainfrom
feat/network-wildcards

Conversation

@entlein
Copy link
Copy Markdown

@entlein entlein commented May 10, 2026

Summary

Companion PR to `storage#30`. Wires the v0.0.2 wildcard matchers into the runtime CEL functions and ships 20 user-facing YAML fixtures covering every edge case of the new surface.

What's new

Fixtures (`tests/resources/network-wildcards/`)
20 kubectl-applicable NetworkNeighborhood documents. Each fixture exercises ONE edge case and double as authoritative syntax documentation. Index in the directory's `README.md`. Coverage:

  • 01-08 — IP forms (literal v4/v6, CIDR v4/v6, `*` sentinel, 0.0.0.0/0 + ::/0, mixed list, deprecated singular)
  • 09-14 — DNS forms (literal, leading-`` RFC 4592, mid-`⋯`, trailing-``, trailing-dot normalisation, recursive-`**` rejected at admission)
  • 15-20 — composed cases (egress + ingress direction isolation, NONE egress, realistic Stripe API, cluster DNS via mid-`⋯`, port+protocol+CIDR composed, multi-container pod with different rules per container)

CEL function rewiring (`pkg/rulemanager/cel/libraries/networkneighborhood/network.go`)
All six `nn.*` functions now route IP comparisons through `storage/networkmatch.MatchIP` and DNS comparisons through `MatchDNS`. Mirror image applied symmetrically to egress + ingress:

  • `nn.was_address_in_egress` / `_in_ingress`
  • `nn.is_domain_in_egress` / `_in_ingress`
  • `nn.was_address_port_protocol_in_egress` / `_in_ingress`

Each function walks BOTH the deprecated singular field (back-compat) AND the new plural list (wildcard-aware). Two helpers — `neighborMatchesIP` and `neighborMatchesDNS` — factor the two-list walk so the six call sites stay readable. The existing CEL `functionCache` continues to memoise (containerID, observed) tuples, so the wildcard-match overhead only fires on cache misses.

Backward compatibility

  • Profiles that use only the deprecated singular `IPAddress` / `DNS` fields behave exactly as before
  • Profiles that use the new plural `IPAddresses` / `DNSNames` fields gain CIDR + wildcard matching with no rule-side changes
  • Mixed profiles (one neighbor uses singular, another uses plural) work — each neighbor is matched against both fields independently

Test plan

  • `TestFixturesParse` — every YAML in `tests/resources/network-wildcards/` parses against the v1beta1 schema
  • `TestFixturesMatchExpectedBehaviour` — representative observed→match triples for each major edge case route through the actual nn.* CEL functions, pinning the contract between the user-facing examples and the runtime
  • Unit tests for the rewired CEL functions (CIDR, `` sentinel, leading-`` DNS, mid-`⋯`, trailing-dot resilience, direction isolation, deprecated-singular back-compat, mixed singular+plural, composed CIDR+port+protocol)
  • Existing `TestWasAddressPortProtocolIn{Egress,Ingress}` and integration tests stay green
  • Full `pkg/rulemanager/...` suite green; pre-existing eBPF privilege failures in `pkg/containerwatcher/v2/tracers/` and `pkg/validator/` (kernel-level operations, not related to this work) reproduce on `main`

Storage dep

`go.mod` replace pinned to the storage fork ref carrying the networkmatch package. Once `storage#30` merges, this PR's replace will be updated to the post-merge SHA.

Entlein added 5 commits May 10, 2026 12:49
… surface

Living documentation for the feat/network-wildcards work. Each fixture
is a complete, kubectl-applicable NetworkNeighborhood document
exercising ONE edge case in the v0.0.2 wildcard surface. Test_34
(forthcoming) consumes them directly; users learning the syntax can
copy-paste them as authoritative examples.

Coverage:
  01 — IPv4 literal in ipAddresses[]
  02 — IPv6 literal (canonicalisation)
  03 — IPv4 CIDR
  04 — IPv6 CIDR
  05 — '*' sentinel for ANY IP (with discouragement annotation)
  06 — 0.0.0.0/0 + ::/0 (RFC-aligned alternative to '*')
  07 — mixed list (literal + CIDR + sentinel)
  08 — backward-compat singular ipAddress
  09 — DNS literal
  10 — DNS leading '*' (RFC 4592)
  11 — DNS mid '⋯' (DynamicIdentifier)
  12 — DNS trailing '*' (one or more, never zero)
  13 — trailing-dot normalisation
  14 — '**' recursive — admission MUST reject
  15 — egress + ingress on same container, direction isolation
  16 — egress: [] NONE (declared zero-egress)
  17 — realistic Stripe API + cluster DNS
  18 — Kubernetes service-FQDN via mid '⋯' (the user's case)
  19 — port + protocol + CIDR composed
  20 — multi-container pod, different rules per container

README.md indexes all fixtures and lists the wildcard token vocabulary.

Each fixture's header comment lists the edge case, expected outcomes,
match path, spec reference, and operational guidance. Ready to be
consumed by node-agent's Test_34_NetworkWildcardSurface (forthcoming)
and by storage's networkmatch unit tests via testdata-style references.
Replaces byte-equality with the v0.0.2 wildcard-aware matchers from
storage's pkg/registry/file/networkmatch — applied symmetrically to
all six nn.* CEL functions (egress + ingress mirror images):

  nn.was_address_in_egress / _in_ingress
  nn.is_domain_in_egress   / _in_ingress
  nn.was_address_port_protocol_in_egress / _in_ingress

Each function now walks BOTH the deprecated singular field
(IPAddress / DNS, byte-equality, back-compat) AND the new plural
field (IPAddresses / DNSNames, wildcard-aware) on each NetworkNeighbor
entry. A profile that uses only the deprecated form behaves exactly
as before; a profile that uses the new form gains CIDR + wildcard
matching with no rule-side changes required.

Two helpers (neighborMatchesIP / neighborMatchesDNS) factor the
two-list walk so the six call sites stay readable. Compiled-form
caching of the matcher across calls is deferred to a follow-up — the
existing cel functionCache still memoises (containerID, observed)
tuples, so the per-call MatchIP/MatchDNS overhead only fires on
cache misses.

Tests cover:
  - CIDR membership across egress/ingress
  - '*' sentinel for any IP
  - leading-* DNS wildcard (RFC 4592, exactly one label)
  - mid-⋯ DynamicLabel (the kubernetes service-FQDN case)
  - trailing-dot resilience
  - direction isolation (egress and ingress lists are walked
    independently — same address allowed on one direction
    must NOT match the other)
  - back-compat: deprecated singular IPAddress/DNS still works
  - mixed: profile with one entry using singular, another using plural
  - composed match: CIDR + port + protocol on the granular variant

go.mod: temporary local-path replace for kubescape/storage so the
node-agent picks up the in-flight feat/network-wildcards work; user
flips back to fork ref before pushing.
TestFixturesParse: every YAML under tests/resources/network-wildcards/
parses against the v1beta1 NetworkNeighborhood schema. The fixtures
double as authoritative user-facing syntax documentation, so a fixture
that fails to parse is a documentation bug.

TestFixturesMatchExpectedBehaviour: representative observed→match
triples for each major edge case (literal IP, CIDR, '*' sentinel,
deprecated singular IPAddress, leading-* DNS RFC 4592, mid-⋯
DynamicLabel, direction isolation between egress and ingress) are
exercised through the actual nn.* CEL functions. If a fixture's
header comment says '10.1.2.3 → match' and the matcher disagrees,
ONE of them is wrong; this test pins both.

True end-to-end Test_34_NetworkWildcardSurface (kubectl-applies the
fixtures against a live cluster) belongs in the iximiuz lab; that
job is left for the lab pass once the storage + node-agent images
ship via the fork CI.
Local replace points at ../storage so the fork ref isn't fetched.
User reverts both go.mod and go.sum before pushing the branch.
Updates the storage replace to a pseudo-version on the fork that includes
the v0.0.2 wildcard surface (pkg/registry/file/networkmatch/, IPAddresses
schema field, REST validation). Build and tests stay green against the
pinned ref.

The .claude/ entry on .gitignore prevents the agent state directory from
being tracked accidentally.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 10, 2026

Review Change Stack
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: 652545f6-8ee3-4a70-9e21-905d73e39a1f

📥 Commits

Reviewing files that changed from the base of the PR and between f89fc80 and 4c90e22.

📒 Files selected for processing (2)
  • pkg/rulemanager/cel/libraries/networkneighborhood/network.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/wildcard_test.go

📝 Walkthrough

Walkthrough

This pull request refactors CEL IP/DNS matching to shared helpers that support plural CIDR and DNS wildcard fields while preserving deprecated singular-field parity; adds explicit port-range validation; introduces comprehensive unit tests and helpers; and adds 20 NetworkNeighborhood fixture YAMLs with README plus minor .gitignore and go.mod updates.

Changes

Network Wildcard Matching Feature

Layer / File(s) Summary
Core Matching Logic
pkg/rulemanager/cel/libraries/networkneighborhood/network.go
Introduces neighborMatchesIP and neighborMatchesDNS helpers; refactors wasAddressInEgress, wasAddressInIngress, isDomainInEgress, isDomainInIngress, wasAddressPortProtocolInEgress, and wasAddressPortProtocolInIngress to use the shared helpers and adds explicit port-range validation.
Unit Tests
pkg/rulemanager/cel/libraries/networkneighborhood/wildcard_test.go, pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go
Adds table-driven fixture parsing/matching tests and focused wildcard/unit tests covering CIDR, * sentinel, legacy-field parity, DNS wildcards/ellipsis/trailing-dot normalization, port/protocol composition and overflow rejection, direction isolation, and helper buildLibWithContainer.
Test Fixtures
tests/resources/network-wildcards/*
Adds 20 NetworkNeighborhood fixture YAMLs exercising IPv4/IPv6 literals and CIDRs, any-IP sentinel and CIDR equivalents, mixed IP lists, deprecated singular fields, DNS literal and wildcard patterns (leading *., mid-ellipsis , trailing *), an invalid recursive wildcard fixture, ingress/egress isolation, empty egress, realistic Stripe API scenario, port+protocol composition, and multi-container configurations; includes README.md.
Documentation & Config
tests/resources/network-wildcards/README.md, .gitignore, go.mod
Adds README documenting wildcard token vocabulary, NetworkNeighbor field semantics, fixture index, and v0.0.2 migration/back-compat notes; updates .gitignore to ignore .claude/; updates go.mod replace directive pseudo-version.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% 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 'feat: NetworkNeighbor wildcard runtime (v0.0.2)' is directly related to the main change—wiring v0.0.2 wildcard matchers into runtime CEL functions with 20 YAML fixtures.
Description check ✅ Passed The description is related to the changeset, detailing the wildcard matcher implementation, 20 test fixtures, CEL function rewiring, backward compatibility, and test plan.
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/network-wildcards

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
pkg/rulemanager/cel/libraries/networkneighborhood/network.go (1)

171-191: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Reject out-of-range ports before narrowing to int32.

int64int32 narrowing can wrap here. For example, an invalid CEL value like 4294967739 becomes 443 after conversion, so this matcher can incorrectly return true for a bogus port. Guard portInt to the valid TCP/UDP range before comparing.

Proposed fix
 	portInt, ok := port.Value().(int64)
 	if !ok {
 		return types.MaybeNoSuchOverloadErr(port)
 	}
+	if portInt < 0 || portInt > 65535 {
+		return types.Bool(false)
+	}
 	protocolStr, ok := protocol.Value().(string)
 	if !ok {
 		return types.MaybeNoSuchOverloadErr(protocol)
 	}
@@
-		for _, portInfo := range egress.Ports {
-			if portInfo.Protocol == v1beta1.Protocol(protocolStr) && portInfo.Port != nil && *portInfo.Port == int32(portInt) {
+		expectedPort := int32(portInt)
+		for _, portInfo := range egress.Ports {
+			if portInfo.Protocol == v1beta1.Protocol(protocolStr) && portInfo.Port != nil && *portInfo.Port == expectedPort {
 				return types.Bool(true)
 			}
 		}
@@
 	portInt, ok := port.Value().(int64)
 	if !ok {
 		return types.MaybeNoSuchOverloadErr(port)
 	}
+	if portInt < 0 || portInt > 65535 {
+		return types.Bool(false)
+	}
 	protocolStr, ok := protocol.Value().(string)
 	if !ok {
 		return types.MaybeNoSuchOverloadErr(protocol)
 	}
@@
-		for _, portInfo := range ingress.Ports {
-			if portInfo.Protocol == v1beta1.Protocol(protocolStr) && portInfo.Port != nil && *portInfo.Port == int32(portInt) {
+		expectedPort := int32(portInt)
+		for _, portInfo := range ingress.Ports {
+			if portInfo.Protocol == v1beta1.Protocol(protocolStr) && portInfo.Port != nil && *portInfo.Port == expectedPort {
 				return types.Bool(true)
 			}
 		}

Also applies to: 213-233

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/rulemanager/cel/libraries/networkneighborhood/network.go` around lines
171 - 191, The code narrows port.Value() from int64 to int32 which can wrap;
validate portInt is within the TCP/UDP range before comparing or converting:
check portInt >= 0 && portInt <= 65535 and return
types.MaybeNoSuchOverloadErr(port) (or similar error) if out of range, then
safely cast to int32 for comparison with *portInfo.Port; apply the same guard
for the second occurrence around lines 213-233 (the portInt handling used with
cp.Spec.Egress and portInfo.Port).
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go`:
- Around line 52-53: The test uses yaml.Unmarshal which ignores unknown fields
and can let fixture typos slip; replace the call to yaml.Unmarshal(data, &nn)
with yaml.UnmarshalStrict(data, &nn) in the fixture parsing block (the one
assigning err and calling require.NoError(t, err, "fixture %s must parse against
v1beta1 schema", name)) so the test fails on unknown fields; ensure any
necessary yaml package provides UnmarshalStrict and adjust imports if needed.
- Around line 155-159: The test case that builds ipChecks currently only asserts
wasAddressInEgress; update the test in fixtures_test.go to also assert
wasAddressInIngress for each entry so both directions are validated: for the
"8.8.8.8" entry assert wasAddressInEgress == true and wasAddressInIngress ==
false, and for the "10.244.5.5" entry assert wasAddressInEgress == false and
wasAddressInIngress == true (or the expected inverse), ensuring the loop that
iterates ipChecks checks both wasAddressInEgress and wasAddressInIngress for
every ipCheck element.

In `@pkg/rulemanager/cel/libraries/networkneighborhood/network.go`:
- Around line 34-43: The neighborMatchesDNS function currently compares the
deprecated neighbor.DNS via simple string equality which diverges from DNSNames
behavior; update it so that when neighbor.DNS is non-empty you call
networkmatch.MatchDNS with a single-element slice (e.g.,
networkmatch.MatchDNS([]string{neighbor.DNS}, observed)) so the same
normalization/trailing-dot logic is applied as for DNSNames, and add a
regression test covering neighbor.DNS matching with and without trailing dots to
ensure parity with DNSNames.

In `@tests/resources/network-wildcards/README.md`:
- Around line 5-8: Update the README sentence that currently states every
`*.yaml` is "kubectl-applicable" to note that one fixture in the set is
intentionally rejected at admission and should not be applied; mention that the
test harness (Test_34_NetworkWildcardSurface) consumes all fixtures including an
admission-rejected example and point readers to the manifest indexed at line 48
as the intentionally-rejected case so users don’t attempt to kubectl-apply it.

---

Outside diff comments:
In `@pkg/rulemanager/cel/libraries/networkneighborhood/network.go`:
- Around line 171-191: The code narrows port.Value() from int64 to int32 which
can wrap; validate portInt is within the TCP/UDP range before comparing or
converting: check portInt >= 0 && portInt <= 65535 and return
types.MaybeNoSuchOverloadErr(port) (or similar error) if out of range, then
safely cast to int32 for comparison with *portInfo.Port; apply the same guard
for the second occurrence around lines 213-233 (the portInt handling used with
cp.Spec.Egress and portInfo.Port).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 6afa11bf-3914-4be4-b861-58eff302d9bf

📥 Commits

Reviewing files that changed from the base of the PR and between a3fdc33 and 8bddfc7.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (26)
  • .gitignore
  • go.mod
  • pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/network.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/wildcard_test.go
  • tests/resources/network-wildcards/01-literal-ipv4.yaml
  • tests/resources/network-wildcards/02-literal-ipv6.yaml
  • tests/resources/network-wildcards/03-cidr-ipv4.yaml
  • tests/resources/network-wildcards/04-cidr-ipv6.yaml
  • tests/resources/network-wildcards/05-any-ip-sentinel.yaml
  • tests/resources/network-wildcards/06-any-as-cidr.yaml
  • tests/resources/network-wildcards/07-mixed-ip-list.yaml
  • tests/resources/network-wildcards/08-deprecated-ipaddress.yaml
  • tests/resources/network-wildcards/09-dns-literal.yaml
  • tests/resources/network-wildcards/10-dns-leading-wildcard.yaml
  • tests/resources/network-wildcards/11-dns-mid-ellipsis.yaml
  • tests/resources/network-wildcards/12-dns-trailing-star.yaml
  • tests/resources/network-wildcards/13-dns-trailing-dot-normalisation.yaml
  • tests/resources/network-wildcards/14-recursive-star-rejected.yaml
  • tests/resources/network-wildcards/15-egress-and-ingress.yaml
  • tests/resources/network-wildcards/16-egress-none.yaml
  • tests/resources/network-wildcards/17-realistic-stripe-api.yaml
  • tests/resources/network-wildcards/18-cluster-dns-via-mid-ellipsis.yaml
  • tests/resources/network-wildcards/19-port-protocol-with-cidr.yaml
  • tests/resources/network-wildcards/20-multi-container-mixed-wildcards.yaml
  • tests/resources/network-wildcards/README.md

Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go Outdated
Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go Outdated
Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/network.go
Comment thread tests/resources/network-wildcards/README.md Outdated
Five findings, all legit, all fixed:

- Port range guard (Major): wasAddressPortProtocolInEgress/Ingress now
  reject portInt outside [0, 65535] BEFORE narrowing to int32. Without
  this, a CEL value like 4294967739 wraps to 443 and would falsely
  match a port-443 entry. New TestWasAddressPortProtocolInEgress_
  PortWrapRejected pins the contract.

- neighborMatchesDNS now routes the deprecated singular DNS field
  through MatchDNS (single-element slice) instead of raw string
  equality, so back-compat behaviour gets the same trailing-dot
  stripping + lowercasing as the new DNSNames[]. New
  TestIsDomainInEgress_DeprecatedDNS_TrailingDotParity pins this.

- Direction-isolation fixture test now exercises BOTH
  wasAddressInEgress and wasAddressInIngress for each observation,
  via a new ipBothCheck struct. The prior version only checked egress,
  so a regression that broke ingress matching would have slipped through.

- TestFixturesParse uses yaml.UnmarshalStrict so a typo in any user-
  facing fixture (the YAML files double as documentation) fails the
  test instead of silently parsing.

- README clarifies that fixture 14 is intentionally rejected at
  admission and shouldn't be kubectl-applied — points readers at the
  index entry so they don't try to use it as a template.

Also bumps the storage replace to e1263bf6, which carries storage's CR
fixes (deprecated IPAddress validation, ValidateUpdate now also runs
network-profile validation, field-path assertions in admission tests).
@github-actions
Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Entlein added 2 commits May 10, 2026 19:42
Pulls in storage's CR round-2 fixes: deterministic admission error
ordering across container groups, and field-path assertions on the
ValidateUpdate test.
Pulls in storage's deprecated-DNS validation parity fix.
@github-actions
Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go`:
- Around line 10-12: Remove the unused imports "github.com/goradd/maps",
"github.com/kubescape/node-agent/pkg/objectcache", and
"github.com/kubescape/node-agent/pkg/objectcache/v1" from fixtures_test.go and
delete the corresponding blank identifier workaround declarations (the _ = ...
lines that reference those packages around lines 244-246); tests already use
buildLibWithContainer from wildcard_test.go in the same package so those imports
and blank identifier lines are unnecessary—simply delete the three import
entries and the three blank identifier lines to clean up the file.

In `@pkg/rulemanager/cel/libraries/networkneighborhood/network.go`:
- Around line 19-29: The deprecated IPAddress field in neighborMatchesIP is
compared using byte-equality while DNS uses MatchDNS normalization; clarify this
intentional asymmetry by either (a) adding a brief comment inside
neighborMatchesIP explaining that IPAddress uses strict byte-equality by design
(so formats like 192.168.001.1 or alternate IPv6 representations will not
match), or (b) if you want consistent behavior, route the deprecated IPAddress
through networkmatch.MatchIP (and remove the direct equality check) so both
deprecated and list fields use the same normalization; reference
neighborMatchesIP and networkmatch.MatchIP when making the change.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 96818701-da40-4299-af40-7865277ce05b

📥 Commits

Reviewing files that changed from the base of the PR and between 8bddfc7 and 07d4bc0.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (5)
  • go.mod
  • pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/network.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/wildcard_test.go
  • tests/resources/network-wildcards/README.md

Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go Outdated
Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/network.go
Two findings, both nitpick-level, both applied:

- Remove the unused 'maps', 'objectcache', 'objectcachev1' imports
  from fixtures_test.go along with the blank-identifier _ = ... lines
  at the bottom that existed only to silence the unused-import error.
  buildLibWithContainer is defined in wildcard_test.go (same package),
  so fixtures_test.go has no real need for those imports.

- Route the deprecated singular IPAddress through networkmatch.MatchIP
  for symmetry with the deprecated singular DNS (which round 1 already
  routed through MatchDNS). Both deprecated fields now get the same
  canonicalisation (IPv6 expanded forms, IPv4-mapped IPv6) as the new
  list fields. New TestWasAddressInEgress_DeprecatedIPAddress_
  IPv6Canonicalisation pins this.
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pkg/rulemanager/cel/libraries/networkneighborhood/network.go`:
- Around line 20-25: The deprecated neighbor.IPAddress is routed through
networkmatch.MatchIP which accepts wildcards/CIDRs, but tests only cover
literal/canonical IPs; add explicit coverage or documentation to define
backward-compat behavior. Either (A) add unit tests exercising
neighbor.IPAddress set to "*" and CIDR like "0.0.0.0/8" (mirror
TestWasAddressInEgress_AnyIPSentinel and TestWasAddressInEgress_* patterns) to
assert they match/ don’t match as intended, or (B) update the code comment near
neighbor.IPAddress and existing tests (e.g.,
TestWasAddressInEgress_LegacySingularStillWorks,
TestWasAddressInEgress_DeprecatedIPAddress_IPv6Canonicalisation) to state that
deprecated IPAddress only guarantees literal/canonical matching and should not
be relied on for wildcard/CIDR semantics; choose one approach and add the
corresponding test or comment to make the compatibility contract explicit.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c593d69d-c819-4111-bbc5-4ffe92eb0ed5

📥 Commits

Reviewing files that changed from the base of the PR and between 07d4bc0 and f89fc80.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (4)
  • go.mod
  • pkg/rulemanager/cel/libraries/networkneighborhood/fixtures_test.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/network.go
  • pkg/rulemanager/cel/libraries/networkneighborhood/wildcard_test.go

Comment thread pkg/rulemanager/cel/libraries/networkneighborhood/network.go
…nd 3)

CR caught that the round-2 routing of deprecated IPAddress through
MatchIP had a documentation gap: existing tests only proved literal
+ canonical (IPv6) matching, never the wildcard/CIDR semantics that
MatchIP now also enables on the deprecated field.

Adds TestWasAddressInEgress_DeprecatedIPAddress_AcceptsWildcardAndCIDR
which pins the contract: deprecated singular field accepts the SAME
wildcard token vocabulary as the new list form — '*' sentinel,
CIDRs, 0.0.0.0/0 and ::/0 alternatives. Comment on neighborMatchesIP
documents this is intentional unification, not accidental.
@github-actions
Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.000 0.000 N/A
Peak CPU (cores) 0.000 0.000 N/A
Avg Memory (MiB) 0.000 0.000 N/A
Peak Memory (MiB) 0.000 0.000 N/A
Dedup Effectiveness

No data available.

@github-actions
Copy link
Copy Markdown

Performance Benchmark Results

Node-Agent Resource Usage
Metric BEFORE AFTER Delta
Avg CPU (cores) 0.231 0.222 -4.0%
Peak CPU (cores) 0.241 0.232 -3.7%
Avg Memory (MiB) 294.223 273.949 -6.9%
Peak Memory (MiB) 295.727 275.648 -6.8%
Dedup Effectiveness (AFTER only)
Event Type Passed Deduped Ratio
capabilities 0 0 N/A
hardlink 6000 0 0.0%
http 1761 119399 98.5%
network 911 77989 98.8%
open 30704 621054 95.3%
symlink 6000 0 0.0%
syscall 983 1905 66.0%
Event Counters
Metric BEFORE AFTER
capability_counter 11 8
dns_counter 1441 1421
exec_counter 7210 7109
network_counter 94852 93482
open_counter 784710 773709
syscall_counter 3542 3510

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