Add RBAC for Gateway API, service mesh, and ingress controller CRDs#2874
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2874 +/- ##
==========================================
+ Coverage 42.24% 43.59% +1.34%
==========================================
Files 337 340 +3
Lines 28951 30262 +1311
==========================================
+ Hits 12230 13192 +962
- Misses 15916 16225 +309
- Partials 805 845 +40
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 28 files with indirect coverage changes Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
…mesh, and ingress controllers (#48966) ### What does this PR do? Adds 22 new builtin CRD entries to the orchestrator explorer so Cloud Security can determine internet-reachability paths for k8s workloads. Uses a hybrid collection strategy: resource-specific entries for high-volume vendors (Istio, NGINX, Traefik) and group-level entries for less common vendors. Three new per-family config flags (all **opt-in, default: false**): - `orchestrator_explorer.custom_resources.ootb.gateway_api` - `orchestrator_explorer.custom_resources.ootb.service_mesh` - `orchestrator_explorer.custom_resources.ootb.ingress_controllers` **New families:** - **Gateway API** (5 resource-specific): gateways, httproutes, grpcroutes, tlsroutes, listenersets - **Service mesh — Istio** (5 resource-specific): virtualservices, gateways, destinationrules, serviceentries, sidecars (with v1beta1 fallback) - **Service mesh — others** (6 group-level): Envoy Gateway, Traefik (legacy), Linkerd, Consul, Consul Mesh, Kuma - **Ingress controllers — NGINX** (2 resource-specific): virtualservers, virtualserverroutes - **Ingress controllers — Traefik** (1 resource-specific): ingressroutes - **Ingress controllers — others** (3 group-level): Kong, HAProxy Core, HAProxy v1 ### Motivation Cloud Security needs to tell customers which container workloads are internet-reachable. Today, the agent collects standard Ingress and Service objects, covering ~16% of EKS customers. Over 36% use service meshes or non-standard ingress controllers whose exposure paths go through CRDs we don't collect. RFC: https://datadoghq.atlassian.net/wiki/x/4IOyfAE Technical implementation: https://datadoghq.atlassian.net/wiki/x/EgO6fAE ### Describe how you validated your changes - All existing tests pass: `TestNewBuiltinCRDConfigs`, `TestImportBuiltinCollectors`, `TestGetDatadogCustomResourceCollectors`, `TestFilterCRCollectorsByPermission` - New test `TestNewBuiltinCRDConfigsPerFamilyFlags` verifies each per-family flag independently disables its family, and the global OOTB flag disables everything - Package compiles cleanly with `go build -tags "kubeapiserver orchestrator"` ### Additional Notes **All three flags default to `false` (opt-in).** Collection is only activated when RBAC is granted (via helm/operator) and the corresponding flag is set to `true`. **Merge order:** The backend allowlist PR (dd-go) must be deployed before this PR merges, otherwise collected CRs will be silently dropped. - [ ] Backend allowlist deployed: DataDog/dd-go#230589 - [ ] Helm chart RBAC merged: DataDog/helm-charts#2541 - [ ] Operator RBAC merged: DataDog/datadog-operator#2874 ## Related PRs | Repo | PR | Purpose | |------|----|---------| | DataDog/dd-go | DataDog/dd-go#230589 | Backend allowlist (deploy FIRST) | | DataDog/helm-charts | DataDog/helm-charts#2541 | Helm chart RBAC | | DataDog/datadog-operator | DataDog/datadog-operator#2874 | Operator RBAC | Co-authored-by: eliott.bouhana <[email protected]>
kangyili
left a comment
There was a problem hiding this comment.
They're just RBACs, I think we can remove this featureflag NetworkCRDsConfig.Enabled.
Add opt-in `networkCRDs.enabled` boolean to OrchestratorExplorerFeatureConfig that grants list/watch RBAC for 15 API groups used by Gateway API, service mesh (Istio, Envoy Gateway, Traefik Legacy, Linkerd, Consul, Kuma), and ingress controllers (NGINX, Traefik, Kong, HAProxy). Uses resource-specific rules for high-volume vendors (Gateway API, Istio, NGINX, Traefik) and group-level wildcards for the long tail. Also replaces inline string literals in appsec RBAC with shared constants.
The gci formatter requires a blank line between the Traefik resources block and the general resources block, and re-aligns the equals signs to match the new block's column width.
…agent
When networkCRDs.enabled=true, set all three per-family agent config flags
on the cluster-agent pod so collection is activated alongside the RBAC:
DD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_GATEWAY_API=true
DD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_SERVICE_MESH=true
DD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_INGRESS_CONTROLLERS=true
These map to orchestrator_explorer.custom_resources.ootb.{gateway_api,
service_mesh,ingress_controllers} in the agent config (DataDog/datadog-agent#48966).
974bcf2 to
2426537
Compare
|
🎯 Code Coverage (details) 🔗 Commit SHA: 2494f0a | Docs | Datadog PR Page | Give us feedback! |
Cover the collectKubernetesNetworkResources=true code paths in orchestrator explorer: RBAC policy rules for Gateway API, service mesh, and ingress controller API groups, plus the three OOTB env vars forwarded to the cluster-agent.
tbavelier
left a comment
There was a problem hiding this comment.
Looks on the principle, but 2 points of attention:
- If we can avoid a temporary CRD, we absolutely want to do it. The CRD is long-lived and is not meant to be used as a temporary flag setter
- Operator RBACs should be updated to be able to grant them to DCA/component that runs the collection
| if orchestratorExplorer.NetworkCRDs != nil { | ||
| f.collectKubernetesNetworkResources = apiutils.BoolValue(orchestratorExplorer.NetworkCRDs.Enabled) | ||
| } |
There was a problem hiding this comment.
see previous comment on how this could be enabled with featureutils.HasFeatureEnableAnnotation to avoid "polluting" the CRD with a flag that is "temporary"/not really meant to be toggled off once enabled (and eventually, the annotation is removed, it just becomes true by default in code)
Replace spec.features.orchestratorExplorer.networkCRDs.enabled with agent.datadoghq.com/network-crds-enabled annotation to avoid polluting the long-lived CRD with a temporary opt-in flag. Add kubebuilder RBAC markers for the 13 new API groups so the operator ClusterRole can grant those permissions to the cluster-agent. Constraint: CRD fields are hard to deprecate once shipped Rejected: Keep CRD field | reviewer feedback that annotation is preferred for experimental features Confidence: high Scope-risk: narrow
What does this PR do?
Adds list/watch RBAC permissions for 14 new API groups to the cluster agent ClusterRole, enabling OOTB collection of network topology CRDs for Cloud Security internet-reachability analysis.
Gated behind the
agent.datadoghq.com/network-crds-enabled: "true"annotation on the DatadogAgent resource (default: disabled, opt-in).New API groups:
gateway.networking.k8s.io(resource-specific)networking.istio.io(resource-specific),gateway.envoyproxy.io,traefik.containo.us,policy.linkerd.io,consul.hashicorp.com,mesh.consul.hashicorp.com,kuma.iok8s.nginx.org,traefik.io(resource-specific),configuration.konghq.com,core.haproxy.org,ingress.v1.haproxy.orgMotivation
The Datadog Agent is adding OOTB collection of these CRDs for Cloud Security internet-reachability analysis. The operator needs to grant the cluster agent RBAC permissions to list/watch these resources.
RFC: https://datadoghq.atlassian.net/wiki/x/4IOyfAE
Describe how you validated your changes
featureutils.HasFeatureEnableAnnotation(same pattern asprivateactionrunner,hostprofiler,flightrecorder)pkg/kubernetes/rbac/const.goQA Instructions
1. Deploy the operator on a kind cluster
2. Apply a DatadogAgent CR with the network CRDs annotation
3. Verify the ClusterRole contains the new network CRD permissions
All 13 groups should be present with
["list","watch"]verbs.4. Verify the env vars are forwarded to the cluster-agent container
Expected:
DD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_GATEWAY_API=trueDD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_SERVICE_MESH=trueDD_ORCHESTRATOR_EXPLORER_CUSTOM_RESOURCES_OOTB_INGRESS_CONTROLLERS=true5. Verify annotation disabled does NOT add the rules
Apply a CR without the annotation and confirm the ClusterRole does NOT contain the 13 new API groups.
6. Check operator logs for errors
No RBAC-related errors should appear.
Additional Notes
This PR should be merged before the corresponding agent PR. Collection is opt-in — both the operator annotation and the agent-side flags must be enabled.
Related PRs