Skip to content

feat(synthetics): accept OAuth2 for synthetics tests run - #653

Merged
platinummonkey merged 1 commit into
DataDog:mainfrom
jaluna0:feat/synthetics-tests-run-oauth
Jul 17, 2026
Merged

feat(synthetics): accept OAuth2 for synthetics tests run#653
platinummonkey merged 1 commit into
DataDog:mainfrom
jaluna0:feat/synthetics-tests-run-oauth

Conversation

@jaluna0

@jaluna0 jaluna0 commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Summary

synthetics tests run is the only synthetics command that rejects an OAuth2 session (pup auth login). It hard-requires DD_API_KEY + DD_APP_KEY, while every sibling command works with a bearer token. This makes it accept OAuth2 too — preferring the bearer, falling back to keys.

Why

tests_run builds its own reqwest::Client and its build_auth_headers only ever set dd-api-key/dd-application-key — it never reads cfg.access_token. Every other synthetics command routes through make_dd_client/apply_auth, which prefers the bearer.

The Datadog CI endpoints this command calls already accept OAuth2 server-side (verified in dogweb):

Endpoint Accepts OAuth Permission
GET /synthetics/ci/tunnel yes SYNTHETICS_WRITE or CREATE_EDIT_TRIGGER
POST /synthetics/tests/trigger/ci yes SYNTHETICS_WRITE or CREATE_EDIT_TRIGGER
GET /synthetics/ci/batch/{id} yes SYNTHETICS_READ

pup already requests synthetics_write/synthetics_read by default. So this was a client-side gap, not a backend limit — no backend change required, and it applies to --tunnel runs too.

Changes

  • build_auth_headers (src/commands/synthetics.rs): prefer OAuth2 bearer, fall back to API + app keys, mirroring client::apply_auth.
  • Clearer error when no auth is configured.
  • Positive/negative tests for all three auth paths (bearer, key fallback, none).

Testing

  • Added unit tests: bearer preferred, key fallback, no-auth error.

`synthetics tests run` was the only synthetics command that could not
authenticate with an OAuth2 session (`pup auth login`). Its
`build_auth_headers` hard-required DD_API_KEY + DD_APP_KEY and never read
`cfg.access_token`, unlike every sibling command which routes through
`make_dd_client`/`apply_auth` and prefers a bearer token.

The Datadog CI endpoints this command calls (`synthetics/ci/tunnel`,
`synthetics/tests/trigger/ci`, `synthetics/ci/batch/{id}`) already accept
OAuth2 bearer tokens with the `synthetics_write`/`synthetics_read` scopes,
which pup requests by default — so this was a client-side gap, not a
backend limitation.

- Prefer OAuth2 bearer, fall back to API + app keys, mirroring
  `client::apply_auth`.
- Clearer error when no auth is configured.
- Add positive/negative tests for the three auth paths.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@jaluna0
jaluna0 marked this pull request as ready for review July 17, 2026 19:53
@jaluna0
jaluna0 requested a review from a team as a code owner July 17, 2026 19:53
@platinummonkey
platinummonkey merged commit 3040061 into DataDog:main Jul 17, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants