Repository navigation
fix: do not panic when a trap matches resources by namespace only - #61
Merged
Merged
Conversation
MatchResources.Any[].selector is optional, and the README documents that a trap may set only namespaces. Both policy generators dereferenced it unconditionally, so such a trap panicked the reconcile loop after the decoys had already been placed, leaving honeytokens without a captor policy. Skip filters without a selector, as the decoy path in matching.go already does.
Trap.IsValid() dereferenced value.Selector.MatchLabels whenever Namespaces was empty, so an explicit `namespaces: []` with no selector panicked the same way the policy generators did before this PR, instead of returning the intended validation error. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Member
|
Excellent finding again, thank you very much! Will digging through the diff, I found another related issue in |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
MatchResources.Any[].selectoris optional, and the README says a trap only needs one ofnamespacesorselector. both policy generators dereference the selector without checking it, so a trap that matches by namespace alone panics the reconcile loopthe timing makes it worse than a plain nil deref:
reconcileDecoysruns beforereconcileCaptors, so the honeytoken files are already written into the workload containers when the panic happens. the TracingPolicy or KivePolicy is never created, so the decoys sit there with nothing watching them, and the panic repeats on every reconcilea minimal policy that triggers it:
Changes
skip resource filters that have no selector, which is what the decoy path in
matching.goalready does (lines 175 and 199). the three affected spots aregenerateTetragonTracingPolicyand both branches ofgenerateKivePolicyTesting
added a spec that generates both policy types from a namespace-only trap. it panics with
invalid memory address or nil pointer dereferencebefore the change and passes aftergo test ./internal/... ./api/...is green. theinternal/controllersuite needs the envtest binaries, which I do not have locally, and it fails the same way on an unmodified checkout