I have a Cloud Run instance which connects to Cloud SQL postgres database through Unix socket with url like: "postgresql+asyncpg://postgres:password@instance-db?host=/cloudsql/project:region:instance-db".
I need to connect with different user/role, but if I use url like: "postgresql+asyncpg://user:user_password@instance-db?host=/cloudsql/project:region:instance-db" I get an error "Database user does not exist".
Is it possible to connect with non postgress role with Cloud Run without sidecaring Cloud Auth Proxy to cloud run service?
Solved! Go to Solution.
Yes, it's indeed possible to connect to a Cloud SQL PostgreSQL database from Cloud Run using a non-default PostgreSQL role. However, there are several important considerations and steps to ensure this setup works correctly:
User/Role Permissions in PostgreSQL
Cloud SQL Configuration
IAM Permissions for Cloud Run Service Account
Connection String Configuration
postgresql+asyncpg://user:user_password@/dbname?host=/cloudsql/project:region:instance-id
Emphasize: Replace the placeholders with your actual role name, password, database name, and instance connection name. Cloud Run's built-in connector provides secure Unix socket-based connections.Important Considerations:
Yes, it's indeed possible to connect to a Cloud SQL PostgreSQL database from Cloud Run using a non-default PostgreSQL role. However, there are several important considerations and steps to ensure this setup works correctly:
User/Role Permissions in PostgreSQL
Cloud SQL Configuration
IAM Permissions for Cloud Run Service Account
Connection String Configuration
postgresql+asyncpg://user:user_password@/dbname?host=/cloudsql/project:region:instance-id
Emphasize: Replace the placeholders with your actual role name, password, database name, and instance connection name. Cloud Run's built-in connector provides secure Unix socket-based connections.Important Considerations:
@ms4446 It worked with proper url string, thank you.