Repository navigation
feat(auth)!: split auth, roles and claims config; strict config - #83
Merged
Merged
Conversation
Identity configuration is now three shared confx sections: auth (mode, jwt, headers, mint_type), roles (switch, anonymous, default, allowed) and claims (prefix, json_setting). The rls section is gone. auth: typed Mode, New returns an error for unknown modes, a jwt mode without a key and a headers mode without trusted proxies (headers mode no longer trusts every peer). The Bearer scheme is case-insensitive, an optional leeway covers clock skew, the role claim is a path (app_metadata.role, realm_access.roles[0]) and must be a string, and an empty anonymous role refuses requests without credentials with ErrAuthRequired. Challenge gives the WWW-Authenticate value. SkipRoleSwitch replaces the old Enabled flag: credentials are always verified. pgexec: the default claims namespace moves out of pgexec; an empty ClaimsPrefix sets no per-claim settings, and ClaimsJSONSetting exposes every claim as one JSON setting (request.jwt.claims). SQLSTATE class 21 is user input instead of internal. The test fixture's policies read jwt.claims. confx: Load rejects unknown keys in the file and in environment variables of known sections, naming the key they moved to or the closest valid key; values decode with weak typing into typed plugin settings (Plugins[S]). ValidateLog checks log.format, ValidatePluginNames checks plugins.disabled, and JWT.secret_file reads the HMAC secret from a file. httpx: CORS takes a CORSPolicy with exposed headers, and CORS and gzip add to Vary instead of replacing it. BREAKING CHANGE: confx.RLS, confx.Auth's flat fields, auth.Config.Enabled, auth.New's signature, pgexec.DefaultClaimsPrefix, the CORS function signatures and confx.Plugins' map settings change; unknown config keys are errors.
archlemon
force-pushed
the
feat/v1-auth-config
branch
from
November 23, 2026 21:30
58d7213 to
1f08514
Compare
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.
Pre-1.0 config and security contract changes (readiness review B1, B2, B3) plus the shared bugs, in the engine. pdbq and pdbr follow in their own PRs against this commit.
Changelog
Breaking
confx): therlssection is replaced byauth,rolesandclaims(shape below).rls.enabled: falseno longer turns authentication off;roles.switch: falseruns requests as the connection role while credentials are still verified and claims still set.auth):auth.Newnow returns(*Authenticator, error)and rejects an unknown mode, a jwt mode without a secret or JWKS URL, and a headers mode without trusted proxies (an emptyTrustedProxiesno longer trusts every peer).auth.Modeis a typed string (ModeJWT,ModeHeaders,ModeNone).Config.Enabledis gone;SkipRoleSwitchreplaces it.AnonymousRolerefuses requests without credentials withErrAuthRequired(products answer 401 withWWW-Authenticate, seeauth.Challenge). A credential that resolves to no role at all is refused withErrRoleNotAllowed; a role claim that is not a non-empty string isErrInvalidToken(it used to fall back to the default role).pgexec):DefaultClaimsPrefixis removed from pgexec;confx.DefaultClaimsPrefixisjwt.claims(PostGraphile's namespace). An emptyIdentity.ClaimsPrefixnow sets no per-claim settings instead of defaulting. The test fixture's policies readjwt.claims.user_id.confx.Load): unknown keys in the YAML file are errors; so are environment variables with the product prefix whose first segment names (or nearly names) a config section. Messages name the key a removed key moved to (MovedKeys,WithMoved) or the closest valid key. Variables outside the config sections (PDBQ_TEST_DATABASE_URL) are ignored.confx.Pluginsis generic,Plugins[S], with the product's typed settings struct instead ofmap[string]map[string]any.httpx):CORS,PreflightandCORSWithPreflighttake aCORSPolicy{Origins, AllowMethods, ExposeHeaders}.confx.ValidateRLS→ValidateIdentity(Auth, Roles, Claims);confx.AuthConfig(RLS)→AuthConfig(Auth, Roles) (auth.Config, error).Added
auth: case-insensitiveBearerscheme;Leeway;RoleClaimPath(app_metadata.role,realm_access.roles[0],"https://example.com/role") andValidateClaimPath;HeaderRoleClaim;ErrAuthRequired;Challenge(err)forWWW-Authenticate;ParseMode.pgexec:Identity.ClaimsJSONSettingsets every claim as one JSON object ({}without claims), e.g.request.jwt.claims, so PostgREST/Supabase policies port unchanged;ValidateClaimsSetting.confx:auth.jwt.secret_file(JWT.ResolveSecret),auth.jwt.leeway,auth.jwt.role_claim_path,auth.headers.role_claim,claims.json_setting;DefaultAuth,DefaultRoles,DefaultClaims;IdentityWarnings;ValidatePluginNames(did-you-mean);ValidateLogcheckslog.format.httpx:CORSPolicy.ExposeHeaders(Access-Control-Expose-Headers),AddVary.Fixed
Vary: Accept-Encoding; it addsVary: Originto every response (and the request-method/headers to preflights), and gzip adds rather than appends blindly.ON CONFLICT DO UPDATE command cannot affect row a second time, a scalar subquery returning several rows) is user input with its message passed through in prod, instead of an internal error.Shared config migration (both products)
rls.enabled: trueroles.switch: truerls.enabled: falseroles.switch: falseauth.mode: nonerls.anonymous_role(defaultanonymous)roles.anonymous(default empty)rls.default_roleroles.defaultrls.allowed_rolesroles.allowedrls.role_claimauth.jwt.role_claim_path/auth.headers.role_claimrls.claims_prefix(defaultpdbq.claims)claims.prefix(defaultjwt.claims)claims.prefix: pdbq.claimsto keep old policies, or update themclaims.json_settingrequest.jwt.claimsrls.auth.modeauth.moderls.auth.jwt_secretauth.jwt.secretauth.jwt.secret_filerls.auth.jwks_urlauth.jwt.jwks_urlrls.auth.jwks_cache_ttlauth.jwt.jwks_cache_ttlrls.auth.jwt_issuerauth.jwt.issuerrls.auth.jwt_audienceauth.jwt.audienceauth.jwt.leeway0srls.auth.header_prefixauth.headers.prefixrls.auth.header_claimsauth.headers.claimsrls.auth.trusted_proxiesauth.headers.trusted_proxiesrls.auth.jwt_typeauth.mint_typelog.format: <anything>log.format: textorjsonNew config shape:
The same table and the Go API changes are in
docs/upgrading.md("0.x → 1.0", a section next to the catalog format 10 notes).The claim header prefix stays per product (
X-Pdbq-Claim-/X-Pdbr-Claim-): names SQL sees are product-neutral so policies port; names on the wire between a gateway and the server are product-namespaced like every other product header (README).Closes #76
Closes #77
Closes #78
Closes #80
Not in this PR: the B13 overload-order item listed in #80 (catalog work), B6's pdbr
base_path/etags/schema-endpoint defaults (later phases); the statement-timeout default lives in the products.Tests
go test -race ./...,go vet,golangci-lint(0 issues), actlint-test.testutil pgexec watch introspect postgis contrib metrics cache) on fresh postgis/postgis:18-3.7 and 14-3.7: pass, including a new policy test readingcurrent_setting('request.jwt.claims', true)::json->>'sub'throughRunTxandQueryTx.Newerrors, anonymous refusal and challenges, case-insensitive Bearer, leeway, role claim paths,SkipRoleSwitch; strict loading (moved keys, did-you-mean for file and env, ignored unrelated env, list entries, map keys), env decoding into typed plugin settings; CORS expose headers and Vary composition; JSON claims setting.FuzzClaimPath(10s, 4 workers) clean.