[Feature] Generic CRD/operator-aware reference resolution for Secrets/ConfigMaps (POP-400 false positives)
Is your feature request related to a problem? Please describe.
POP-400 ("Used? Unable to locate resource reference") on Secrets/ConfigMaps has a systematic class of false positives that isn't about a missing native-K8s scanner (like #173, fixed by adding Job/CronJob PVC refs) — it's that a Secret/ConfigMap can be legitimately consumed by a third-party CRD's spec, or read directly by an operator's own controller via the API (never mounted in any Pod spec at all). Popeye's Secret/ConfigMap linters only look at cache.PodRefs/ServiceAccountRefs/IngressRefs (internal/lint/sec.go, internal/lint/cm.go), so any of these patterns are unconditionally flagged:
ClusterSecretStore.spec.provider.doppler.auth.secretRef(external-secrets.io)MariaDB.spec.tls/.spec.metrics.passwordSecretKeyRef(mariadb-operator)ClusterIssuer.spec.acme.privateKeySecretRef(cert-manager)Gateway.spec.listeners[].tls.certificateRefs(Gateway API)- Grafana's sidecar (
kiwigrid/k8s-sidecar) discovering ConfigMaps by label via the API, not via envFrom/volumeMount - Argo CD / Helm / Cilium reading their own state Secrets directly via the API, never mounting them
None of these are misconfigurations — they're real references Popeye structurally can't see, because it only understands the Pod spec's env/volume shape.
I ran into ~100 instances of this across a single production cluster (mostly ESO, cert-manager, mariadb-operator, Gateway API, Kyverno's self-managed webhook certs, and Grafana dashboard ConfigMaps). I worked around it locally with per-FQN excludes.linters.{secrets,configmaps}.instances[].codes: [400], which works fine but requires knowing in advance exactly which resources are false positives — it doesn't scale to N clusters or new operators.
I searched existing issues/PRs and didn't find one covering this specific pattern (closest precedents: #173 for Job/CronJob→PVC refs, #366 for projected volumes — both extended internal/cache for native K8s Pod-spec shapes, not third-party CRDs).
Describe the solution you'd like
I don't think Popeye should special-case every operator (that doesn't scale and adds maintenance burden / dependencies for CRD types Popeye doesn't own — happy to be told otherwise). What might: Popeye already has all the plumbing needed to read any CRD generically — internal/dao/generic.go (dynamic client over unstructured.Unstructured) and Loader.LoadGeneric() are already used internally for Cilium's CiliumNetworkPolicy/CiliumClusterwideNetworkPolicy (internal/db/loader.go).
Proposal: a declarative, user-configurable "custom reference" mechanism in spinach.yaml that reuses that existing dynamic-client infra to populate the same refs map that sec.go/cm.go already consume — no new Go types, no vendoring third-party CRD schemas:
popeye:
customRefs:
secrets:
- gvr: external-secrets.io/v1beta1/clustersecretstores
jsonPath: spec.provider.doppler.auth.secretRef.name
namespaceJsonPath: spec.provider.doppler.auth.secretRef.namespace # optional, defaults to CR's own ns
- gvr: k8s.mariadb.com/v1alpha1/mariadbs
jsonPath: spec.tls.caSecretKeyRef.name # illustrative
configmaps:
- gvr: v1/configmaps
labelSelector: grafana_dashboard=1 # "matches this selector" = "considered used", no jsonPath neededImplementation sketch (roughly the size of #224, ~200-400 LOC + tests):
- New config struct in
pkg/config(CustomRefsunderPopeye), parsed/validated invalidateSpinach(). - A new
cache.CustomRefs(or similar) that, for each configuredgvr, callsLoader.LoadGeneric(ctx, gvr)(already tolerant of CRDs not installed in the cluster — would need to confirm/harden that path) and walksunstructured.NestedString(obj.Object, jsonPathParts...)to populate the samesync.Mapviacache.ResFqn(cache.SecretKey, fqn)/ResFqn(cache.ConfigMapKey, fqn). - One extra call added to
Secret.Lint()/ConfigMap.Lint()(internal/lint/sec.go:43-51,internal/lint/cm.go:39-42), same pattern as the existingServiceAccountRefs/IngressRefscalls.
This also generalizes cleanly to any future "operator writes/reads a Secret via its own controller" pattern (Kyverno's self-managed webhook TLS, Cilium's ClusterMesh sync secrets, Argo CD's internal state) via the labelSelector-only form, without Popeye needing to know what those operators are.
Describe alternatives you've considered
- Per-cluster
excludes.linters.secrets/configmaps.instances[].codes: [400]— works today, is what I'm using as a stopgap, but doesn't scale (must be re-derived per cluster/per new resource, and gives zero positive signal that the reference actually exists — it's just "trust me"). - Hardcoding support for specific popular operators (à la the existing Cilium CRD handling) — considered and rejected in this proposal on purpose; happy to discuss if the maintainers would actually prefer that route for a short list of very common operators (cert-manager, ESO) vs. the generic mechanism above.
Additional context
Happy to put together a PR for the generic mechanism if this shape is roughly acceptable — wanted to check appetite/design direction first given the scope (new config surface) before investing the time.
Source: derailed/popeye