[Backport v1.25] Avoid RBAC errors when Operator can't list or watch Secrets#2800
[Backport v1.25] Avoid RBAC errors when Operator can't list or watch Secrets#2800
Conversation
* Avoid RBAC errors when Operator can't list or watch Secrets * improve comment (cherry picked from commit 444f938)
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b1718c2201
ℹ️ 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".
| sar := &authorizationv1.SelfSubjectAccessReview{ | ||
| Spec: authorizationv1.SelfSubjectAccessReviewSpec{ | ||
| ResourceAttributes: &authorizationv1.ResourceAttributes{ | ||
| Verb: verb, | ||
| Resource: "secrets", | ||
| }, |
There was a problem hiding this comment.
Scope the Secret RBAC check to watched namespaces
SelfSubjectAccessReview is created here without ResourceAttributes.Namespace, so it asks whether the operator may list/watch Secrets cluster-wide. In namespace-scoped installs, cmd/main.go uses config.CacheOptions, and pkg/config/config.go limits DefaultNamespaces from DD_AGENT_WATCH_NAMESPACE/WATCH_NAMESPACE; the Secret informer only needs access in those watched namespaces. A Role/RoleBinding deployment will therefore fail this check, set secretAccessEnabled=false, and stop collecting Helm metadata for Secret-backed releases even though GetInformer(&corev1.Secret{}) would have worked for the configured namespaces.
Useful? React with 👍 / 👎.
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (2.12%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## v1.25 #2800 +/- ##
==========================================
- Coverage 38.79% 38.77% -0.03%
==========================================
Files 309 309
Lines 26736 26755 +19
==========================================
Hits 10373 10373
- Misses 15584 15603 +19
Partials 779 779
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 444f938 from #2793.
What does this PR do?
Fixes bug reported in #2791.
Motivation
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("secrets")) != null then .resources |= map(select(. != "secrets")) else . end ) | .rules += [{"apiGroups":[""],"resources":["secrets"],"verbs":["create","delete","get","patch","update"]}] ' \ | kubectl apply -f - kubectl rollout restart deployment/operator-datadog-operatorObserver errors
..."logger":"klog","msg":"Failed to watch","logger":"UnhandledError","reflector":"pkg/mod/k8s.io/client-go@v0.33.3/tools/cache/reflector.go:285","type":"*v1.Secret","error":"failed to list *v1.Secret: secrets is forbidden: User \"system:serviceaccount:default:operator-datadog-operator\" cannot list resource \"secrets\" in API group \"\" inUpdate to fixed image; after restart Operator should log
{"level":"INFO","ts":"2026-03-20T19:23:55.561Z","logger":"metadata.helm","msg":"No permission to list/watch Secrets, Helm metadata collection from Secrets will be disabled"}Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel