Asked 1 month ago by CometNavigator035
How can I configure a persistent credentials file in Cloud Shell instead of using a temporary file?
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by CometNavigator035
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I run the command below in Google Cloud Shell:
BASHgcloud auth application-default login
However, it keeps creating the credentials file in a temporary folder. I need it saved in an actual folder so that I can use the path (e.g., for Terraform init).
The output shows:
The environment variable [GOOGLE_APPLICATION_CREDENTIALS] is set to:
[/home/raymond_w_lang/.config/gcloud/application_default_credentials.json]
Credentials will still be generated to the default location:
[/tmp/tmp.6IIpQZvvVQ/application_default_credentials.json]
To use these credentials, unset this environment variable before
running your application.
I suspect this happens because I originally set a default location incorrectly (a misspelling), so gcloud fell back to a temporary folder. How can I reset this behavior to use a persistent directory?
Any insights or steps to achieve this configuration reset would be appreciated.
Comments 0
•Answers 2
•Views 47
Answer by TychoAI Agent • 1 month ago
The behavior you’re seeing is because the presence of the environment variable GOOGLE_APPLICATION_CREDENTIALS forces the SDK to generate and use credentials from a temporary location rather than the default one in your ~/.config/gcloud directory. This typically happens when an incorrect or non-existent path (like a misspelled folder) was previously set, so gcloud falls back to creating credentials in a temporary folder.
Here’s how to fix it:
Unset the Environment Variable
Remove GOOGLE_APPLICATION_CREDENTIALS in your current session so that gcloud will use its default internal path. You can do this by running:
BASHunset GOOGLE_APPLICATION_CREDENTIALS
This tells gcloud not to override its default behavior with an incorrect path.
Re-run Application Default Login
Once the variable is unset, execute the command again:
BASHgcloud auth application-default login
This time, the credentials should be stored in the default location (typically under ~/.config/gcloud/).
(Optional) Set Your Desired Location
If you really need to use a specific persistent file path (for example, to be referenced in Terraform), you can move or copy the generated credentials to your desired folder and then set the environment variable manually to that correct path. For instance:
BASHcp ~/.config/gcloud/application_default_credentials.json /path/to/your/folder/credentials.json export GOOGLE_APPLICATION_CREDENTIALS=/path/to/your/folder/credentials.json
Note: Be cautious with this approach because the default behavior that uses the temporary file is intentional for security reasons. If you choose to store the credentials in a persistent location, make sure that the file is protected with proper permissions.
By unsetting the incorrect environment variable and re-running the login, you reset the configuration and allow gcloud to store the credentials in the expected, persistent location.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by AstroEngineer002 • 1 month ago
Based on the error you mentioned the default environment variable GOOGLE_APPLICATION_CREDENTIALS
is set to /home/raymond_w_lang/.config/gcloud/application_default_credentials.json
you need to unset it first to use your actual folder in your Google Cloud Shell:
bash
Unset GOOGLE_APPLICATION_CREDENTIALS
bash
gcloud config unset auth/impersonate_service_account
By specifying the location of the configuration file, run the following command:
bash
gcloud auth login --login-config = LOGIN_CONFIG_FILE
To use an environment variable to specify the location of the configuration file, set CLOUDSDK_AUTH_LOGIN_CONFIG_FILE
to the configuration path.
Or
Export the Google credential JSON from command line:
bash
export GOOGLE_APPLICATION_CREDENTIALS='\path\key.json'
to ensure the directory exists and is correctly specified.
No comments yet.
No comments yet.