← Back to Pull requests

[auth] Support Bearer access tokens and WIF #2639

Merged
Drarig29 merged 8 files (650 lines) on Nov 24, 2026 19:09 UTC
View on GitHub
Drarig29 Drarig29 commented on Nov 20, 2026 10:58 UTC
Author

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 upload exited with "APP key not defined".

These commands now accept DD_ACCESS_TOKEN (or DATADOG_ACCESS_TOKEN, read first): synthetics run-tests / deploy-tests / import-tests / upload-application, sbom upload, deployment gate, deployment correlate-image and gate evaluate.

  • A token takes precedence over an application key, which is then not sent. The API key becomes optional.

  • Synthetics also accepts --accessToken and the accessToken config key, resolved like appKey (config file < env < CLI).

  • API key + application key setups send the same headers as before.
  • This PR also makes it clear which credentials each command needs:

  • Every command's --help has 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. Serverless instrument commands warn that a short-lived intake key would expire once stored in the service.

  • The README has a new Authentication section that explains authentication once and points to datadog-ci <command> --help for each command's credentials, with a GitHub Actions example using the intake and identity actions. The synthetics, sbom, deployment and gate READMEs document DD_ACCESS_TOKEN.

  • Missing-credential errors say what is needed. For example: "sbom upload needs 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?

  • getRequestBuilder takes an accessToken. When one is set, it sends Authorization: Bearer and never DD-APPLICATION-KEY, so no caller can send both. It only sends DD-API-KEY when an API key is set.

  • Presigned mobile application upload parts use a separate request builder with the same proxy settings but no Datadog credentials, so API keys, application keys, and Bearer tokens are not sent to S3/Azure storage URLs.

  • A new packages/base/src/helpers/auth.ts resolves 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.

  • Each base command class in packages/base/src/commands/ declares public static authRequirement, and its plugin command inherits it. CliWithAuthHelp overrides Cli.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 from packages/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, trace and span.
    - noAuth ({kind: 'none'}): the command needs no Datadog credentials, for example plugin, version, ci-env read, sourcemaps find / inject and react-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 with getServerlessInstrumentAuthHelp (instrument: cloud credentials plus a long-lived API key), getCloudCredentialsOnlyAuthHelp (uninstrument, stepfunctions, lambda cloudwatch: cloud credentials only) and getFlareAuthHelp (flares: cloud credentials plus an API key).
  • New CI job, e2e-test-federation*, taken over from the closed #2637.

  • - It sets only DD_API_KEY and DD_ACCESS_TOKEN from 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 because e2e-test covers 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 read DATADOG_
    credentials fall back to the corresponding DD_* 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-test and e2e-test-windows never set a token, so they behave as before.

    Testing

  • Unit tests cover the Bearer and API key headers in getRequestBuilder, every precedence and message branch in auth.ts, token-only success, and missing-credential errors for each org-action command. They also cover accessToken precedence in the four Synthetics commands. A help test renders every registered command and fails if one lacks the Authentication section or does not declare an authRequirement.

  • Headers, checked locally from the worktree: DD_API_HOST_OVERRIDE=http://127.0.0.1:48731 yarn launch synthetics run-tests --public-id abc-def-ghi against a local capture server.

  • - With only DD_ACCESS_TOKEN, the settings, test and suite requests carried only Authorization: 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.
  • Presigned mobile upload regression tests verify that PUTs carry no Authorization, DD-API-KEY, or DD-APPLICATION-KEY header with either token-only or API key + application key credentials, while retaining Content-MD5 and the configured proxy dispatcher. A real upload against S3/Azure was not verified.

  • Errors, checked locally: DD_API_KEY=… yarn launch sbom upload e2e/fixtures/sbom-reports/sbom.json exits 1 with the message above.

  • e2e-test-federation passed on head dd1950513 (run), verifying the following with WIF credentials only:

  • - synthetics run-tests (trigger through intake.synthetics.<site>, poll results, test fetch) and sbom upload, both with the token alone;
    - junit and sourcemaps uploads and their token read-backs;
    - git-metadata and sarif uploads.
  • Not verified with a real token:

  • - deployment gate, deployment correlate-image and gate evaluate;
    - synthetics deploy-tests, import-tests, upload-application and 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

  • Feature or bugfix MUST have appropriate tests (unit, integration)
  • [SYNTH-31082]: https://datadoghq.atlassian.net/browse/SYNTH-31082?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: juliomalegria-dd Review duration: 6250m
    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
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Assignees
    Drarig29 Drarig29
    Labels
    risk: medium confidence: 46.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 40.1% · Moderate risk
    40.1%