Skip to content

feat(http): support OAuth2 token request timeouts - #388

Closed
brandondomingue-cb wants to merge 1 commit into
buildbarn:mainfrom
brandondomingue-cb:review/oauth-client-credentials-timeout
Closed

brandondomingue-cb wants to merge 1 commit into
buildbarn:mainfrom
brandondomingue-cb:review/oauth-client-credentials-timeout

Conversation

@brandondomingue-cb

Copy link
Copy Markdown

Summary

Add an optional token_request_timeout duration to OAuth2ClientCredentials (tokenRequestTimeout in JSON). Apply it to the HTTP client used by the OAuth2 client-credentials token source.

A stalled token endpoint currently can block token acquisition indefinitely. This allows deployments to bound that HTTP request without changing the behavior of existing configurations.

Behavior and compatibility

  • When configured, the duration must be valid and strictly positive; invalid values fail configuration with InvalidArgument.
  • The timeout uses http.Client.Timeout, covering connection establishment, redirects, response headers, and reading the response body, including a body that keeps trickling data.
  • When omitted, the HTTP timeout remains zero (unbounded), matching the existing behavior. No default timeout is introduced.
  • OAuth2 may probe two authentication styles during initial acquisition. Each HTTP request has its own timeout budget. This is not a deadline for the entire acquisition, waiting on another acquisition, or an enclosing RPC/job.
  • Failed acquisition returns an error and no token. A later successful acquisition can recover, and a valid recovered token remains reusable.

The change is limited to the HTTP client implementation, the protobuf schema and its generated Go binding, Bazel dependencies, and regression tests. No deployment configuration or credentials are included.

Validation

  • bazel test --nocache_test_results --test_output=all --test_arg=-test.v //pkg/http/client:client_test: 11 leaf cases covering validation, JSON configuration, omitted-timeout compatibility, and three endpoint stalls (no headers, partial body, and trickling body), followed by recovery and token reuse.
  • bazel test --nocache_test_results --test_output=errors //pkg/http/...: both HTTP client and HTTP server test targets executed and passed.
  • Scoped Gazelle and gofumpt formatting checks and git diff --check passed.
  • Generated the Go protobuf binding through //pkg/proto/configuration/http/client:client_go_proto with --output_groups=go_generated_srcs and verified it against the checked-in binding.
  • Previously checked the regression cases against the original implementation: invalid-duration and stalled-endpoint cases fail without this change.

Native race validation was blocked before test execution by a local macOS SDK/linker mismatch; no race-test pass or full-repository test pass is claimed.

Generated with Toshi

@brandondomingue-cb
brandondomingue-cb deleted the review/oauth-client-credentials-timeout branch October 12, 2026 21:40
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.

1 participant