Repository navigation
[Go] Add external-IdP token federation - #1106
Open
anilmenon14 wants to merge 1 commit into
Open
anilmenon14 wants to merge 1 commit into
anilmenon14 wants to merge 1 commit into
Conversation
anilmenon14
force-pushed
the
feature/go-federated-token-auth
branch
from
November 13, 2026 11:29
f105644 to
049a994
Compare
This was referenced Nov 13, 2026
anilmenon14
requested review from
elenagaljak-db and
teodordelibasic-db
and removed request for
teodordelibasic-db
November 13, 2026 13:54
This was referenced Nov 19, 2026
Open
anilmenon14
force-pushed
the
feature/go-federated-token-auth
branch
from
November 21, 2026 16:08
049a994 to
517bee7
Compare
Add external-IdP (for example Microsoft Entra ID) token federation to the Go SDK through two new, additive C FFI entry points. Go: IdpTokenSupplier, NewFederatedToken (WithClientID selects workload identity federation), CreateStreamWithFederatedToken and CreateArrowStreamWithFederatedToken. Each FederatedToken has a random cache identity, so streams on one token share its exchanged token and two tokens never share one. A non-retryable *ZerobusError from the supplier is permanent; other errors are retried; a panic is recovered and reported as permanent. FFI: zerobus_sdk_create_stream_with_federated_token and zerobus_sdk_create_arrow_stream_with_federated_token take an IdpTokenSupplierCallback returning a CIdpToken. user_data ownership follows the headers-provider entry points. The callback runs on a blocking thread. zerobus.h changes are additive. Tests run real streams against the mock gRPC server and a new mock token endpoint that records every exchange request. go/lib archives are left for the release branch. Refs #1069 Co-authored-by: Isaac <no-reply@databricks.com> Signed-off-by: Anil Menon <anil.menon@databricks.com>
anilmenon14
force-pushed
the
feature/go-federated-token-auth
branch
from
November 21, 2026 16:31
517bee7 to
78985e0
Compare
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.
Adds first-class external-IdP token federation (for example Microsoft Entra ID) to the Go (cgo) SDK, through two new C FFI entry points. This is the Go half of #1069. The Java half is #1105. The two PRs touch disjoint files: this one changes
rust/ffi/andgo/, #1105 changesrust/jni/andjava/.WHY: Customers whose workloads already carry an IdP identity (Entra ID managed identity, workload identity, and so on) should not have to provision and rotate a Databricks OAuth client secret just to use Zerobus. The Rust core already performs the RFC 8693 token exchange, caching and proactive refresh (#740 / #760). The Go SDK only needs a way to hand it an IdP token.
WHAT:
github.com/databricks/zerobus-sdk/go):IdpTokenSupplier:func() (string, error). There is nocontext.Contextparameter, because the SDK calls the supplier during background refresh, when no caller context exists.NewFederatedToken(supplier, opts ...FederatedTokenOption): account-level federation by default.WithClientID(spClientID)selects workload identity federation.ZerobusSdk.CreateStreamWithFederatedTokenandZerobusSdk.CreateArrowStreamWithFederatedToken, alongside the existing...WithHeadersProvidermethods.FederatedTokengets a random 128-bit cache identity (go:<hex>) when it is built. It is passed to the core'sIdpTokenSupplier::with_identity. Exchanged tokens are cached per table. For account-level federation the cache is per instance: streams created from the same instance share one exchanged token, and different instances never share one. For workload identity federation the core keys the cache by the service principal's client ID, so instances with the same client ID share a token. The identity is never derived from an address.*ZerobusErrorwithIsRetryable: false(found witherrors.As, so it may be wrapped) is permanent and stops recovery. A panicking supplier is recovered in Go and reported as a permanent failure, so it never unwinds into Rust or crashes the process.zerobus.hgains 96 lines and loses none, so C++ and .NET are unaffected):zerobus_sdk_create_stream_with_federated_tokenandzerobus_sdk_create_arrow_stream_with_federated_token.IdpTokenSupplierCallbackthat returns aCIdpToken(token, orerror_messageplusis_retryable),user_dataandfree_user_data, a nullableclient_id(null means account-level), and acache_identity.user_datafollows the headers-provider entry points: the FFI owns it once the call is made, and frees it exactly once on every path, after any in-flight callback has returned.rust/ffi/src/federated.rsadapts the callback into the core'sIdpTokenSupplier. It runs the callback onspawn_blocking, so a slow IdP round-trip never stalls a Tokio worker. A blocking call can't be cancelled, so it holds a lock for the whole call: a hung callback holds one thread per stream, and retries or refreshes wait for it instead of starting new calls.ZerobusError, so a transient IdP failure stays retryable inCResult.is_retryable, including on the Arrow path.HeadersProviderpattern. Each create hands a newcgo.Handleto the FFI, which releases it throughgoFreeIdpTokenSupplier. Go never deletes it itself.examples/json/federated(Entra ID client-credentials grant, both modes, wired intomake examples/lint/fmt),go/NEXT_CHANGELOG.md,rust/ffi/NEXT_CHANGELOG.mdandgo/CLAUDE.md.Release note for maintainers: as agreed, this PR does not commit rebuilt
go/lib/*.aarchives. CI builds the FFI from source (make build-rust). The archives get committed on the release version-bump branch throughrelease-go.yml.How is this tested?
rust/ffi/src/federated.rstests):cache_identity, blankclient_id), withuser_datafreed exactly once in every case.user_dataexactly once on failure.FederatedTokenProviderandspawn_blocking, and surfaces its error as non-retryable, in both modes.cargo clippy --all-targets -D warningsandcargo fmt --checkare clean.go/federated_test.go): both modes andString(), option validation, unique cache identities, retryability classification (including a wrapped*ZerobusError), panic recovery, handle release, and nil-token rejection.go/tests/federated_test.go): real JSON and Arrow streams run against the existing mock gRPC server. The SDK's Unity Catalog URL points at a new loopback mock token endpoint (go/tests/mock_token_server.go), which records every exchange request and replies from a script. The tests check:POST /oidc/v1/token, form-encoded, with noAuthorizationheader.subject_tokenis byte-identical to the supplier's token (a realistic ~1.5 KB JWT).grant_typeandsubject_token_typeare the token-exchange values.client_idis sent only for workload identity federation.Bearertoken, with the table-name header.FederatedTokenshare one exchanged token: the supplier is called once and the token endpoint hit once.client_idshare one, and differentclient_ids don't.*ZerobusError, even wrapped, stays permanent.subject_tokenand correctclient_idin both modes, and shares the token across streams.cgo.Handleis released, so theFederatedTokenis garbage-collected.go test -racewith no data races.authorizationand table-name headers.client_iddropped for workload identity, or always omitted on the Arrow path.recover()removed. This crashes the test process, which shows the recovery is load-bearing.make testpasses (95 Rust FFI tests, 82 Go tests), andmake lintpasses, including all examples.ZerobusSdkand oneFederatedTokenper mode: