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 SDK does not pick up the correct user project when running on Vertex Pipelines or CustomJobs #852

Closed
Ark-kun opened this issue Nov 18, 2021 · 2 comments · Fixed by #943, #1068 or #1059
Assignees
Labels
api: aiplatform Issues related to the AI Platform API. priority: p2 Moderately-important priority. Fix may not be included in next release.

Comments

@Ark-kun
Copy link
Contributor

Ark-kun commented Nov 18, 2021

Usually the Vertex SDK gets the project ID automatically (by calling google.auth.default()). This works when running on Kubeflow Pipelines.
However when running on Vertex Pipelines or 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).

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.

Deducing 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)

Perhaps we should improve the Vertex SDK initializer to use the project mentioned in CLOUD_ML_PROJECT_ID if it's available by default.

@product-auto-label product-auto-label bot added the api: aiplatform Issues related to the AI Platform API. label Nov 18, 2021
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Nov 19, 2021
@morgandu morgandu removed the triage me I really want to be triaged. label Nov 23, 2021
@yoshi-automation yoshi-automation added triage me I really want to be triaged. 🚨 This issue needs some love. labels Nov 23, 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.
@kweinmeister kweinmeister added priority: p2 Moderately-important priority. Fix may not be included in next release. and removed 🚨 This issue needs some love. triage me I really want to be triaged. labels Feb 1, 2022
@Ark-kun
Copy link
Contributor Author

Ark-kun commented Mar 11, 2022

I'm not sure this issue is fixed.

@Ark-kun
Copy link
Contributor Author

Ark-kun commented Mar 15, 2022

/reopen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: aiplatform Issues related to the AI Platform API. priority: p2 Moderately-important priority. Fix may not be included in next release.
Projects
None yet
5 participants