Commit db4aa0f
authored
[delegatedauth] Support all AWS credential sources in every Agent flavor | WIF-75 (#54318)
### What does this PR do?
Removes the `ec2` build tag from Agent Cloud Auth's AWS credential resolution, so every Agent flavor can use EKS IRSA, ECS task roles, EKS Pod Identity and EC2 IMDS. Newly covered: trace-agent, standalone Dogstatsd, private action runner, IoT, Heroku. `ec2` still gates DBM and EC2 host tagging, untouched.
### Why
`ec2` also gates DBM and EC2 host tagging, so flavors that opted out of those silently lost Cloud Auth with them. Most importantly APM has never supported it, and `comp/trace/config/fx` sets `FailIfAPIKeyMissing: true`, so a customer using Cloud Auth for APM can't drop the static `api_key`.
### What changed
**Build-tag removal.** The three `!ec2` stubs are deleted and the tag dropped from credential resolution and detection. `pkg/util/aws/creds` had no other consumer. No replacement tag: gating cost +56 KiB per excluded flavor, and gating is what created the silent gap to begin with.
**Two SDK providers replaced.** IRSA and IMDS were already resolved by our own code. The remaining two SDK dependencies are gone: `credentials/endpointcreds` for the ECS/EKS container leg (replaced by a GET + JSON decode) and `credentials.NewStaticCredentialsProvider` (a 2-line struct). `aws-sdk-go-v2/aws` and `signer/v4` stay, both already linked for the SigV4 proof. No change to the STS or SigV4 paths.
The container replacement keeps the retry behavior `endpointcreds` provided: connection errors, truncated bodies, 5xx and 429 are retried, bounded by an attempt cap and an elapsed budget, while a 403 or a malformed document is not. IRSA and IMDS have no inner retries, unchanged, so the three legs are intentionally not uniform.
**Diagnosability.** Detection returns why it failed rather than a bool, failures name the one mechanism that was tried and what to check for it, and blank-but-error-free credentials are now a failure rather than a false "resolved". A half-configured credential pair (ex: `AWS_ACCESS_KEY_ID` without `AWS_SECRET_ACCESS_KEY`) logs a warning naming it, and is still skipped rather than erroring, matching the AWS SDK. `agent status` reports disable reason, per-key credential source, last and next refresh, and last error.
**Config precedence fix.** Setting only `delegated_auth.aws.region` built a non-nil `ProviderConfig`, which downstream reads as "explicitly configured" and skipped provider detection entirely. The region is now applied to the auto-detected provider.
**`cloud_provider_metadata` opt-out.** Three IMDS entry points reached `DoHTTPRequest` directly rather than through `GetMetadataItem`, so an operator who excluded `aws` was probed anyway. All three now check first. This predates the PR, but removing the build tag is what exposes it to flavors that otherwise never touch IMDS.
### Size
| Build | vs `main` |
|---|---|
| trace-agent binary | +73.2 KiB |
| `iot_agent_deb_amd64` package | +4.03 KiB |
| `agent_rpm_arm64` package | +55.97 KiB |
Static quality gates moved +0.06 MiB on `agent_rpm_arm64` and `agent_suse_arm64`, and nowhere else.
Keeping `endpointcreds` would have cost +404.8 KiB instead of +73.2 KiB on the trace-agent, almost all of it smithy-go middleware and its reflection metadata, and would have put IoT over its hard limit.
The main Agent package grows even though its binary already had this code: `omnibus/config/software/datadog-agent.rb` ships `trace-agent` and `privateactionrunner` inside it, and those two are what newly compile the credential code.
### Deliberately not in this PR
- `otel-agent` (DDOT) still uses the noop delegated-auth module.
- Adding inner retries to the IRSA and IMDS legs.
### Describe how you validated your changes
**Staging end to end** on `charcadet.us1.staging.dog`, two deploys differing only in the agent image. All four flavors on the cluster (`agent`, `trace-agent`, `process-agent`, `private-action-runner`) go from `missing AWS credentials` to a delegated key, verified across 16 pods and 48 containers. Per-phase log links and reasoning in [this comment](#54318 (comment)). IRSA and static-env credentials on real AWS are not covered end to end and remain for `qa/rc-required`.
**Local** (`trace-agent`, default flavor tags, no `ec2`): container-credentials path reached end to end against a stub endpoint. A pre-PR non-`ec2` build stops in the `_noec2` stub and cannot get this far.
**Tests.** `bzl test //comp/core/delegatedauth/...:all //pkg/util/aws/creds:all` passes, including flavor targets that never compiled this code before. New coverage for the container provider (each retry class asserts exact request counts, so the non-retry cases cannot silently start retrying), region precedence, detection-failure recording, status fields, and the metadata opt-out.
Co-authored-by: stephen.rosenthal <stephen.rosenthal@datadoghq.com>1 parent dbd7f40 commit db4aa0f
33 files changed
Lines changed: 1662 additions & 595 deletions
File tree
- comp/core/delegatedauth
- api/cloudauth/aws
- common
- impl
- status_templates
- internal/qbranch/anomalydetection-testbench
- pkg
- config/setup
- util/aws/creds
- internal
- releasenotes/notes
- test/static
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
| 8 | + | |
10 | 9 | | |
11 | 10 | | |
12 | 11 | | |
| |||
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | | - | |
24 | | - | |
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | 28 | | |
32 | | - | |
33 | | - | |
| 29 | + | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
37 | | - | |
38 | 33 | | |
39 | 34 | | |
40 | 35 | | |
41 | | - | |
42 | | - | |
43 | 36 | | |
44 | 37 | | |
45 | 38 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
56 | 63 | | |
57 | 64 | | |
58 | 65 | | |
| |||
66 | 73 | | |
67 | 74 | | |
68 | 75 | | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
69 | 90 | | |
70 | 91 | | |
71 | 92 | | |
| |||
75 | 96 | | |
76 | 97 | | |
77 | 98 | | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | 99 | | |
83 | 100 | | |
84 | 101 | | |
85 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
86 | 113 | | |
87 | 114 | | |
88 | 115 | | |
| |||
99 | 126 | | |
100 | 127 | | |
101 | 128 | | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
109 | 147 | | |
110 | | - | |
111 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
112 | 178 | | |
113 | | - | |
114 | 179 | | |
115 | 180 | | |
116 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments