Skip to content

feat: add Google Cloud OIDC detector - #306

Draft
cloudsmith-iduffy wants to merge 2 commits into
masterfrom
iduffy/gcp-oidc
Draft

feat: add Google Cloud OIDC detector#306
cloudsmith-iduffy wants to merge 2 commits into
masterfrom
iduffy/gcp-oidc

Conversation

@cloudsmith-iduffy

@cloudsmith-iduffycloudsmith-iduffy commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a Google Cloud OIDC environment detector to the credential auto-discovery chain, mirroring the existing AWS detector. When CLOUDSMITH_ORG and CLOUDSMITH_SERVICE_SLUG are set, the CLI mints an OIDC ID token from the ambient Google identity via the google-auth SDK and exchanges it for a short-lived Cloudsmith token — no long-lived credentials on disk.

  • New optional dependency google-auth>=2.0.0 under a [gcp] extra (also added to [all]), matching the AWS [aws]/boto3 pattern.
  • Discovery uses google.auth.default() — the standard ADC chain (GOOGLE_APPLICATION_CREDENTIALS service-account key → local gcloud user credentials → GCE/Cloud Run/GKE/App Engine metadata server). get_token() turns the resolved credentials into an ID token:
    • compute/metadata credentials → queried via google-auth's metadata client with format=full, which adds the email/identity claims so users have more to validate against (the SDK's metadata ID-token path omits them).
    • local gcloud user credentials → refreshed id_token used directly (fetch_id_token_credentials doesn't support user credentials).
    • service-account keys, impersonated SAs, external accounts / Workload Identity Federation → delegated to google-auth's own fetch_id_token_credentials dispatch.
  • detect() activates only when google-auth is importable and either ADC resolves or the metadata server is reachable (via the IP-based is_on_gce probe, which avoids the slow-DNS hang on non-GCE hosts); it never raises into the chain.
  • Registered as [AWSDetector, GCPDetector] — after the AWS detector.

Test Plan

  • Unit tests: 15 tests in test_gcp_detector.py covering all detect branches and every credential path (compute/metadata, user ADC, delegated dispatch, fallbacks); hermetic (real ADC on the dev machine is never touched). Skipped cleanly when the [gcp] extra is absent. Full core suite: 171 passed, no regressions.
  • Live end-to-end: with cache cleared, CLOUDSMITH_ORG=iduffy-demo CLOUDSMITH_SERVICE_SLUG=google-10rf cloudsmith whoami authenticates as the google-10rf service account via the user-ADC path in ~3s (no hang).

🤖 Generated with Claude Code

@cloudsmith-iduffy
cloudsmith-iduffy requested a review from a team as a code ownerJune 8, 2026 22:55
@cloudsmith-iduffy
cloudsmith-iduffy marked this pull request as draft June 8, 2026 22:57
@cloudsmith-iduffy
cloudsmith-iduffy changed the base branch from generic-oidc-detector to masterJune 8, 2026 23:01
@cloudsmith-iduffy
cloudsmith-iduffyforce-pushed the iduffy/gcp-oidc branch 6 times, most recently from e8c47d0 to d8816e1CompareJune 10, 2026 14:06
@cloudsmith-iduffy
cloudsmith-iduffyforce-pushed the iduffy/gcp-oidc branch 2 times, most recently from 8c48230 to 60f4060CompareJune 10, 2026 19:46
cloudsmith-iduffyand others added 2 commits June 10, 2026 21:22
Add two controls for OIDC detector selection, resolved through the
credential context rather than read ad hoc from the environment:
- CLOUDSMITH_OIDC_<ID>_DISABLED skips a specific detector (only the
literal "true", case-insensitive, disables). The credentials
decorator resolves these into context.oidc_disabled_detectors.
- --oidc-detector-order (env var CLOUDSMITH_OIDC_DETECTOR_ORDER)
overrides which detectors are considered and the order they are
tried in (comma-separated ids; unlisted/unknown ids are skipped).
When both are set the order list defines the candidate set and
sequence, then the disabled set is applied on top, so a disabled
detector is always skipped. Each detector gains a stable `id`
attribute and a public `registered_detectors()` accessor is added.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Adds a Google Cloud OIDC environment detector to the credential
auto-discovery chain, mirroring the existing AWS detector. When
CLOUDSMITH_ORG and CLOUDSMITH_SERVICE_SLUG are set, the CLI mints an
OIDC ID token from the ambient Google identity via the google-auth SDK
and exchanges it for a short-lived Cloudsmith token.
Discovery uses google.auth.default() -- the standard ADC chain
(GOOGLE_APPLICATION_CREDENTIALS service-account key, local gcloud user
credentials, then the GCE/Cloud Run/GKE/App Engine metadata server).
get_token() turns the resolved credentials into an ID token:
- compute/metadata credentials are queried via the metadata client with
format=full, which adds the email/identity claims so users have more
to validate against (the SDK's metadata ID-token path omits them);
- local gcloud user credentials use their refreshed id_token directly
(fetch_id_token_credentials does not support user credentials);
- service-account keys, impersonated service accounts, and external
accounts / Workload Identity Federation are delegated to google-auth's
own fetch_id_token_credentials dispatch.
detect() activates only when google-auth is importable and either ADC
resolves or the metadata server is reachable (via the IP-based
is_on_gce probe, avoiding slow DNS on non-GCE hosts); it never raises
into the chain. google-auth is an optional dependency under a new [gcp]
extra.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudsmith-iduffy
cloudsmith-iduffy changed the base branch from master to iduffy/oidc-detector-controlsJune 10, 2026 20:26
Base automatically changed from iduffy/oidc-detector-controls to masterJune 11, 2026 09:37
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

@cloudsmith-iduffy