Skip to content

feat(auth/gcp): add GCP credential provider#1173

Open
wolo-lab wants to merge 2 commits into
wolo/auth-gcp-clientfrom
wolo/auth-gcp-provider
Open

feat(auth/gcp): add GCP credential provider#1173
wolo-lab wants to merge 2 commits into
wolo/auth-gcp-clientfrom
wolo/auth-gcp-provider

Conversation

@wolo-lab

@wolo-lab wolo-lab commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Problem

auth/gcp has the credentials-service REST client (#1149) but no
auth.CredentialProvider that resolves the acting user's credential from the
invocation context. Without it there is no way to wire per-user GCP credentials
(Agent Identity / IAM Connector) into a tool call — adk-python has this via its
GCP auth provider.

Summary

  • Add gcp.NewProvider(scheme, *gcp.ProviderConfig) returning an
    auth.CredentialProvider that resolves a per-user credential via the REST
    client and maps it to an auth.Credential. The acting user is taken from the
    ADK context at resolve time, so it runs inside an agent invocation.
  • Add agent.Identity and agent.IdentityFromContext(ctx) (Identity, bool) so
    code holding only a context.Context (e.g. an http.RoundTripper deep beneath
    a tool call, past jsonrpc2/net/http wrapping) can recover the invocation
    identity. Identity is synthesized on demand from Session() on the typed
    context and registered under a private key in internal/adkcontext — a
    module-internal leaf package (shared by agent and internal/context to avoid
    an import cycle), so code outside the module can neither name nor forge it.
  • Value on both context types delegates every non-identity key, and any context
    without a session, to the embedded context — so it never panics and a wrapped
    ADK context can still supply the identity.
  • Config-struct API (ProviderConfig, nil = defaults), consistent with
    gcp.NewClient.

@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch 4 times, most recently from 5a28496 to 234d752 Compare July 20, 2026 11:29
@wolo-lab
wolo-lab marked this pull request as ready for review July 20, 2026 11:32
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from 234d752 to c65d414 Compare July 20, 2026 11:40
@wolo-lab
wolo-lab requested a review from baptmont July 20, 2026 11:49
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from c65d414 to 9186dc4 Compare July 20, 2026 11:49
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-client branch 2 times, most recently from 642c715 to 73b5382 Compare July 22, 2026 20:25
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from 9186dc4 to edeb3da Compare July 22, 2026 21:21
wolo-lab added 2 commits July 22, 2026 22:23
Add gcp.NewProvider, an auth.CredentialProvider that resolves per-user
credentials from the Agent Identity / IAM Connector services (via the REST
client) and maps them to an auth.Credential. It takes the acting user from the
ADK context at resolve time, so it runs inside an agent invocation and needs no
per-user configuration.

To recover the user from an http.RoundTripper that only sees a context.Context
(deep beneath a tool call, past jsonrpc2/net/http wrapping), this also adds
agent.FromContext(ctx) (ReadonlyContext, bool): ADK contexts register a
read-only view of themselves under a private key, and FromContext returns it.
Identity still lives on the typed context via Session(); nothing is stored under
a key.

Additive and non-breaking: the only new public API in agent is FromContext; the
Value overrides are on unexported/internal context types and change behavior
only for the new private key. No new module dependencies (the GCP client is
hand-rolled over net/http + ADC).
…ontext

FromContext/RequireContext returned a full agent.ReadonlyContext just so the
GCP credential provider could read UserID. That forced a readonlyView
laundering type (13 method forwarders) plus anti-widening + reflection tests,
all existing only to stop the recovered context from being widened back to a
mutable Context/InvocationContext.

Return a small immutable agent.Identity{UserID,AppName,SessionID} via
IdentityFromContext/RequireIdentity instead. Returning a value erases the
widening concern entirely: readonlyView and the widening tests are gone.
Rename the context key SelfKey -> IdentityKey to match what it now carries.

All of this API is new in this PR (absent from main), so nothing released
changes; ReadonlyContext/Context/InvocationContext are untouched.
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-client branch from 73b5382 to c2c93fc Compare July 22, 2026 22:26
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from edeb3da to a4d444d Compare July 22, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant