[Backport v1.26] Avoid RBAC errors when Operator can't list or watch ConfigMaps#2900
Conversation
* Avoid RBAC errors when Operator can't list or watch ConfigMaps * Update access flag only if informer succeeded (#2894) --------- Co-authored-by: Timothée Bavelier <[email protected]> (cherry picked from commit d09fcb3)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: acd73e5967
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| ResourceAttributes: &authorizationv1.ResourceAttributes{ | ||
| Verb: verb, | ||
| Resource: "secrets", | ||
| Resource: resource, | ||
| }, |
There was a problem hiding this comment.
Scope RBAC preflight checks to watched namespaces
canListWatch builds a SelfSubjectAccessReview without setting ResourceAttributes.Namespace, which makes the authorization check evaluate list/watch for configmaps across all namespaces. In namespace-scoped deployments (for example when the manager cache is limited via watch-namespace settings and RBAC grants access only in those namespaces), this returns denied, so Start() leaves configMapAccessEnabled false and disables ConfigMap-based Helm metadata even though the informer would work for the watched namespace(s).
Useful? React with 👍 / 👎.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v1.26 #2900 +/- ##
==========================================
- Coverage 40.07% 40.05% -0.02%
==========================================
Files 319 319
Lines 28041 28052 +11
==========================================
Hits 11237 11237
- Misses 15982 15993 +11
Partials 822 822
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Backport d09fcb3 from #2889.
What does this PR do?
reported in #2886
Fix similar to #2793 for
configmapsMotivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
Minimum Agent Versions
Are there minimum versions of the Datadog Agent and/or Cluster Agent required?
Describe your test plan
kubectl get clusterrole operator-datadog-operator -o json \ | jq ' .rules |= map( if (.resources // [] | index("configmaps")) != null then .resources |= map(select(. != "configmaps")) else . end ) | .rules += [{"apiGroups":[""],"resources":["configmaps"],"verbs":["create","delete","get","patch","update"]}] ' \ | kubectl apply -f - kubectl rollout restart deployment/operator-datadog-operatorObserver errors
{"level":"ERROR","ts":"2026-04-10T14:22:21.312Z","logger":"controller-runtime.cache.UnhandledError","msg":"Failed to watch","reflector":"pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:289","type":"*v1.ConfigMap","error":"failed to list *v1.ConfigMap: configmaps is forbidden: User "system:serviceaccount:default:operator-datadog-operator" cannot list resource "configmaps" in API group "" in the namespace "default"","stacktrace":"k8s.io/apimachinery/pkg/util/runtime.logError\n\t/go/pkg/mod/k8s.io/[email protected]/pkg/util/runtime/runtime.go:221\n
Update to fixed image; after restart Operator should log
{"level":"INFO","ts":"2026-04-10T14:18:38.100Z","logger":"metadata.helm","msg":"No permission to list/watch ConfigMaps, Helm metadata collection from ConfigMaps will be disabled"}
Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel