Skip to content

jir-ogc#553

Merged
jirhiker merged 1 commit intostagingfrom
jir-ogc
Feb 27, 2026
Merged

jir-ogc#553
jirhiker merged 1 commit intostagingfrom
jir-ogc

Conversation

@jirhiker
Copy link
Copy Markdown
Member

Why

This PR addresses the following problem / context:

  • Use bullet points here

How

Implementation summary - the following was changed / added / removed:

  • Use bullet points here

Notes

Any special considerations, workarounds, or follow-up work to note?

  • Use bullet points here

Copilot AI review requested due to automatic review settings February 27, 2026 16:17
@jirhiker jirhiker merged commit 6df9112 into staging Feb 27, 2026
9 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the Cloud SQL connection configuration to prefer IAM DB authentication by default, and removes unused async-related imports.

Changes:

  • Switches CLOUD_SQL_IAM_AUTH default from False to True in both runtime DB engine creation and Alembic migration engine creation.
  • Removes unused imports in db/engine.py (asyncio, async_sessionmaker).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
db/engine.py Removes unused imports and changes Cloud SQL IAM auth default to True for connector-based connections.
alembic/env.py Changes Cloud SQL IAM auth default to True for URL building and online migration connector connections.
Comments suppressed due to low confidence (1)

alembic/env.py:66

  • Defaulting CLOUD_SQL_IAM_AUTH to True changes Alembic’s Cloud SQL URL rendering behavior when the env var is omitted (it will render an IAM-style URL and the online connector path will attempt IAM token auth). Please ensure all migration runners set CLOUD_SQL_IAM_AUTH explicitly, or keep the default False to avoid unexpected failures in password-auth setups.
        password = os.environ.get("CLOUD_SQL_PASSWORD", "")
        database = os.environ.get("CLOUD_SQL_DATABASE", "")
        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}"
        return f"postgresql+pg8000://{user}:{password}@/{database}"

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.
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.
Comment on lines 109 to 113
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")

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.
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants