Commit ae05ce6
authored
fix(cluster-agent): gate pprof/expvar debug endpoints to loopback (#54508)
### What does this PR do?
The Cluster Agent's metrics server (`0.0.0.0:metrics_port`, default `5000`) served the entire `http.DefaultServeMux`, exposing the `pprof` and `expvar` debug endpoints (registered via blank imports in `cmd/cluster-agent/main.go`) unauthenticated to anything that can reach the pod. This routes only `/metrics` on the public mux and gates everything under `/debug/` to loopback callers, returning `404` to non-loopback requests.
### Motivation
Solves #CONTP-1771 and #VULN-87907.
`/metrics` must stay reachable off-pod so the node Agent can scrape Cluster Agent telemetry, so a blanket localhost bind (like the core Agent's expvar server) isn't viable — hence a per-path loopback gate. This removes an unauthenticated, network-reachable debug/DoS surface while preserving telemetry scraping and local flare tooling.
### Describe how you validated your changes
- Unit tests (`TestLoopbackOnly`, `TestMetricsMuxRouting`) covering loopback vs off-host for `/metrics` and `/debug/*` — 16/16 pass.
- `dda inv cluster-agent.build` links clean; `dda inv linter.go` clean; release-note lint clean.
- Generated a flare.
- Deployed the built cluster-agent image to a local minikube cluster and curled the live DCA pod:
- **In-pod** (loopback `127.0.0.1:5000`): `/metrics`, `/debug/vars`, `/debug/pprof/*` all `200` — flare/profiler unaffected.
- **Off-pod** (from a separate pod → DCA pod IP): `/debug/*` = `404`, `/metrics` = `200`.
- Verified nothing else is registered on the DCA's `DefaultServeMux` (only `pprof`/`expvar`), so no routes are dropped.
### Additional Notes
Brings the DCA in line with the core Agent, which already binds its equivalent `pprof`/`expvar` server to `127.0.0.1`, while keeping `/metrics` public.
Co-authored-by: wassim.dhif <wassim.dhif@datadoghq.com>1 parent 0b134fc commit ae05ce6
4 files changed
Lines changed: 149 additions & 3 deletions
File tree
- cmd/cluster-agent/subcommands/start
- releasenotes-dca/notes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2163 | 2163 | | |
2164 | 2164 | | |
2165 | 2165 | | |
| 2166 | + | |
2166 | 2167 | | |
2167 | 2168 | | |
2168 | 2169 | | |
2169 | 2170 | | |
2170 | 2171 | | |
| 2172 | + | |
2171 | 2173 | | |
2172 | 2174 | | |
2173 | 2175 | | |
2174 | 2176 | | |
2175 | 2177 | | |
| 2178 | + | |
2176 | 2179 | | |
2177 | 2180 | | |
2178 | 2181 | | |
2179 | 2182 | | |
2180 | 2183 | | |
| 2184 | + | |
2181 | 2185 | | |
2182 | 2186 | | |
2183 | 2187 | | |
2184 | 2188 | | |
2185 | 2189 | | |
| 2190 | + | |
2186 | 2191 | | |
2187 | 2192 | | |
2188 | 2193 | | |
2189 | 2194 | | |
2190 | 2195 | | |
| 2196 | + | |
2191 | 2197 | | |
2192 | 2198 | | |
2193 | 2199 | | |
2194 | 2200 | | |
2195 | 2201 | | |
| 2202 | + | |
2196 | 2203 | | |
2197 | 2204 | | |
2198 | 2205 | | |
2199 | 2206 | | |
2200 | 2207 | | |
| 2208 | + | |
2201 | 2209 | | |
2202 | 2210 | | |
2203 | 2211 | | |
2204 | 2212 | | |
2205 | 2213 | | |
| 2214 | + | |
2206 | 2215 | | |
2207 | 2216 | | |
2208 | 2217 | | |
2209 | 2218 | | |
2210 | 2219 | | |
| 2220 | + | |
2211 | 2221 | | |
2212 | 2222 | | |
2213 | 2223 | | |
2214 | 2224 | | |
2215 | 2225 | | |
| 2226 | + | |
2216 | 2227 | | |
2217 | 2228 | | |
2218 | 2229 | | |
2219 | 2230 | | |
2220 | 2231 | | |
| 2232 | + | |
2221 | 2233 | | |
2222 | 2234 | | |
2223 | 2235 | | |
2224 | 2236 | | |
2225 | 2237 | | |
| 2238 | + | |
2226 | 2239 | | |
2227 | 2240 | | |
2228 | 2241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
332 | 333 | | |
333 | 334 | | |
334 | 335 | | |
335 | | - | |
336 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
337 | 345 | | |
338 | 346 | | |
339 | 347 | | |
340 | | - | |
| 348 | + | |
341 | 349 | | |
342 | 350 | | |
343 | 351 | | |
| |||
776 | 784 | | |
777 | 785 | | |
778 | 786 | | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
779 | 806 | | |
780 | 807 | | |
781 | 808 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
38 | 42 | | |
39 | 43 | | |
40 | 44 | | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments