Open uriyyo opened 9 hours ago
Hi @uriyyo thanks for raising an issue on the Cloud SQL Python Connector! š
I am curious as to where you are deploying the application? Is it Cloud Run, GKE, et?.
I wonder if the Service Usage Consumer
is a permission that is only required in a certain serverless environment.
Hi @jackwotherspoon,
We are using PostgreSQL instance together with Cloud Run Funciton
We are using PostgreSQL instance together with Cloud Run Function
Thanks for the quick reply @uriyyo š
Let me try and quickly reproduce the issue in my own Cloud Run Function, then I will take a look at your PR, thanks again! š
@uriyyo I have not been able to reproduce this issue yet. I am able to successfully connect with the Python Connector in a Cloud Run Function with purely the Cloud SQL Client
role.
Is there any other part of your setup I should know about that may be causing the need for the Service Usage Consumer
role? Is your Cloud Run Function in a different project than your Cloud SQL instance?
Bug Description
When I try to connect to a Cloud SQL instance using the
google.cloud.sql.connector.Connector
I'm getting error:Forbidden: Authenticated IAM principal does not seem authorized to make API request. Verify 'Cloud SQL Admin API' is enabled within your GCP project and 'Cloud SQL Client' role has been granted to IAM principal.
But I have already granted the
Cloud SQL Client
role to the service account. Actually, the issue is with theService Usage Consumer
permission. Under the hood, thegoogle.cloud.sql.connector.Connector
uses theService Usage Consumer
permission to get service metadata. So, you need to grant theService Usage Consumer
permission to the service account to fix this issue.https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/blob/d622575cab34c0dc85763076f7c404e7265c3f26/google/cloud/sql/connector/client.py#L258-L262
https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/blob/d622575cab34c0dc85763076f7c404e7265c3f26/google/cloud/sql/connector/client.py#L128-L131
Here we override exception message: https://github.com/GoogleCloudPlatform/cloud-sql-python-connector/blob/d622575cab34c0dc85763076f7c404e7265c3f26/google/cloud/sql/connector/instance.py#L136-L137
Because of this issue, the error message is misleading and confusing (I spent a lot of time debugging this issue š ).
Example code (or command)
Stacktrace
No response
Steps to reproduce?
Environment
Additional Details
No response