Skip to content

[Backport v1.26] Avoid RBAC errors when Operator can't list or watch ConfigMaps#2900

Merged
tbavelier merged 2 commits into
v1.26from
backport-2889-to-v1.26
Apr 14, 2026
Merged

[Backport v1.26] Avoid RBAC errors when Operator can't list or watch ConfigMaps#2900
tbavelier merged 2 commits into
v1.26from
backport-2889-to-v1.26

Conversation

@dd-octo-sts

@dd-octo-sts dd-octo-sts Bot commented Apr 14, 2026

Copy link
Copy Markdown

Backport d09fcb3 from #2889.


What does this PR do?

reported in #2886

Fix similar to #2793 for configmaps

  • Don't start CM watch in helm metadata forwarder if Operator doesn't have list/watch RBAC.

Motivation

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?

  • Agent: vX.Y.Z
  • Cluster Agent: vX.Y.Z

Describe your test plan

  1. install Operator
❯ helm install operator datadog/datadog-operator \
--set datadogMonitor.enabled=true \
--set datadogAgent.enabled=false \
--set datadogAgentInternal.enabled=false
  1. Update rbac to drop secret watch, list permissions, restart operator pod.
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-operator
  1. Observer 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

  2. 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

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies
  • PR has a milestone or the qa/skip-qa label
  • All commits are signed (see: signing commits)

* 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)
@dd-octo-sts dd-octo-sts Bot added bug Something isn't working backport label added by backport action labels Apr 14, 2026
@dd-octo-sts
dd-octo-sts Bot requested a review from a team as a code owner April 14, 2026 07:06
@dd-octo-sts dd-octo-sts Bot added bot label added by backport bot team/container-platform labels Apr 14, 2026
@dd-octo-sts dd-octo-sts Bot added this to the v1.26.0 milestone Apr 14, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines 172 to 175
ResourceAttributes: &authorizationv1.ResourceAttributes{
Verb: verb,
Resource: "secrets",
Resource: resource,
},

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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-commenter

codecov-commenter commented Apr 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 40.05%. Comparing base (7d61c8e) to head (b551098).

Files with missing lines Patch % Lines
pkg/controller/utils/metadata/helm_metadata.go 0.00% 47 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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              
Flag Coverage Δ
unittests 40.05% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
pkg/controller/utils/metadata/helm_metadata.go 25.89% <0.00%> (-0.88%) ⬇️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7d61c8e...b551098. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tbavelier
tbavelier merged commit 35f861a into v1.26 Apr 14, 2026
34 checks passed
@tbavelier
tbavelier deleted the backport-2889-to-v1.26 branch April 14, 2026 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport label added by backport action bot label added by backport bot bug Something isn't working team/container-platform

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants