Skip to content

Fix ADC detection for Google Cloud Shell - #60

Open
pran-ram wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
pran-ram:fix/cloud-shell-adc
Open

Fix ADC detection for Google Cloud Shell#60
pran-ram wants to merge 1 commit into
GoogleCloudPlatform:mainfrom
pran-ram:fix/cloud-shell-adc

Conversation

@pran-ram

Copy link
Copy Markdown

No description provided.

@google-cla

google-cla Bot commented Jul 25, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@mikesson

Copy link
Copy Markdown
Collaborator

Hi @pran-ram , thanks for the PR - could you explain the error you've seen before and the improvement with the code changes provided with the ADC credentials?

@mikesson

Copy link
Copy Markdown
Collaborator

@p-habib-eshwar - here's a description of this proposed change:

In Google Cloud Shell (and some containerized/CI-CD environments), credentials are provisioned dynamically via environment variables or an internal metadata server rather than a physical file stored at $HOME/.config/gcloud/application_default_credentials.json.

Under the old logic, running this script inside Google Cloud Shell would always trigger NEED_LOGIN=true (and issue a warning) because the physical file was missing, even though the environment already had fully authorized, valid credentials.

The new logic recognizes the Cloud Shell credentials because gcloud auth application-default print-access-token succeeds in that environment.

Instead of verifying how the credentials are stored (i.e., looking for a file at a hardcoded path), the script now simply tests if the credentials work. This makes the deployment script more resilient across different operating systems, custom configurations, and automated environments.

The nested conditional statements have been flattened, reducing the logic from 12 lines of code down to 6 lines, making the deployment script easier to maintain.

@pran-ram

Copy link
Copy Markdown
Author

Thanks for expanding on the rationale.

My primary motivation for the change was that the deployment script was treating the absence of $HOME/.config/gcloud/application_default_credentials.json as equivalent to “not authenticated”. In Google Cloud Shell, ADC is already available even though that file doesn’t exist, so the script incorrectly set NEED_LOGIN=true.

The new approach validates that ADC is usable instead of assuming a specific credential storage mechanism, which also makes the check work across a wider range of environments.

@p-habib-eshwar

Copy link
Copy Markdown
Collaborator

Hi @pran-ram, thanks for the contribution. The ADC change looks right, but this PR needs a few things before we can proceed as per docs/contributing.md:

  1. Sign the Google CLA (cla/google is currently failing) - required per docs/contributing.md.
  2. Retarget the PR to devel (functionality changes must not target main).
  3. Rename the branch to the contrib/* convention.
  4. Update the PR description with the purpose of the change.
  5. Please sign your commits and update branch. The current commit is unsigned.

Please update the PR accordingly and we can continue the review.

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.

3 participants