Grant the k8s_attributes processor RBAC to the otel-agent container #3865
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
cyrille-leclerc
What does this PR do?
When the bundled DDOT Collector configuration,
spec.features.otelCollector.conf.configData, declares ak8s_attributesprocessor, theotelCollectorfeature grants the Datadog Agent's ServiceAccount the permissions that the processor needs to watch the pods:get,list, andwatchonpodsandnamespaces;get,list, andwatchonreplicasetsinapps.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). Sospec.override.nodeAgent.createRbac: falseremoves 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 ask8s_attributes/pods. A processor withpassthrough: truegets no RBAC: it only adds the pod IP, without calling the Kubernetes API. That's thedatadogHelm chart's rule, whose detection of thek8s_attributesname 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 thedatadogHelm chart'sdatadog.otelCollector.configMap.Fixes #3862
Motivation
The
k8s_attributesprocessor applies the OpenTelemetry Kubernetes resource attribute conventions, including theresource.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>-agentServiceAccount 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
K8S_NODE_NAME) thatk8s_attributesuses withfilter.node_from_env_var, on the same container (fixes #3863).nodespermissions aren't granted:k8s_attributesonly needs them to extract node metadata, such ask8s.node.uidor node labels, which users can add.configDataas YAML and reads the keys ofprocessors. 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
internal/controller/datadogagent/feature/otelcollector/rbac_test.go:-
Test_configHasK8sAttributesProcessorcoversk8s_attributes,k8s_attributes/<name>,k8sattributes,k8sattributes/<name>,passthrough: trueandfalse, a processor without settings, a processor whose name only containsk8s_attributes(transform/k8s_attributes), another processor with unusual settings, no processors, invalid YAML, and an empty configuration;-
Test_otelCollectorFeature_k8sAttributesRBACchecks that the ClusterRole and ClusterRoleBinding are created, with these rules and the Agent's ServiceAccount, for aconfigDatawithk8s_attributes. It also checks that they aren't created for the default configuration or a user-provided ConfigMap.-
Test_k8sAttributesRBAC_createRbacOverrideapplies the dependency overrides after the feature, and checks that the ClusterRole and ClusterRoleBinding stay withcreateRbacunset ortrue, and are removed withcreateRbac: false.go test ./internal/controller/datadogagent/...andgo vetpass.operator-render, built from this branch (make build-renderer):- a
DatadogAgentwhoseconfigDatahask8s_attributesrenders thedefault-datadog-otel-agent-k8s-attributesClusterRole, with these rules, and its ClusterRoleBinding to thedefault/datadog-agentServiceAccount;- a
DatadogAgentwith the default configuration renders no such ClusterRole;- the same
DatadogAgentas the first one, withoverride.nodeAgent.createRbac: false, renders no such ClusterRole either.DatadogAgentwhoseconfigDatahas ak8s_attributesprocessor, then checkkubectl auth can-i --as=system:serviceaccount:<namespace>:<name>-agent watch pods --all-namespaces, and that the logs of theotel-agentcontainer have nopods is forbiddenerrors.Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependencies:enhancement, to be added by a maintainerqa/skip-qalabel[1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
🤖 Generated with Claude Code