Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

### Bug Fixes

* Disable async token refresh for GCP credential providers to avoid wasted refresh attempts caused by double-caching with Google's internal `oauth2.ReuseTokenSource` ([#1549](https://github.com/databricks/databricks-sdk-go/issues/1549)).

### Documentation

### Internal Changes
Expand Down
10 changes: 9 additions & 1 deletion config/auth_gcp_google_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"

"github.com/databricks/databricks-sdk-go/config/credentials"
"github.com/databricks/databricks-sdk-go/config/experimental/auth"
"github.com/databricks/databricks-sdk-go/logger"
"golang.org/x/oauth2/google"
"google.golang.org/api/idtoken"
Expand Down Expand Up @@ -41,8 +42,15 @@ func (c GoogleCredentials) Configure(ctx context.Context, cfg *Config) (credenti
if err != nil {
return nil, fmt.Errorf("could not obtain OAuth2 token from JSON: %w", err)
}
// Disable async token refresh. Google's token sources cache tokens
// internally via oauth2.ReuseTokenSource, and there is no way to
// bypass this caching for unexported token source types. Async
// refresh would be unnecessary work since Google's cache already
// handles token renewal.
opts := append(cacheOptions(cfg), auth.WithAsyncRefresh(false))

logger.Infof(ctx, "Using Google Credentials")
visitor := serviceToServiceVisitor(inner, creds.TokenSource, "X-Databricks-GCP-SA-Access-Token", true, cacheOptions(cfg)...)
visitor := serviceToServiceVisitor(inner, creds.TokenSource, "X-Databricks-GCP-SA-Access-Token", true, opts...)
return credentials.NewOAuthCredentialsProvider(visitor, inner.Token), nil
}

Expand Down
10 changes: 9 additions & 1 deletion config/auth_gcp_google_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/databricks/databricks-sdk-go/config/credentials"
"github.com/databricks/databricks-sdk-go/config/experimental/auth"
"github.com/databricks/databricks-sdk-go/logger"
"golang.org/x/oauth2"
"google.golang.org/api/impersonate"
Expand All @@ -28,7 +29,14 @@ func (c GoogleDefaultCredentials) Configure(ctx context.Context, cfg *Config) (c
if err != nil {
return nil, err
}
opts := cacheOptions(cfg)

// Disable async token refresh. Google's token sources cache tokens
// internally via oauth2.ReuseTokenSource, and there is no way to
// bypass this caching for unexported token source types. Async
// refresh would be unnecessary work since Google's cache already
// handles token renewal.
opts := append(cacheOptions(cfg), auth.WithAsyncRefresh(false))

// Always attempt to create SA token source for the secondary header.
// If it fails, fall back to refreshableVisitor with a warning.
platform, err := impersonate.CredentialsTokenSource(ctx, impersonate.CredentialsConfig{
Expand Down
Loading