
Cerrar sesión en Google Cloudparececomo debería ser fácil. Si corro:
$ unset GOOGLE_APPLICATION_CREDENTIALS
$ gcloud auth revoke --all
Revoked credentials:
- [my account]
$ gcloud auth list
No credentialed accounts.
To login, run:
$ gcloud auth login `ACCOUNT`
al principioaspectocomo si estuviera completamente desconectado gcloud
. Pero mira lo que sucede cuando abro un shell de Python:
>>> from google.cloud import secretmanager_v1beta1 as secretmanager
>>> client = secretmanager.SecretManagerServiceClient()
/Users/my/path/.venv/lib/python3.7/site-packages/google/auth/_default.py:66: UserWarning: Your application has authenticated using end user credentials from Google Cloud SDK. We recommend that most server applications use service accounts instead. If your application continues to use end user credentials from Cloud SDK, you might receive a "quota exceeded" or "API not enabled" error. For more information about service accounts, see https://cloud.google.com/docs/authentication/
warnings.warn(_CLOUD_SDK_CREDENTIALS_WARNING)
>>> path = client.secret_version_path(project="my-project-name", secret="my-secret", secret_version="latest")
>>> secret = client.access_secret_version(path)
>>> secret.payload.data.decode()
"Oh, no! I should be secret!"
Como puede ver, aunque ejecuté, gcloud auth revoke --all
todavía puedo acceder a Google Cloud a través del SDK de Python utilizando las credenciales de usuario que están almacenadas en algún lugar. ¿Hay alguna manera decompletamente¿Cerrar sesión de Google Cloud en mi computadora portátil?
EDITAR: para aclarar más: no hay ningún archivo JSON de cuenta de Google Cloud Service guardado en esta computadora y he desarmado la GOOGLE_APPLICATION_CREDENTIALS
variable de entorno.
Respuesta1
No estoy seguro de si esto te ayudará de alguna manera, pero me encontré con un problema similar. Una vez que revoqué todas las credenciales usando el comando, gcloud auth revoke --all
todavía pude ejecutar scripts en mi entorno. Al final, encontré el archivo de credenciales predeterminado de la aplicación ubicado en~/.config/gcloud/application_default_credentials.json. Cambiar el nombre o eliminar este archivo ayudó a revocar las credenciales por completo. Y ahora la biblioteca cliente no tiene acceso al entorno:
File "audit_test.py", line 8, in main
client = resource_manager.Client()
File "fake_path/python3.7/site-packages/google/cloud/resource_manager/client.py", line 72, in __init__
super(Client, self).__init__(credentials=credentials, _http=_http)
File "fake_path/python3.7/site-packages/google/cloud/client.py", line 132, in __init__
credentials, _ = google.auth.default()
File "fake_path/python3.7/site-packages/google/auth/_default.py", line 321, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started
Respuesta2
Como se comentó anteriormente porAjahnCharles, gcloud auth application-default revoke
obras. Simplemente presione el comando y eliminará los application-default
créditos. Ver la diferenciaaquí. Tuve el mismo problema y solo esto funcionó.
Editar:
Recuerde que aún necesita llamar, gcloud auth revoke --all
ya que gcloud auth application-default revoke
solo elimina los créditos predeterminados de la aplicación.