Skip to content

feat: extend passthrough auth to mirror destinations#1233

Open
lalvania wants to merge 1 commit into
pgdogdev:mainfrom
lalvania:feat/mirror-passthrough-auth
Open

feat: extend passthrough auth to mirror destinations#1233
lalvania wants to merge 1 commit into
pgdogdev:mainfrom
lalvania:feat/mirror-passthrough-auth

Conversation

@lalvania

Copy link
Copy Markdown

Closes #1189 — Support Mirrors with pass through auth.

from_config only provisions a mirror pool when the source and destination databases have matching [[users]] name sets. Passthrough only writes a [[users]] entry for the source side, so mirroring stays disabled. This patch also writes a matching entry for each mirror destination when passthrough runs, unlocking the name-match check. Any pre-existing destination entry is left alone.

Rollout notes

For operators upgrading with a valid users.toml:

  • No schema change — drop-in binary replacement, no pgdog.toml or users.toml edits required.
  • Login for any (name, database) already in users.toml with a matching password is a zero-write, zero-reload no-op. Indistinguishable from pre-patch.
  • The new code path only fires for a passthrough login whose (name, database) isn't in users.toml. If you have no [[mirroring]] blocks it's dormant regardless.
  • The existing mirroring disabled ... users don't match warning should decrease (never increase) after upgrade. Increase = regression signal.
  • Under enabled_allow_change, source-side rotation is unchanged. The mirror record is no longer rotated in lockstep — matters only if your mirror Postgres password is being rotated in sync with the source externally.

Open questions

Three things worth calling out that I didn't want to decide unilaterally:

  1. Should [[mirroring]] only speak in [[databases]]? Should it care about user / authentication, or only that the source / target exists within [[databases]]? Or is this for establishing authentication?

  2. Should [[users]] be server-side authentication only, while [[databases]] handles client-side auth only? Today [[users]] does both — name/password gate the client, and the same fields (or server_* overrides) get used for pgdog → Postgres. A cleaner split might make this feature — and mirroring in general — less bolted-on.

  3. Should the ~1350-line inline mod tests in databases.rs be extracted to a sibling file? The new tests join it in the same style. Thoughts on extracting this to a sibling crate like diesel's diesel_tests/?

@CLAassistant

CLAassistant commented Jul 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

When passthrough_auth adds a user record for the source database, also add
the same user for every mirror destination whose source_db matches, so
from_config's name-based source_users == dest_users check passes and the
mirror pool is provisioned with the client-supplied password.

Never overwrites an existing destination record — the operator may have
deliberately configured per-side credentials. Only grace-fills entries
whose password was left unset, matching the source-side add() behaviour.

Adds integration/mirror/passthrough/ that plugs into the existing bare-metal
mirror harness (integration/setup.sh provisions pgdog/pgdog1; run_pgdog
picks up the subdir).

Closes pgdogdev#1189
@lalvania
lalvania force-pushed the feat/mirror-passthrough-auth branch from e728b00 to af2b47d Compare July 18, 2026 02:19
);

{
let _lock = lock();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you may want to take that lock a little earlier - when you get the config on line 232.

@codecov

codecov Bot commented Jul 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.88889% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/backend/databases.rs 98.88% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

[Mirroring] Dynamic pool creation with passthrough auth

3 participants