← Back to Pull requests

Grant the k8s_attributes processor RBAC to the otel-agent container #3865

Open
unknown opened this pull request with 646 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 29, 2026 22:12 UTC
Author

What does this PR do?

When the bundled DDOT Collector configuration, spec.features.otelCollector.conf.configData, declares a k8s_attributes processor, the otelCollector feature grants the Datadog Agent's ServiceAccount the permissions that the processor needs to watch the pods:

  • get, list, and watch on pods and namespaces;

  • get, list, and watch on replicasets in apps.
  • These are the rules that the Operator already grants to the OTel Agent Gateway (GetDefaultOtelAgentGatewayClusterRolePolicyRules). They go in a dedicated ClusterRole and ClusterRoleBinding, <namespace>-<DatadogAgent name>-otel-agent-k8s-attributes, registered under the node Agent component (AddClusterPolicyRulesByComponent). So spec.override.nodeAgent.createRbac: false removes them, as it removes the other RBAC of the node Agent.

    The processor is detected by its name, k8s_attributes, or by its deprecated alias, k8sattributes, with or without a /<name> suffix, such as k8s_attributes/pods. A processor with passthrough: true gets no RBAC: it only adds the pod IP, without calling the Kubernetes API. That's the datadog Helm chart's rule, whose detection of the k8s_attributes name DataDog/helm-charts#3120 fixes (DataDog/helm-charts#3111).

    A configuration in a user-provided ConfigMap (conf.configMap) can't be inspected when the Operator builds the RBAC, so its users keep granting the permissions, as with the datadog Helm chart's datadog.otelCollector.configMap.

    Fixes #3862

    Motivation

    The k8s_attributes processor applies the OpenTelemetry Kubernetes resource attribute conventions, including the resource.opentelemetry.io/<attribute> pod annotations (extract.otel_annotations: true). It's a common addition to the bundled DDOT Collector configuration.

    The ClusterRole that the Operator creates for the Datadog Agent has no rules for pods, namespaces, or ReplicaSets. On a cluster with Operator 1.32.0, the <name>-agent ServiceAccount could only list and watch pods through an extra ClusterRole that I created and bound to it. Users have to create and bind that ClusterRole themselves today.

    Additional Notes

  • Related: #3864 adds the node name (K8S_NODE_NAME) that k8s_attributes uses with filter.node_from_env_var, on the same container (fixes #3863).

  • nodes permissions aren't granted: k8s_attributes only needs them to extract node metadata, such as k8s.node.uid or node labels, which users can add.

  • The detection parses configData as YAML and reads the keys of processors. An invalid configuration doesn't grant anything.
  • Minimum Agent Versions

    None: these are Kubernetes RBAC rules for the existing otel-agent container.

    Describe your test plan

  • New unit tests in internal/controller/datadogagent/feature/otelcollector/rbac_test.go:

  • - Test_configHasK8sAttributesProcessor covers k8s_attributes, k8s_attributes/<name>, k8sattributes, k8sattributes/<name>, passthrough: true and false, a processor without settings, a processor whose name only contains k8s_attributes (transform/k8s_attributes), another processor with unusual settings, no processors, invalid YAML, and an empty configuration;
    - Test_otelCollectorFeature_k8sAttributesRBAC checks that the ClusterRole and ClusterRoleBinding are created, with these rules and the Agent's ServiceAccount, for a configData with k8s_attributes. It also checks that they aren't created for the default configuration or a user-provided ConfigMap.
    - Test_k8sAttributesRBAC_createRbacOverride applies the dependency overrides after the feature, and checks that the ClusterRole and ClusterRoleBinding stay with createRbac unset or true, and are removed with createRbac: false.
  • go test ./internal/controller/datadogagent/... and go vet pass.

  • operator-render, built from this branch (make build-renderer):

  • - a DatadogAgent whose configData has k8s_attributes renders the default-datadog-otel-agent-k8s-attributes ClusterRole, with these rules, and its ClusterRoleBinding to the default/datadog-agent ServiceAccount;
    - a DatadogAgent with the default configuration renders no such ClusterRole;
    - the same DatadogAgent as the first one, with override.nodeAgent.createRbac: false, renders no such ClusterRole either.
  • To test on a cluster: deploy a DatadogAgent whose configData has a k8s_attributes processor, then check kubectl auth can-i --as=system:serviceaccount:<namespace>:<name>-agent watch pods --all-namespaces, and that the logs of the otel-agent container have no pods is forbidden errors.
  • Checklist

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies: enhancement, to be added by a maintainer

  • PR has a milestone or the qa/skip-qa label

  • All commits are signed (see: [signing commits][1])
  • [1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

    🤖 Generated with Claude Code

    Diff: 646 lines (+484 / -162) across 8 files Reviewer: cyrille-leclerc Review duration: 2983m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.75) × (1 − Review Confidence (0.44)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 646 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.387
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #3865"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 44.2% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.2% · Lower = rushed or shallow review
    44.2%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 41.9% · Moderate risk
    41.9%