Repository navigation
fix(auth): fall back to metadata service when CLOUDSDK_CONFIG points at a directory without the well-known ADC file - #1094
Conversation
…to a directory without the well-known ADC file CLOUDSDK_CONFIG only relocates the gcloud CLI config directory (commonly set to work around readOnlyRootFilesystem containers); it is not an ADC directive. Prior to this change, its mere presence in the environment flipped set_explicitly=True, so a missing $CLOUDSDK_CONFIG/ application_default_credentials.json raised FileNotFoundError instead of falling through to the GCE metadata service. The docstring on get_service_data() states the function is meant to match google.auth.default(). Its _get_gcloud_sdk_credentials() step silently returns None when the well-known file is absent, regardless of CLOUDSDK_CONFIG, so ADC proceeds to the metadata service. This change brings the async library in line with that reference behaviour. Only GOOGLE_APPLICATION_CREDENTIALS remains an explicit user directive: if it is set, a missing file still raises (the else-branch is unchanged, and a regression test covers this). Fixes talkiq#936.
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Workspace UI Review profile: ASSERTIVE Plan: Enterprise Run ID: 📒 Files selected for processing (2)
Updates ADC discovery so missing well-known credentials under Overall Judgement: ✅ Ready to merge — behavior is narrowly scoped and covered by targeted unit tests. Walkthrough
ChangesCredential discovery behavior
Assessment against linked issues
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Fixes #936.
Problem
When
CLOUDSDK_CONFIGis set in the environment (a common workaround forreadOnlyRootFilesystemcontainers that need a writablegcloudCLI config directory), and the file at$CLOUDSDK_CONFIG/application_default_credentials.jsondoes not exist,get_service_data()raisesFileNotFoundErrorinstead of returning{}. That preventsTokenfrom falling back to the GCE metadata service, which breaks Workload Identity–only authentication for any async workload whose base image happens to exportCLOUDSDK_CONFIG.The docstring on
get_service_data()states the function is meant to matchgoogle.auth.default(). In google-auth,_get_gcloud_sdk_credentials()guards the well-known file withos.path.isfile()and silently returnsNonewhen it is missing, regardless ofCLOUDSDK_CONFIG. OnlyGOOGLE_APPLICATION_CREDENTIALSis treated as explicit user intent.Fix
In the well-known-file branch,
set_explicitlyis now alwaysFalse(previouslybool(cloudsdk_config)). TheGOOGLE_APPLICATION_CREDENTIALSbranch is unchanged; a missing file at that path still raises.Testing
GCSObjects*sensor on a Kubernetes environment where the triggerer pod exportedCLOUDSDK_CONFIG=/tmp/gcloudwith no file at that path — trigger yieldedFileNotFoundErrorinstead of falling back to WI. With this patch applied the trigger polls cleanly through the metadata service and the sensor completes normally.auth/tests/unit/token_test.py. All existing and new tests pass locally.