apache / apache/arrow-adbc

IAM Auth Login for CloudSQL (GCP, Postgres, Python)

Open
#4,010 3 comments 2 reactions 0 assignees View on GitHub
Type: enhancement
Dominant language
C#
Stars
627
Forks
217
Avg merge
17h
Merged PRs (30d)
57

Description

### What feature or improvement would you like to see?

I have a GCP CloudSQL instance running postgres and I would like to connect to it through ADBC using IAM auth login (similar to the [dbc.how "getting started" BigQuery method](https://docs.columnar.tech/dbc/getting_started/first_steps/#loading-using-a-driver)).

Right now, I can connect through SQL alchemy using this function:

```python
import sqlalchemy
from google.cloud.sql.connector import Connector, IPTypes

def sa_eng_pg_iam(project, user, region="us-east1", pg_instance="01"):
# 1. Initialize Cloud SQL Python Connector
connector = Connector()

# 2. Connection function
def getconn():
instance_str = f"{project}:{region}:pg-{project}-{pg_instance}"
conn = connector.connect(
instance_connection_string=instance_str, # INSTANCE_CONNECTION_NAME
driver="pg8000",
user=user, # IAM Database User
db="postgres",
enable_iam_auth=True, # Enable IAM Auth
ip_type=IPTypes.PUBLIC, # Use IPTypes.PRIVATE for VPC
)
return conn

# 3. Create SQLAlchemy pool
pool = sqlalchemy.create_engine(
"postgresql+pg8000://",
creator=getconn,
)
return pool

```

From there I can return the sqlalchemy engine by using only my IAM user email after authing through `gcloud blah blah blah`.

It would be nice to have a similar method with ADBC.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.