[Python] Authentication for Google Cloud in a docker

Discussão em 'Python' iniciado por Stack, Maio 23, 2025.

  1. Stack

    Stack Membro Participativo

    Sorry for the lengthy question, but I find the authentication for Google Cloud confusing, and am not sure where the problem is.

    If I run my script outside of a container, it works, but within a container I get the following error:

    credentials, google_project_id = google.auth.default()
    ^^^^^^^^^^^^^^^^^^^^^
    File "/usr/local/lib/python3.11/site-packages/google/auth/_default.py", line 685, in default
    raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
    google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.


    Via the above link I get to the page Set up ADC for a containerized development environment, where it says


    To test your containerized application on your local workstation, you can configure your container to authenticate with your local ADC file. For more information, see Configure ADC with your Google Account.
    ​

    I'm trying to test my containerized application on my local workstation.

    However, I've changed the project in Google Cloud and tried to set the new project with the following commands:

    $ gcloud config set project new-project

    WARNING: Your active project does not match the quota project in your local Application Default Credentials file. This might result in unexpected quota issues.

    To update your Application Default Credentials quota project, use the `gcloud auth application-default set-quota-project` command.
    Updated property [core/project].


    $ gcloud auth application-default set-quota-project new-project

    Credentials saved to file: [/home/.../.config/gcloud/application_default_credentials.json]

    These credentials will be used by any library that requests Application Default Credentials (ADC).

    Quota project "new-project" was added to ADC which can be used by Google client libraries for billing and quota. Note that some services may still bill the project owning the resource.


    If I now try to create local authentication credentials for my user account as recommended in the guide for configuring ADC with my Google Account, it still refers to the old project:

    $ gcloud auth application-default login

    Your browser has been opened to visit:
    ...

    Credentials saved to file: [/home/.../.config/gcloud/application_default_credentials.json]

    These credentials will be used by any library that requests Application Default Credentials (ADC).

    Quota project "WRONG_PROJECT" was added to ADC which can be used by Google client libraries for billing and quota. Note that some services may still bill the project owning the resource.


    So, could the reason for the error in the docker be that I have the wrong quota project associated with my Application Default Credentials? How can I change that since the set project and set-quota-project commands do not help?

    I've read, for example, these SO questions, but they don't seem to answer my problem:


    Continue reading...

Compartilhe esta Página