Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

credentials: remove the context timeout to fix token request failure with non-GCE ADC #7845

Merged
merged 3 commits into from
Nov 19, 2024

Conversation

rockspore
Copy link
Contributor

@rockspore rockspore commented Nov 15, 2024

The defer cancel() is called when NewDefaultCredentialsWithOptions returns and this is definitely a problem. It means the context is done, but all non-GCE token sources will rely on it to make HTTP requests to the token endpoint.

Alternatively (or maybe preferably), NewDefaultCredentialsWithOptions should take a top-level context. Despite this being an experimental API, I don't think such a breaking change is easy.

RELEASE NOTES: NONE

Copy link

codecov bot commented Nov 15, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.74%. Comparing base (66385b2) to head (0381aae).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7845      +/-   ##
==========================================
- Coverage   81.84%   81.74%   -0.11%     
==========================================
  Files         374      374              
  Lines       37993    37994       +1     
==========================================
- Hits        31096    31057      -39     
- Misses       5598     5622      +24     
- Partials     1299     1315      +16     
Files with missing lines Coverage Δ
credentials/google/google.go 77.33% <100.00%> (+0.30%) ⬆️

... and 25 files with indirect coverage changes

---- 🚨 Try these New Features:

@rockspore rockspore marked this pull request as ready for review November 15, 2024 01:33
@rockspore rockspore changed the title Remove the context timeout to fix token request failure with non-GCE ADC credentials: remove the context timeout to fix token request failure with non-GCE ADC Nov 15, 2024
@rockspore rockspore requested a review from dfawley November 15, 2024 01:34
@arjan-bal arjan-bal added the Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. label Nov 15, 2024
@arjan-bal arjan-bal added this to the 1.69 Release milestone Nov 15, 2024
@@ -121,8 +116,11 @@ var (
newALTS = func() credentials.TransportCredentials {
return alts.NewClientCreds(alts.DefaultClientOptions())
}
newADC = func(ctx context.Context) (credentials.PerRPCCredentials, error) {
Copy link
Member

Choose a reason for hiding this comment

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

Why change this part? Maybe we should leave this alone and use context.TODO() at the call site instead of something that adds a deadline to a context.Background.

This seems like an incorrect use of contexts to me, though, by the oauth package.

Copy link
Contributor Author

@rockspore rockspore Nov 15, 2024

Choose a reason for hiding this comment

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

Why change this part? Maybe we should leave this alone and use context.TODO() at the call site instead of something that adds a deadline to a context.Background.

It's internal method so I didn't think too much. But it's perfectly fine to leave it unchanged.

This seems like an incorrect use of contexts to me, though, by the oauth package.

I fully agree. As I pointed out in internal ticket, there is definitely some code smell since it keeps this given context in a struct. So basically, it can only take a top-level context from a main func and doesn't allow any deadline or timeout to be set.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OAuth library team also maintains the DetectDefault API that's meant to support both gRPC and HTTP for client SDK. That API doesn't need a context. Some adapter is needed to create the gRPC's RPCCreds from it so I am not sure whether it's worth moving to that API.

I went for this simplistic fix as I just wanted to unblock Cloud Spanner's issue with Direct Path. But still wanted to just mention the above option.

Copy link
Member

Choose a reason for hiding this comment

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

I'm fine with this as a workaround, and if there is some better way to be using oauth, then I'm happy to review changes that move us to that as well. It doesn't seem like using this API is a problem, so I think we can treat anything like that as a cleanup.

@rockspore rockspore requested a review from dfawley November 15, 2024 19:30
@rockspore rockspore merged commit db700b7 into grpc:master Nov 19, 2024
15 checks passed
@rockspore rockspore deleted the adc branch November 19, 2024 22:08
@dfawley
Copy link
Member

dfawley commented Nov 19, 2024

Thank you for the fix! I searched and found that this should fix an old issue that was closed without a fix (#6285).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Auth Includes regular credentials API and implementation. Also includes advancedtls, authz, rbac etc. Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants