Repository navigation
Description
I'm trying to understand the recommended way for developers to launch experiments from a local machine via the Python client while keeping their individual Google email as the experiment creator.
Context
We recently upgraded our XMC deployment from 52886e1c0e40 (v0.8.0) to d71d985e57a7, which includes the authentication changes from #775 (199d2d28a32f).
Previously, our local launch flow worked like cmd/experiment_state_server/experiment_state_api.py:
- The client impersonated a shared service account (
XMC_CLIENT_SA) to create an ID token for our XMC OAuth audience (IAP_CLIENT_ID). AuditMetadataInterceptorattached the local user's email asx-goog-user-emailgRPC metadata on requests to the Experiment State Server (ESS), which forwarded that header to the XID service.- The
CreateExperimentrequest set the human user (<user>@<company>.com) as the ACL owner, without adding the shared service account to the ACL.
In 199d2d28a32f, resolveUserEmail stopped reading unverified x-goog-user-email metadata and now extracts the caller's email strictly from the verified JWT. Because the bearer token belongs to the impersonated service account, CreateExperiment now resolves the creator as xmc-workload@PROJECT_ID.iam.gserviceaccount.com and fails the creator write-permission check against the user-owned ACL:
creator xmc-workload@PROJECT_ID.iam.gserviceaccount.com did not give themselves write permissions on the XID 12345: rpc error: code = PermissionDenied desc = permission denied
Ignoring unverified x-goog-user-email metadata makes sense from a security standpoint, since any caller could spoof that header. However, it leaves us unsure how interactive CLI launches are meant to authenticate per-user.
Workarounds we've tried
- Adding the shared service account as an ACL writer: Restores launches, but every experiment's creator is recorded as the shared service account rather than the human user, and all users impersonating that service account share write access.
- Authenticating directly with user ADC (
gcloud auth login --update-adc): Sending the user's own ID token preserves individual identity, without requiring service account impersonation. However:google.oauth2.id_token.fetch_id_token()only supports service account and metadata server credentials, so the client has to refresh user ADC credentials directly.- Tokens created by
gcloudcarry the Google Cloud SDK OAuth client ID as their audience rather than our XMCIAP_CLIENT_ID. To accept them, we had to patch ESS, XID, and Dashboard to allow the Google Cloud SDK audience and run the same email/domain/IAM admission checks used by browser OAuth login.
Questions
Before we maintain our custom user-ADC patch (or open a PR for that patch), we'd like to get clarification on the intended design?
- How are local Python clients expected to authenticate after #775 while preserving individual user attribution (
creatorand per-user ACL isolation)? - Is there an existing CLI login or token-exchange flow that creates an XMC session token (or an ID token with
IAP_CLIENT_IDaudience) for a human user, or is per-user service account provisioning expected? - If authenticating with
gclouduser ADC tokens is a reasonable direction, is accepting the Google Cloud SDK client audience and enforcing the OAuth admission policy on backend gRPC services the right approach, or is there a simpler configuration we missed?
Activity
VLukiantsev commentedon Oct 19, 2026
Thanks @hartikainen for the detailed write-up! Your read of #775 is correct: identity now comes only from the verified bearer token, because
x-goog-user-emailcould be spoofed.1. How should local clients authenticate while keeping per-user attribution?
With a token that belongs to the user, not with shared-SA impersonation. With
XMC_CLIENT_SA, the creator is always the SA. Our own examples only work because they setowners = all_authenticated_users, which is your workaround #1 with an even wider ACL. That setup is fine for CI and automation, but it isn't a per-user auth model. ESS and XID already accept a Google ID token for the user withaud = IAP_CLIENT_ID, with no server changes.2. Is there an existing CLI login, or are per-user SAs expected?
There's no CLI login yet. That's a gap on our side, and per-user SAs aren't the intended model. We tested this workaround on our deployment, and it needs no server patch:
http://localhost:8085/as an authorized redirect URI on your XMC OAuth client.openid emailand redirecthttp://localhost:8085/. You can usegoogle_auth_oauthlib.flow.InstalledAppFlowwithrun_local_server(port=8085).id_tokenas the bearer token on the gRPC channel, and set the ACL owner to the user.Result:
creator=<user>@<company>.comand the ACL holds only that user. ID tokens expire after 1h; use the refresh token to get new ones. The caveat is that the CLI needs your OAuth client secret.We'll ship a proper login flow in the next version: a CLI command that signs the user in through the browser and gives the client an XMC token tied to their own identity, with the same admission checks as the Dashboard.
3. Should XMC accept the gcloud SDK audience?
We'd advise against it. The Cloud SDK client ID is shared by every gcloud user, so
audno longer ties the token to XMC. Admission checks would become the only gate, and a token minted for another purpose could be replayed against XMC. The workaround above gives you per-user identity without that patch. We'd rather support an explicit allowlist of OAuth client IDs that you own, and we'll cover that in the login work. Happy to take input on the design here in #1309.VLukiantsev commentedon Oct 23, 2026
Hi @hartikainen — following up here: interactive per-user CLI authentication is now available in XMC
0.16.0along withxmanager >= 0.8.5.post1on PyPI.How it works
Instead of distributing an OAuth client secret to developer machines or impersonating
XMC_CLIENT_SA, the XMC Dashboard acts as the OAuth broker (/auth/cli/start→/auth/callback→/auth/cli/exchange) using PKCE (S256) and issues an XMC-signed session JWT (aud = IAP_CLIENT_ID,sub = <user>@<domain>) after enforcing your deployment's email/domain/IAM admission checks. No additionallocalhostredirect URIs need to be registered on your Google OAuth client.How to use it
0.16.0.xmanagerclient in your local Python environment:pip install -U "xmanager>=0.8.5.post1"# Opens your browser (or use --no-browser on headless/SSH machines) xmanager login --env=/path/to/.env~/.config/xmc/credentials.json(0600).xmanager launchand the Python SDK (experiment_state_api) automatically pick up the cached token from~/.config/xmc/credentials.jsonbefore falling back toXMC_AUTH_TOKENorXMC_CLIENT_SA. Your experiments will record your individual Google email ascreator, and per-user ACL ownership works out of the box without addingXMC_CLIENT_SA.Useful flags & docs:
xmanager login --status— check cached token status and expiryxmanager login --no-browser— copy/paste authorization code flow for remote/SSH sessionsxmanager logout— clear cached credentialsdocs/authentication.md