[auth] Support Bearer access tokens and WIF #2639
All Vouch review confidence checks passed
Residual risk 0.40 = Change Risk (0.75) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 650 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.388
Shallow Review Depth
shallow_review_depth
0.344
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #2639"
general
weight: 0.35
juliomalegria-dd
Drarig29
What and why?
SYNTH-31082
This PR lets datadog-ci authenticate with a Datadog access token sent as
Authorization: Bearer <token>, for example the short-lived token that a Workload Identity Federation (WIF) identity mapping returns in GitHub Actions. It addresses #2634.We already support WIF intake mappings through the API key, but an intake mapping only provides an API key. Commands that act on behalf of a user or service account still required a long-lived application key, so they could not run on WIF credentials. For example,
sbom uploadexited with "APP key not defined".These commands now accept
DD_ACCESS_TOKEN(orDATADOG_ACCESS_TOKEN, read first):synthetics run-tests/deploy-tests/import-tests/upload-application,sbom upload,deployment gate,deployment correlate-imageandgate evaluate.--accessTokenand theaccessTokenconfig key, resolved likeappKey(config file < env < CLI).This PR also makes it clear which credentials each command needs:
--helphas an "Authentication" section, between Details and Examples, that names the credentials and the Workload Identity Federation mapping that provides them, with a terminal link to the WIF docs. Serverlessinstrumentcommands warn that a short-lived intake key would expire once stored in the service.datadog-ci <command> --helpfor each command's credentials, with a GitHub Actions example using theintakeandidentityactions. The synthetics, sbom, deployment and gate READMEs documentDD_ACCESS_TOKEN.sbom uploadneeds an application key (DD_APP_KEY) or an access token (DD_ACCESS_TOKEN). An intake mapping only provides an API key: use a Workload Identity Federation identity mapping to get an access token."yarn launch sourcemaps upload --help:<img width="1510" height="468" alt="image" src="https://github.com/user-attachments/assets/7a3beafd-c326-44b3-a9f5-2d02c7ecd961" />
yarn launch synthetics run-tests --help:<img width="645" height="376" alt="image" src="https://github.com/user-attachments/assets/e6b5f8f7-9332-4eaa-8ede-c8e1c371c94c" />
How?
getRequestBuildertakes anaccessToken. When one is set, it sendsAuthorization: Bearerand neverDD-APPLICATION-KEY, so no caller can send both. It only sendsDD-API-KEYwhen an API key is set.packages/base/src/helpers/auth.tsresolves the token from the environment, applies the precedence and builds the error messages and the shared help texts. The org-action commands use it instead of their own key checks.packages/base/src/commands/declarespublic static authRequirement, and its plugin command inherits it.CliWithAuthHelpoverridesCli.usage()to render the Authentication section from it with Clipanion's own header formatting; a test fails when a registered command does not declare one. Keeping the declaration next to each command means CODEOWNERS requests the command's owners when its credential text changes. The possible values, exported frompackages/base/src/helpers/auth.ts:-
orgActionAuth({kind: 'orgAction'}): the command calls Datadog API endpoints, so it needs an API key and an application key, or an access token from a WIF identity mapping. Used by the 8 commands above.-
apiKeyAuth({kind: 'apiKey'}): the command only sends telemetry, so it needs an API key, which a WIF intake mapping can provide. Used by the uploads (junit, sarif, sourcemaps, git-metadata, coverage, dora, symbols, …),tag,measure,traceandspan.-
noAuth({kind: 'none'}): the command needs no Datadog credentials, for exampleplugin,version,ci-env read,sourcemaps find/injectandreact-native inject-debug-id.-
customAuth(help)({kind: 'custom', help}): a command-specific text written in the command's own file. The Serverless commands use it, built withgetServerlessInstrumentAuthHelp(instrument: cloud credentials plus a long-lived API key),getCloudCredentialsOnlyAuthHelp(uninstrument,stepfunctions,lambda cloudwatch: cloud credentials only) andgetFlareAuthHelp(flares: cloud credentials plus an API key).e2e-test-federation*, taken over from the closed #2637.- It sets only
DD_API_KEYandDD_ACCESS_TOKENfrom the WIF intake and identity mappings for the Synthetics E2E Testing Org and runs the whole e2e suite without any stored Datadog secret or application key. The serverless suites are skipped becausee2e-testcovers them.- When a token is set, the synthetics and sbom e2e tests remove the API key and application keys from the CLI's env, so the token-only setup the README describes is what gets tested.
- The junit and sourcemaps read-back checks authenticate with the token through the new
getE2EAuthMethods. The e2e tests that readDATADOG_credentials fall back to the correspondingDD_*variables.- The job is blocking. It only runs in DataDog/datadog-ci and is skipped at job level for Dependabot, the cases where GitHub issues no trusted OIDC token.
-
e2e-testande2e-test-windowsnever set a token, so they behave as before.Testing
getRequestBuilder, every precedence and message branch inauth.ts, token-only success, and missing-credential errors for each org-action command. They also coveraccessTokenprecedence in the four Synthetics commands. A help test renders every registered command and fails if one lacks the Authentication section or does not declare anauthRequirement.DD_API_HOST_OVERRIDE=http://127.0.0.1:48731 yarn launch synthetics run-tests --public-id abc-def-ghiagainst a local capture server.- With only
DD_ACCESS_TOKEN, the settings, test and suite requests carried onlyAuthorization: Bearer ….- With the token plus both keys, they carried Bearer +
DD-API-KEY, with no application key.- With keys only, they carried
DD-API-KEY+DD-APPLICATION-KEY, as before.Authorization,DD-API-KEY, orDD-APPLICATION-KEYheader with either token-only or API key + application key credentials, while retainingContent-MD5and the configured proxy dispatcher. A real upload against S3/Azure was not verified.DD_API_KEY=… yarn launch sbom upload e2e/fixtures/sbom-reports/sbom.jsonexits 1 with the message above.e2e-test-federationpassed on headdd1950513(run), verifying the following with WIF credentials only:-
synthetics run-tests(trigger throughintake.synthetics.<site>, poll results, test fetch) andsbom upload, both with the token alone;- junit and sourcemaps uploads and their token read-backs;
- git-metadata and sarif uploads.
-
deployment gate,deployment correlate-imageandgate evaluate;- synthetics
deploy-tests,import-tests,upload-applicationand the tunnel;-
GET /api/v1/synthetics/tests/search, since the fixtures use public IDs.Our route audit shows these accept OAuth tokens, but whether a WIF identity token counts as one on them is an assumption.
Review checklist
[SYNTH-31082]: https://datadoghq.atlassian.net/browse/SYNTH-31082?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ