Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The auth.default() does not pick up the correct user project when running on Vertex Pipelines or CustomJobs #924

Open
Ark-kun opened this issue Nov 19, 2021 · 0 comments
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@Ark-kun
Copy link

Ark-kun commented Nov 19, 2021

Usually the Vertex SDK gets the project ID automatically (by calling google.auth.default()). This works when running on GKE, GCE, Kubeflow Pipelines etc.

However when running on Google Cloud Vertex Pipelines or Vertex Training CustomJobs, the detected project is not the user project and is not usable.

This leads to failure when trying to create any resource in the project:

google.api_core.exceptions.PermissionDenied: 403 Permission 'aiplatform.models.upload' denied on resource '//aiplatform.googleapis.com/projects/gbd40bc90c7804989-tp/locations/us-central1' (or it may not exist).

Here gbd40bc90c7804989-tp is NOT the correct user project.

Fortunately there is a way to get project number from the Vertex environment. There is also a way to get project ID from the project number.

Inferring project number

project_number = os.environ.get("CLOUD_ML_PROJECT_ID")

Getting project ID:

    if not project:
        project_number = os.environ.get("CLOUD_ML_PROJECT_ID")
        if project_number:
            print(f"Inferred project number: {project_number}")
            project = project_number
            # To improve the naming we try to convert the project number into the user project ID.
            try:
                from googleapiclient import discovery

                cloud_resource_manager_service = discovery.build(
                    "cloudresourcemanager", "v3"
                )
                project_id = (
                    cloud_resource_manager_service.projects()
                    .get(name=f"projects/{project_number}")
                    .execute()["projectId"]
                )
                if project_id:
                    print(f"Inferred project ID: {project_id}")
                    project = project_id
            except Exception as e:
                print(e)

Environment details

  • OS:
  • Python version: 3.9
  • pip version: 21.1.1
  • google-auth version: 2.3.3

Steps to reproduce

  1. google.auth.default()

See: googleapis/python-aiplatform#852

@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Nov 19, 2021
@parthea parthea added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed triage me I really want to be triaged. labels Nov 20, 2021
Ark-kun added a commit to Ark-kun/python-aiplatform that referenced this issue Jan 6, 2022
When project ID is not explicitly specified in `aiplatform.init()` call, the SDK uses `google.auth.default()` to infer the project ID.
However when running under Vertex AI (CustomJob, PipelineJob), the project returned by `google.auth.default()` is not the correct user project.
See googleapis#852
See googleapis/google-auth-library-python#924
This PR fixes the fallback to get the project ID from the `CLOUD_ML_PROJECT_ID` environment variable.
@yoshi-automation yoshi-automation added 🚨 This issue needs some love. and removed 🚨 This issue needs some love. labels Feb 18, 2022
@yoshi-automation yoshi-automation added the 🚨 This issue needs some love. label May 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. 🚨 This issue needs some love. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

No branches or pull requests

3 participants