Repository navigation
fix(auth): thread connector transport and User-Agent into OAuth M2M token requests - #498
Open
sevbanbayrak wants to merge 1 commit into
Open
sevbanbayrak wants to merge 1 commit into
sevbanbayrak wants to merge 1 commit into
Conversation
…oken requests With WithClientCredentials the token exchange (and the OIDC discovery before it) was issued through http.DefaultClient, so system.access.audit recorded mintOAuthToken and workspaceInHouseOAuthClientAuthentication as "Go-http-client/2.0" instead of the driver User-Agent and WithUserAgentEntry. The M2M authenticator is built when its option is applied, before the User-Agent entry or transport may be set, so the driver now injects an *http.Client once the config is final: PooledClient passes a client on the same base transport, with BuildUserAgent, to any authenticator exposing SetHTTPClient. The M2M authenticator stores it on the oauth2 context used for GetConfig and TokenSource, and GetEndpoint reuses that client's transport for discovery. Authenticators without SetHTTPClient are unaffected. Fixes databricks#413 Signed-off-by: Sevban Bayrak <svbnbyrk@gmail.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #413
Problem
With
WithClientCredentialsthe OAuth M2M token exchange (and the OIDC discovery before it) is issued throughhttp.DefaultClient, sosystem.access.auditrecordsmintOAuthTokenandworkspaceInHouseOAuthClientAuthenticationasGo-http-client/2.0instead of the driver User-Agent and theWithUserAgentEntryvalue. Query traffic is attributed correctly; only the token path is anonymous, which matters for ISV partner attribution.Root cause
The M2M authenticator is constructed when its option is applied (
WithClientCredentials, or the DSN path), beforeWithUserAgentEntry/WithTransportmay have been applied, and it created its token source on a barecontext.Background(), so no HTTP client could reachoauth2.Fix
internal/client.PooledClientruns once the config is final. It now hands any authenticator that exposesSetHTTPClient(*http.Client)a client on the same base transport (WithTransportor the pooled one) wrapped withBuildUserAgent(cfg). It deliberately wraps the base transport, not the authTransport, so a token fetch cannot recurse intoAuthenticate.m2m.authClientimplementsSetHTTPClient(structural, same pattern asM2MCredentialsfor the kernel backend) and puts that client on theoauth2.HTTPClientcontext used forGetConfigandTokenSource.oauth.GetEndpointreuses the transport of anoauth2.HTTPClientfound onctxfor the/.well-known/databricks-configlookup and OIDC discovery, closing the in-tree NOTE aboutWithTransportnot being threaded into endpoint resolution.Authenticators without
SetHTTPClient(PAT, U2M, token providers) are unchanged. No public API change; option order does not matter.Tests
m2m:Authenticateon an Azure host (offline endpoint) sends the token request through the injected client and reuses the cached token source.oauth:GetEndpointperforms discovery through the ctx client's transport and resolves the servedtoken_endpoint.client:PooledClientinjects a client whose transport carriesBuildUserAgent(cfg)overcfg.Transport, without mutating the caller's request; authenticators without the hook are untouched.go test ./...andgolangci-lint runare clean locally.Verification against a workspace
Ran
SELECT 1through a connector configured withWithClientCredentials+WithUserAgentEntry("Insider_UATest413/…")against an AWS workspace, then queriedsystem.access.audit:workspaceInHouseOAuthClientAuthenticationGo-http-client/2.0godatabrickssqlconnector/1.16.0 (Insider_UATest413/…)mintOAuthTokenGo-http-client/2.0godatabrickssqlconnector/1.16.0 (Insider_UATest413/…)oidcTokenAuthorization