Skip to content

Authenticating local Python clients as individual users #1309

Closed

Description

@hartikainen

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:

  1. The client impersonated a shared service account (XMC_CLIENT_SA) to create an ID token for our XMC OAuth audience (IAP_CLIENT_ID).
  2. AuditMetadataInterceptor attached the local user's email as x-goog-user-email gRPC metadata on requests to the Experiment State Server (ESS), which forwarded that header to the XID service.
  3. The CreateExperiment request 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

  1. 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.
  2. 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 gcloud carry the Google Cloud SDK OAuth client ID as their audience rather than our XMC IAP_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?

  1. How are local Python clients expected to authenticate after #775 while preserving individual user attribution (creator and per-user ACL isolation)?
  2. Is there an existing CLI login or token-exchange flow that creates an XMC session token (or an ID token with IAP_CLIENT_ID audience) for a human user, or is per-user service account provisioning expected?
  3. If authenticating with gcloud user 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

  1. added
    question
    on Oct 19, 2026
  2. self-assigned this
    on Oct 19, 2026
  3. VLukiantsev commented on Oct 19, 2026

    @VLukiantsev
    Collaborator

    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-email could 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 set owners = 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 with aud = 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:

    1. Add http://localhost:8085/ as an authorized redirect URI on your XMC OAuth client.
    2. Run an OAuth authorization-code (loopback) flow against that client with scopes openid email and redirect http://localhost:8085/. You can use google_auth_oauthlib.flow.InstalledAppFlow with run_local_server(port=8085).
    3. Send the returned id_token as the bearer token on the gRPC channel, and set the ACL owner to the user.

    Result: creator=<user>@<company>.com and 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 aud no 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.

  4. VLukiantsev commented on Oct 23, 2026

    @VLukiantsev
    Collaborator

    Hi @hartikainen — following up here: interactive per-user CLI authentication is now available in XMC 0.16.0 along with xmanager >= 0.8.5.post1 on 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 additional localhost redirect URIs need to be registered on your Google OAuth client.

    How to use it

    1. Upgrade your XMC deployment to 0.16.0.
    2. Upgrade the xmanager client in your local Python environment:
      pip install -U "xmanager>=0.8.5.post1"
    3. Sign in as yourself:
      # Opens your browser (or use --no-browser on headless/SSH machines)
      xmanager login --env=/path/to/.env
      This caches your user session token in ~/.config/xmc/credentials.json (0600).
    4. Launch experiments as usual:
      xmanager launch and the Python SDK (experiment_state_api) automatically pick up the cached token from ~/.config/xmc/credentials.json before falling back to XMC_AUTH_TOKEN or XMC_CLIENT_SA. Your experiments will record your individual Google email as creator, and per-user ACL ownership works out of the box without adding XMC_CLIENT_SA.

    Useful flags & docs:

    • xmanager login --status — check cached token status and expiry
    • xmanager login --no-browser — copy/paste authorization code flow for remote/SSH sessions
    • xmanager logout — clear cached credentials
    • Full details and architecture: docs/authentication.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

question

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions