Skip to content

feat(auth): add experimental token-provider fetch timeouts - #5230

Closed
singh4jitendra wants to merge 2 commits into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/token-provider-request-bounds
Closed

singh4jitendra wants to merge 2 commits into
GoogleCloudPlatform:masterfrom
singh4jitendra:fix/token-provider-request-bounds

Conversation

@singh4jitendra

Copy link
Copy Markdown
Contributor

Description

  • Add the opt-in experimental duration gcs-auth.experimental-token-url-timeout / --experimental-token-url-timeout. Zero preserves existing unlimited-provider behavior, negative values are rejected, and positive values bound each custom token-provider fetch, including response body reading.
  • Honor the direct proxy token-source constructor's lifetime context. At the cached Google-library adapter boundary, detach transient initialization cancellation while preserving context values, so completing a FUSE lookup cannot poison later token refreshes.
  • Wire the setting consistently through legacy storage authentication, Google-library authentication, Cloud Logging, and metrics. Keep ADC/key-file behavior, token expiry/reuse, Unix sockets, and the existing response-size cap unchanged.
  • Update generated configuration/protobuf support, validation, CLI parsing, documentation, and focused regressions.

Each source owns its HTTP client and any Unix-socket transport. No shared default client or transport is mutated. This is a compatibility-conscious hardening improvement, not a confirmed security vulnerability or a mount-shutdown cancellation implementation.

Link to the issue in case of a bug fix.

Fixes #5228

Testing details

Checks ran with Go 1.27.2 in Ubuntu 24.04 under WSL.

  1. Manual -
    • make build - passed, including generation, imports/formatting, dependency hygiene, vet, golangci-lint (0 issues), and compilation.
  2. Unit tests -
    • go test -p 1 -count=1 -timeout=2m ./internal/auth ./internal/storage/storageutil ./cfg ./cmd ./internal/monitor -run "^(TestAuthSuite|Test_NewTokenSourceFromURL.*|TestProxyTokenSource.*|Test_GetClientAuthOptionsAndTokenSource.*|TestCustomTokenSourceTimeout|TestGetGcpOtelHttpClient_TokenURLTimeout|TestValidateConfig_ExperimentalTokenURLTimeout|TestToProto.*|TestSerializeConfigToProtoBase64.*|TestArgsParsing_GCSAuthFlags.*|TestValidateConfigFile_GCSAuthConfigSuccessful)$" - passed in all five packages.
    • go test -race -p 1 -count=1 -timeout=2m ./internal/auth ./internal/storage/storageutil ./cfg ./cmd ./internal/monitor -run "^(TestAuthSuite|Test_NewTokenSourceFromURL.*|TestProxyTokenSource.*|Test_GetClientAuthOptionsAndTokenSource.*|TestCustomTokenSourceTimeout|TestGetGcpOtelHttpClient_TokenURLTimeout|TestValidateConfig_ExperimentalTokenURLTimeout|TestToProto.*|TestSerializeConfigToProtoBase64.*|TestArgsParsing_GCSAuthFlags.*|TestValidateConfigFile_GCSAuthConfigSuccessful)$" - passed in all five packages, with no race reports.
    • The WSL checkout uses drvfs, so Unix-socket test temporary files were placed on private tmpfs inside an isolated user/mount namespace. Test expectations were unchanged, and the namespace, servers, and scratch directories were cleaned up.
  3. Integration tests - Not run. Validation uses local HTTP/Unix token providers, configuration/CLI tests, and authentication-adapter tests; no real cloud bucket or FUSE mount was used.

Any backward incompatible change? If so, please explain.

The new experimental timeout defaults to zero, preserving existing provider latency behavior unless explicitly enabled. Direct constructor callers must use a context with token-source lifetime; cached production adapters deliberately do not capture short-lived lookup cancellation. No ADC/key-file or dependency changes are introduced.

Add a disabled-by-default experimental per-fetch timeout for custom HTTP and Unix token providers. Honor explicit source lifetime cancellation while detaching transient initialization contexts at cached adapters. Wire configuration, protobuf, validation, CLI, legacy authentication and telemetry consistently, with regression coverage and documentation.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces an experimental configuration parameter, experimental-token-url-timeout, which allows users to specify a timeout duration for custom token-URL requests. The changes span configuration structures, CLI flags, validation logic, protobuf definitions, and the underlying authentication client setup where the timeout is applied to the HTTP client fetching the tokens. Comprehensive unit tests have been added to verify the validation, CLI parsing, and timeout behaviors under various scenarios. No review comments were provided, so there is no additional feedback to address.

@singh4jitendra
singh4jitendra marked this pull request as ready for review November 6, 2026 07:37
@singh4jitendra
singh4jitendra requested a review from a team as a code owner November 6, 2026 07:37
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @kislaykishore, could you have a look when you get a chance? This adds an opt-in timeout for token-provider requests, keeping the existing behavior unchanged by default. Local validation passed, but the GitHub workflows still need approval. Thanks!

Merge current master without rewriting PR history. Preserve the PR behavior while adopting the upstream v4 module path, Go 1.27.4 and dependency security updates. Validated with relevant race tests and make build.
@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Merged the latest master in eb136e0 and resolved the generated-protobuf conflict. The timeout field is retained, and the code and new test now use the v4 module path.

Rechecked with Go 1.27.4:

  • go test -mod=readonly -p 1 -count=1 -race -timeout=3m ./internal/auth ./internal/storage/storageutil ./cfg ./cmd ./internal/monitor -run '^(TestAuthSuite|Test_NewTokenSourceFromURL.*|TestProxyTokenSource.*|Test_GetClientAuthOptionsAndTokenSource.*|TestCustomTokenSourceTimeout|TestGetGcpOtelHttpClient_TokenURLTimeout|TestValidateConfig_ExperimentalTokenURLTimeout|TestToProto.*|TestSerializeConfigToProtoBase64.*|TestArgsParsing_GCSAuthFlags.*|TestValidateConfigFile_GCSAuthConfigSuccessful)$' - passed in all five packages, including the final regenerated files.
  • make build - passed with 0 lint issues.

The PR behavior and history are preserved. Ready for the updated CI run and review.

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @kislaykishore, just following up on this one. Could you take a look when you have a moment? Happy to make any changes you suggest. Thanks!

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Hi @kislaykishore, could you finish the review when you have a moment and merge if everything looks good? Thanks!

@kislaykishore

Copy link
Copy Markdown
Collaborator

Do we have a pressing use-case for this?

@singh4jitendra

Copy link
Copy Markdown
Contributor Author

Fair question, @kislaykishore. This came from code review rather than a reported production incident. The scenario I wanted to cover is a custom token provider accepting a request but never replying, leaving GCSFuse waiting for a token during mount or refresh. The timeout is opt-in, so existing setups behave the same. I see it as defensive hardening rather than an urgent fix. Happy to defer if you'd prefer a concrete user report first.

@kislaykishore

Copy link
Copy Markdown
Collaborator

Yep, I don't see the priority here. So, let's defer this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants