Skip to content

feat: identity-aware AuthSource with delegated password verification - #474

Merged
sunng87 merged 3 commits into
masterfrom
feat/authsource-identity
Oct 20, 2026
Merged

sunng87 merged 3 commits into
masterfrom
feat/authsource-identity

Conversation

@sunng87

@sunng87 sunng87 commented Oct 17, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to #473, motivated by the GreptimeDB adoption: their custom
auth mechanisms (PgCleartextMechanism + PasswordVerifier) existed
only because AuthSource could fetch passwords for comparison
while their user store verifies (hashed storage, bearer tokens) and
resolves the principal.

Changes

AuthSource<I = ()> — identity type parameter, defaulting to () so
existing implementations are unchanged:

  • verify_password(login, presented_password) -> PgWireResult<Option<I>> — delegates verification to the source
    and returns the authenticated identity. Default: compare against
    get_password, report no identity — so password-store sources keep
    their one-method implementations.
  • get_scram_secret returns (ScramSecret, Option<I>) — the
    identity resolved alongside the credential (e.g. the user a
    verifier belongs to; None for mock verifiers of unknown users).

The built-in cleartext and SCRAM mechanisms call these and report the
identity through AuthOutcome::Completed, statically typed via the
mechanism identity parameter from #473. ScramAuth<I> construction
and the cleartext factory are generic accordingly.

For GreptimeDB this reduces to one AuthSource<UserInfoRef>
implementation wrapping their user provider (verify_password /
get_scram_secret map 1:1 to authenticate_password /
postgres_auth_info), the built-in mechanisms, and a handler matching
AuthOutcome::Completed(Some(user)).

Authorization is deliberately not part of this API: policy does not
belong on the authentication source. Run it in the startup handler on
AuthOutcome::Completed (send an ErrorResponse and close on
failure), or wrap the mechanism when the rejection must precede
AuthenticationOk.

Tests

  • cleartext: verify_password-returning source →
    Completed(Some(identity))
  • SCRAM: identity returned with the verifier →
    Completed(Some(identity))
  • default verify_password comparison path covered by existing
    cleartext tests

Design notes

The identity is carried as Option<I> rather than bare I because
the default method implementations (comparison-based verification,
salted-password derivation) verify successfully without resolving a
principal — there is no I they could return. Sources with
conditional identity resolution (mock verifiers for unknown users)
report None alongside a real credential.

…ooks

AuthSource gains an identity type parameter (default ()):
- verify_password(login, presented): delegates password verification
  to the source and returns the authenticated identity; the default
  implementation compares against get_password
- get_scram_secret returns the identity alongside the credential
- authorize(login, identity): runs after successful verification,
  before the handshake completes (default: allow)

The cleartext and SCRAM mechanisms call these hooks and report the
identity through AuthOutcome::Completed, so deployments whose user
store verifies passwords itself and resolves principals (hashed
storage, bearer tokens) no longer need custom mechanisms for
verification, identity capture or authorization.
Authorization policy does not belong on the authentication source;
deployments that need post-verification authorization can run it in
their startup handler on AuthOutcome::Completed (sending an
ErrorResponse and closing on failure), or wrap the mechanism when the
rejection must precede AuthenticationOk.
@sunng87 sunng87 changed the title feat: identity-aware AuthSource with verification and authorization hooks feat: identity-aware AuthSource with delegated password verification Oct 17, 2026
@sunng87
sunng87 force-pushed the feat/authsource-identity branch from 383dc44 to ad27451 Compare October 18, 2026 14:31
@sunng87
sunng87 merged commit ea06997 into master Oct 20, 2026
11 checks passed
@sunng87
sunng87 deleted the feat/authsource-identity branch October 20, 2026 08:17
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.

1 participant