Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def build_database_url():
user = os.environ.get("CLOUD_SQL_USER", "")
password = os.environ.get("CLOUD_SQL_PASSWORD", "")
database = os.environ.get("CLOUD_SQL_DATABASE", "")
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
# Host is provided by connector, so leave blank.
if use_iam_auth:
return f"postgresql+pg8000://{user}@/{database}"
Expand Down Expand Up @@ -122,7 +122,7 @@ def run_migrations_online() -> None:
user = os.environ.get("CLOUD_SQL_USER")
password = os.environ.get("CLOUD_SQL_PASSWORD")
database = os.environ.get("CLOUD_SQL_DATABASE")
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above in the online migration path: switching CLOUD_SQL_IAM_AUTH default to True can break environments that previously relied on password auth without explicitly setting the flag. Consider requiring explicit configuration or a safer default/fallback.

Suggested change
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)

Copilot uses AI. Check for mistakes.
ip_type = os.environ.get("CLOUD_SQL_IP_TYPE", "public")

connector = Connector()
Expand Down
7 changes: 3 additions & 4 deletions db/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
# limitations under the License.
# ===============================================================================

import asyncio
import copy
import getpass
import os
Expand All @@ -24,7 +23,7 @@
from sqlalchemy import (
create_engine,
)
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
from sqlalchemy.ext.asyncio import create_async_engine
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description still contains the template placeholders (no concrete Why/How/Notes). Please fill this in so reviewers can confirm the intended behavior change (especially the IAM auth default flip) and any expected deployment/config updates.

Copilot uses AI. Check for mistakes.
from sqlalchemy.orm import (
sessionmaker,
)
Expand Down Expand Up @@ -72,7 +71,7 @@ def asyncify_connection():
user = os.environ.get("CLOUD_SQL_USER")
password = os.environ.get("CLOUD_SQL_PASSWORD")
database = os.environ.get("CLOUD_SQL_DATABASE")
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing the default for CLOUD_SQL_IAM_AUTH from False to True is a behavior change: if an environment relies on password auth and does not explicitly set CLOUD_SQL_IAM_AUTH, it will now attempt IAM token acquisition (ADC) and may fail at startup. Consider requiring explicit opt-in (no default), or selecting the default based on whether CLOUD_SQL_PASSWORD is set / whether Google credentials are available.

Suggested change
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
if "CLOUD_SQL_IAM_AUTH" in os.environ:
# Honor explicit configuration of IAM auth.
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)
else:
# Derive a safe default: prefer password auth when a password is set.
use_iam_auth = False if password else True

Copilot uses AI. Check for mistakes.
ip_type = os.environ.get("CLOUD_SQL_IP_TYPE", "public")

connect_kwargs = {
Expand Down Expand Up @@ -109,7 +108,7 @@ def init_connection_pool(connector):
user = os.environ.get("CLOUD_SQL_USER")
password = os.environ.get("CLOUD_SQL_PASSWORD")
database = os.environ.get("CLOUD_SQL_DATABASE")
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", False)
use_iam_auth = get_bool_env("CLOUD_SQL_IAM_AUTH", True)
ip_type = os.environ.get("CLOUD_SQL_IP_TYPE", "public")

Comment on lines 109 to 113
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern here: defaulting CLOUD_SQL_IAM_AUTH to True can silently switch Cloud SQL connections to IAM auth when the env var is omitted, breaking password-auth deployments. Please make this explicit (env var required) or implement a safe default/fallback strategy.

Copilot uses AI. Check for mistakes.
def getconn():
Expand Down