Commit 68e4d34
authored
VULN-92045 resolve DatadogMetric references in the referencing namespace (#54218)
<!-- dd-meta {"pullId":"00000000-0000-0000-0000-000000000000","source":"chat","resourceId":"c4ad7c08-91ff-417c-ba4c-46e80bea665a","workflowId":"8c98a1cb-9292-475c-92c3-1ad5cdb2fd04","codeChangeId":"8c98a1cb-9292-475c-92c3-1ad5cdb2fd04","sourceType":"chat"} -->
<!--Please give us some feedback on your experience writing this PR ! https://app.datadoghq.com/forms/43db4c02-6837-400c-8083-692e141b1b88 !-->
### What does this PR do?
Makes a `datadogmetric@<namespace>:<name>` external metric reference always resolve in the namespace of the object doing the referencing, instead of the namespace embedded in the metric name.
- `metricNameToDatadogMetricID` now takes the referencing namespace and builds the DatadogMetric ID from it. The `<namespace>:` part of the reference becomes an optional group in the parser and is discarded at read time.
- `datadogMetricProvider.getExternalMetric` passes the request namespace, so a request from namespace `A` for `datadogmetric@B:name` looks up `A/name` and returns the usual not-found error.
- `AutoscalerWatcher.extractAutoscalerReference` passes the HPA/WPA namespace, so a cross-namespace reference can no longer mark a foreign DatadogMetric active or make `metrics_retriever` refresh it.
- `datadogmetric@<name>` (no namespace) is now a valid reference and resolves to the referencing namespace, so the namespace is only ever redundant, never meaningful.
- Adds coverage for a tenant namespace attempting to read or activate a DatadogMetric owned by another namespace, and for the namespace-less reference form.
### Motivation
Addresses VULN-92045. The external metrics provider resolved a DatadogMetric using only the namespace embedded in the metric name, with no comparison against the namespace the request was authorized for. In a multi-tenant cluster, tenant `A` could read tenant `B`'s DatadogMetric values, and — through the autoscaler watcher — mark `B`'s DatadogMetrics active, mutating their status and forcing their Datadog queries to run against shared API quota.
Cross-namespace sharing was the original intent of the `<namespace>:` syntax, but it has no authorization model behind it. Rather than adding one, this PR drops the capability and keeps the syntax accepted-but-ignored so existing same-namespace manifests keep working unchanged.
### Describe how you validated your changes
- `dda inv test --targets=./pkg/clusteragent/autoscaling/externalmetrics --build-include=kubeapiserver,test` — 110 tests pass. (The `test` build tag is required, otherwise `datadogmetric_controller_test.go` fails to build against `autoscaling.FilterInformerActions`.)
- `dda inv linter.go --targets=./pkg/clusteragent/autoscaling/externalmetrics --build-tags=kubeapiserver,test` — 0 issues.
### Additional Notes
Behavior change for anyone relying on cross-namespace references: an HPA in namespace `A` pointing at `datadogmetric@B:name` now resolves to `A/name` and fails as not-found rather than reading `B/name`. There is no way to opt back in.
`datadogmetric@:<name>` (empty namespace) does not parse, matching the behavior before this PR.
Created by Auto-JIRA (https://github.com/DataDog/datadog-agent/blob/main/.agents/skills/auto-jira/SKILL.md).
---
PR by Bits - [View session in Datadog](https://app.datadoghq.com/code/c4ad7c08-91ff-417c-ba4c-46e80bea665a)
Comment @DataDog to request changes
Co-authored-by: hasan.mahmood <hasan.mahmood@datadoghq.com>1 parent 8cc30d2 commit 68e4d34
7 files changed
Lines changed: 192 additions & 28 deletions
File tree
- pkg/clusteragent/autoscaling/externalmetrics
- releasenotes-dca/notes
Lines changed: 6 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | | - | |
| 303 | + | |
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
344 | 344 | | |
345 | 345 | | |
346 | 346 | | |
| |||
356 | 356 | | |
357 | 357 | | |
358 | 358 | | |
359 | | - | |
| 359 | + | |
360 | 360 | | |
361 | 361 | | |
362 | 362 | | |
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
382 | 382 | | |
383 | 383 | | |
384 | 384 | | |
| 385 | + | |
385 | 386 | | |
386 | 387 | | |
387 | 388 | | |
388 | 389 | | |
389 | 390 | | |
390 | 391 | | |
391 | 392 | | |
392 | | - | |
| 393 | + | |
393 | 394 | | |
394 | 395 | | |
395 | 396 | | |
| |||
Lines changed: 70 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| |||
180 | 180 | | |
181 | 181 | | |
182 | 182 | | |
183 | | - | |
| 183 | + | |
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
191 | | - | |
| 191 | + | |
192 | 192 | | |
193 | 193 | | |
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | 197 | | |
198 | 198 | | |
199 | | - | |
| 199 | + | |
200 | 200 | | |
201 | 201 | | |
202 | | - | |
| 202 | + | |
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | 207 | | |
208 | 208 | | |
209 | 209 | | |
210 | | - | |
| 210 | + | |
211 | 211 | | |
212 | 212 | | |
213 | 213 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| |||
235 | 235 | | |
236 | 236 | | |
237 | 237 | | |
238 | | - | |
| 238 | + | |
239 | 239 | | |
240 | 240 | | |
241 | | - | |
| 241 | + | |
242 | 242 | | |
243 | 243 | | |
244 | 244 | | |
| |||
247 | 247 | | |
248 | 248 | | |
249 | 249 | | |
250 | | - | |
| 250 | + | |
251 | 251 | | |
252 | 252 | | |
253 | 253 | | |
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
265 | 321 | | |
266 | 322 | | |
267 | 323 | | |
| |||
523 | 579 | | |
524 | 580 | | |
525 | 581 | | |
526 | | - | |
| 582 | + | |
527 | 583 | | |
528 | 584 | | |
529 | 585 | | |
| |||
571 | 627 | | |
572 | 628 | | |
573 | 629 | | |
574 | | - | |
| 630 | + | |
575 | 631 | | |
576 | 632 | | |
577 | 633 | | |
578 | 634 | | |
579 | 635 | | |
580 | 636 | | |
581 | 637 | | |
582 | | - | |
| 638 | + | |
583 | 639 | | |
584 | 640 | | |
585 | 641 | | |
| |||
617 | 673 | | |
618 | 674 | | |
619 | 675 | | |
620 | | - | |
| 676 | + | |
621 | 677 | | |
622 | 678 | | |
623 | 679 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
| |||
Lines changed: 53 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
| 99 | + | |
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| |||
105 | 106 | | |
106 | 107 | | |
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 | + | |
108 | 134 | | |
109 | 135 | | |
110 | 136 | | |
| |||
120 | 146 | | |
121 | 147 | | |
122 | 148 | | |
| 149 | + | |
123 | 150 | | |
124 | 151 | | |
125 | 152 | | |
| |||
138 | 165 | | |
139 | 166 | | |
140 | 167 | | |
| 168 | + | |
141 | 169 | | |
142 | 170 | | |
143 | 171 | | |
| |||
155 | 183 | | |
156 | 184 | | |
157 | 185 | | |
| 186 | + | |
158 | 187 | | |
159 | 188 | | |
160 | 189 | | |
| |||
173 | 202 | | |
174 | 203 | | |
175 | 204 | | |
| 205 | + | |
176 | 206 | | |
177 | 207 | | |
178 | 208 | | |
179 | 209 | | |
180 | | - | |
| 210 | + | |
181 | 211 | | |
182 | 212 | | |
183 | 213 | | |
| |||
191 | 221 | | |
192 | 222 | | |
193 | 223 | | |
| 224 | + | |
194 | 225 | | |
195 | 226 | | |
196 | 227 | | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
197 | 247 | | |
198 | 248 | | |
199 | 249 | | |
| |||
208 | 258 | | |
209 | 259 | | |
210 | 260 | | |
211 | | - | |
| 261 | + | |
212 | 262 | | |
213 | | - | |
| 263 | + | |
214 | 264 | | |
215 | 265 | | |
216 | 266 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
34 | | - | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
40 | | - | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | | - | |
| 45 | + | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
| |||
0 commit comments