postgres_cdc: refresh IAM auth token for each new connection - #4710
Open
ReguiguiMohamed wants to merge 1 commit into
Open
postgres_cdc: refresh IAM auth token for each new connection#4710ReguiguiMohamed wants to merge 1 commit into
ReguiguiMohamed wants to merge 1 commit into
Conversation
openPgConnectionFromConfig copied the password into a fresh pgconn.Config when the pool was built, so the heartbeat, monitor, snapshotter and server-version check all kept authenticating with the token captured at startup. Once that token expired the heartbeat write failed on every tick for the rest of the pipeline's life, while the replication stream stayed healthy. Rebuild the password through the existing Config.RefreshAuthToken from a BeforeConnect hook, which pgx runs before it opens each physical connection. Fixes redpanda-data#4668
ReguiguiMohamed
force-pushed
the
fix/postgres-cdc-heartbeat-iam-token-refresh
branch
from
August 18, 2026 17:15
dd280ce to
7ffd850
Compare
Contributor
|
Thanks for looking into this, I'll take a look shortly |
Author
hey @josephwoodward i'm truly honoured to contribute, will be here awaiting any fixes or updates to my PR in realtime or monitor and add anything |
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.
Fixes #4668.
openPgConnectionFromConfigcopiescfg.DBConfig.Passwordinto a freshpgconn.Configand hands that tostdlib.OpenDB. The value is a snapshot, so every physical connection the returned*sql.DBopens later still authenticates with the token that existed when the pool was built. Withaws.enabled: truethe IAM token lasts around 15 minutes, after which the heartbeat write fails on every tick for the rest of the pipeline's life, while the replication stream stays healthy.Config.RefreshAuthTokenalready exists for this, and is whatConnectcalls for the main connection. This passes it to pgx'sBeforeConnecthook, which runs before each new physical connection and hands over the config that is about to be used, so the password gets rebuilt at the point a connection actually needs one. The heartbeat, monitor, snapshotter and server-version check all open through this helper, so this covers all four.The refresh writes to the shared
Config.DBConfigand the hook reads it straight back, and pools open connections from separate goroutines, so a mutex guards that pair.Testing
connection_test.goexercises the hook without a database. Nothing listens on the port in the DSN, andBeforeConnectruns before the dial, so a refused connection still runs it. The tests check that the token is rebuilt on every connection attempt, that a failing refresh surfaces to the caller, and that a config withoutRefreshAuthTokenis left alone.Against the current code the first two fail, reporting 0 refreshes and the startup password still in place.
I left
CHANGELOG.mdalone since release notes look to be generated from PR titles at release time. Glad to add an entry if you'd prefer one.