Establish exact PostgreSQL identities and notification lifecycle - #1754
Draft
Zetazzz wants to merge 5 commits into
Draft
Establish exact PostgreSQL identities and notification lifecycle#1754Zetazzz wants to merge 5 commits into
Zetazzz wants to merge 5 commits into
Conversation
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
Implements planning items F01 and F12 as one PostgreSQL trust-boundary change:
F12 is included with F01 because the notification broker is the first long-lived consumer of exact pool identity and leases. This PR is stacked on #1752 and preserves its default TCP checkout sanitation contract.
Planning issue: https://github.com/constructive-io/constructive-planning/issues/1693
Architecture and behavior
Exact identities and leases
Pool identity includes driver generation, host, port, database, login credential, complete serializable TLS contract, pool policy, connection purpose, and checkout contract. The identity is an opaque process-local HMAC, so cache keys and diagnostics do not expose connection URLs or provide a portable password verifier.
acquirePgPoolreturns an exact identity, pool, and idempotent release claim. Leased pools are not eligible for LRU/TTL eviction. Admission fails closed when capacity cannot be reclaimed safely, and teardown waits for all detached pool disposal work.The compatibility
getPgPoolAPI remains available. Database-name cleanup aliases are retained for existing code-generation and Graphile cleanup callers during the migration to opaque identities.Optional runtime credentials
The configuration contract now supports a static runtime login bound to an exact route identity, or a resolver that receives only frozen, credential-free route facts. Returned credentials must explicitly include database, user, and password; the database must match the routed physical database. Resolver/configuration failures never fall back to the control credential.
When neither runtime path is configured, the existing single-login behavior remains unchanged. Request-owned runtime and control pool leases are released idempotently on finish, close, abort, and partial acquisition failure.
Notification role and broker
The notification broker exposes exact broker and physical database target identities, frozen exact topic allowlists, per-topic subscription, an observed
terminatedpromise, role revalidation, and idempotent awaited release.Topic validation rejects empty, NUL-containing, malformed surrogate, and over-63-byte PostgreSQL identifiers without Unicode normalization. Subscriber queues are bounded; an overflow terminates only the slow subscriber. Fatal listener failures are latched and delivered to all owners without silent reconnect.
The dedicated listener login is audited on the same pinned client before
LISTEN. The audit checks exact session/current user/database identity, login and NOINHERIT posture, prohibited role attributes and memberships, database ownership/privileges, and application schema/relation/function/sequence privileges. Audit results are frozen and credential-free.Topic ownership is reference counted. Final release waits for
UNLISTEN, destroys uncertain clients, releases the pool lease, and aggregates cleanup failures while still attempting remaining cleanup.#1752 compatibility
DISCARD ALLcheckout sanitizer exactly once.Explicit exclusions
This is lower-level infrastructure only. It does not enable shared realtime or wire notification credentials into GraphQL/server middleware. It excludes F05, F18, F21, F22, F24, F25, F26, and F44, plus scoped introspection, build-state retirement, Graphile cache governance, and pg-many-to-many changes.
Validation
pnpm install --frozen-lockfilegit diff --checkLint has one pre-existing unrelated warning in
packages/express-context/src/loaders/identity-providers.ts(moduleNameis unused); there are no lint errors.pnpm policy:checkis currently blocked only by repository-wide expired exceptions unrelated to this diff:@typescript-eslint/eslint-pluginand@typescript-eslint/parser(2026-08-17), and@types/semver(2026-08-16). This PR does not change those dependencies.Remaining integration and risk