fix: add SPIRE trust bundle ConfigMap to scoped cache#271
fix: add SPIRE trust bundle ConfigMap to scoped cache#271ChristianZaccaria wants to merge 2 commits intokagenti:mainfrom
Conversation
84b2051 to
bee259d
Compare
varshaprasad96
left a comment
There was a problem hiding this comment.
@ChristianZaccaria The changes look good!
Since this is a sensitive change - its related to cache, and if we don't end up spinning right set of informers, our controller would just not work and fail silently - can we have some tests to cover this? (E2E or unit using env test would also be good).
pdettori
left a comment
There was a problem hiding this comment.
Clean, well-motivated fix. The SPIRE trust bundle ConfigMap is managed by SPIRE (no kagenti labels), so using a field selector on metadata.name is the correct approach. Code is well-commented, the conditional guard is correct, and the E2E workaround removal is clean.
Areas reviewed: Go (cmd/main.go), E2E test utilities, CI
Commits: 1 commit, signed-off: yes
CI status: E2E failing — pre-existing flaky metrics test already fixed on main in PR #267. Rebase should resolve it.
kagenti-operator/cmd/main.go
Outdated
| controller.LabelNamespaceDefaults: "true", | ||
| }), | ||
| }, | ||
| } |
There was a problem hiding this comment.
suggestion: Namespace collision edge case — if spireTrustBundleConfigMapNS equals controller.ClusterDefaultsNamespace (typically kagenti-system), this map assignment overwrites the existing label-selector entry, losing cache visibility of kagenti-platform-config and kagenti-feature-gates.
Unlikely in practice (SPIRE is usually in spire-system), but a defensive check or at minimum a comment documenting the assumption would prevent a subtle silent failure:
if spireTrustBundleConfigMapNS == controller.ClusterDefaultsNamespace {
// Log a warning or merge selectors
}There was a problem hiding this comment.
Thanks Paolo, great suggestion and a real edge case.
I've added a defensive check: if spireTrustBundleConfigMapNS collides with an existing cache-scoped namespace (e.g. kagenti-system), we skip the SPIRE entry and log an error explaining that the trust bundle won't be cached and signature verification may fail. The operator stays operational, and the cluster defaults remain visible, and the admin gets a clear message to use a different namespace for the trust bundle ConfigMap.
kagenti-operator/cmd/main.go
Outdated
| controller.LabelNamespaceDefaults: "true", | ||
| }), | ||
| }, | ||
| } |
There was a problem hiding this comment.
suggestion: +1 to @varshaprasad96's request for tests. This is a sensitive cache-scoping change with a silent failure mode (Get returns "not found" if the informer doesn't cover the resource). A unit test using envtest that:
- Creates the SPIRE trust bundle ConfigMap
- Verifies it's visible through the manager's cache when
requireA2ASignature=true - Verifies existing kagenti ConfigMaps remain visible
would catch regressions and document the expected behavior.
| By("labeling spire-bundle configmap for controller cache visibility") | ||
| cmd = exec.Command("kubectl", "label", "--overwrite", "configmap", "spire-bundle", | ||
| "-n", "spire-system", "kagenti.io/defaults=true") | ||
| _, err := Run(cmd) |
There was a problem hiding this comment.
praise: Clean removal of the workaround — the operator now handles cache visibility properly via field selector, so the manual labeling hack is no longer needed.
Thank you for reviewing Varsha, and the great suggestion. I think having tests to protect this code is vital too. I've Added both unit tests and an envtest-based test. The unit tests validate the cache config building logic, correct entries for each flag combination, and the namespace collision edge case mentioned by Paolo. The envtest test starts a real Both tests run automatically in CI |
Signed-off-by: ChristianZaccaria <christian.zaccaria.cz@gmail.com>
8253d0b to
66fd8f5
Compare
Summary
metadata.name, conditionally when--require-a2a-signature=truespire-bundlewithkagenti.io/defaults=trueCloses #251
Previously
The ConfigMap cache was scoped to kagenti-labeled ConfigMaps only. The SPIRE trust bundle (e.g.
spire-bundle) is managed by SPIRE and has no kagenti labels, somgr.GetClient().Get()returned "not found". Signature verification failed silently andSignatureVerifiedstayedFalse. This PR fixes this by adding a field selector entry for the trust bundle ConfigMap to the cache when signature verification is enabled.Test plan
"Signature verification enabled"with no trust bundle errors.