Conversation
Code review comments addressed: - Respect the IP settings in connection configuration (self._ip_type) rather than probing all available IPs - Use SERVER_PROXY_PORT constant (3307) - Use DEFAULT_CONNECT_TIMEOUT constant (30) / configured timeout
…n LazyRefreshCache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Supersedes / extends #1467 to ensure proactive IAM refresh probes actually update the cached IAM access token in Managed Connection Pooling (MCP) PgBouncer for long-lived persistent connections (
GoogleCloudPlatform/cloud-sql-proxy#2553).Why a TLS-only probe is insufficient
When Managed Connection Pooling (PgBouncer) accepts a TLS connection on port
3307:SBUF_EV_TLS_READY,AutoIAMInit(sbuf)extracts the IAM access token from the ephemeral X.509 certificate extension and stores it in the per-socketclient->auto_iam_login_user_credentials->passwd(client->dbandclient->login_user_credentialsare stillNULLbecause the X.509 client certificate does not contain the PostgreSQLdatabaseoruser).client->auto_iam_login_user_credentials->passwdinto the shared pool'sclient->login_user_credentials->passwd(db->user_tree, which is keyed per(database, username)) insidefinish_set_pool(), which is reached only after reading a PostgreSQL v3StartupMessage(PKT_STARTUP_V3->decide_startup_pool->set_pool(client, dbname, username, ...)).StartupMessage, PgBouncer freesclient->auto_iam_login_user_credentialson disconnect without ever updatingpool->user_credentials->passwd, causing idle persistent connections to fail after ~1 hour once the initial IAM token expires.What this PR changes
@abc.abstractmethod def record_principal(self, user: str, database: str) -> NonetoConnectionInfoCache(RefreshAheadCache,LazyRefreshCache, andMonitoredCache).(user, db)pair inConnector.connect_asyncwhenenable_iam_auth=True._probe_instance_connection(shared byRefreshAheadCacheandLazyRefreshCache) to send a PostgreSQL v3StartupMessage([int32 length][int32 196608]["user\0<user>\0database\0<database>\0\0"]) for each recorded(user, database)pair over the TLS probe connection, read the initial server authentication response, and send a clean PostgreSQLTerminatepacket ('X') before closing.