Skip to content

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

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

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.FromContext` / `agent.RequireContext` 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 still
    lives on the typed context via `Session()`.
  • Config-struct API (`ProviderConfig`), consistent with `gcp.NewClient`.

@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from a46455a to 421a856 Compare July 18, 2026 20:44
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).
@wolo-lab
wolo-lab force-pushed the wolo/auth-gcp-provider branch from 421a856 to eadd5a6 Compare July 18, 2026 23:33
…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.
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