Files
zeekay 45126f763c hanzo_iam: an OAuth validator that admits hanzo-sql tokens
A connection that chooses the oauth method presents a token signed RS256 by
the sql key. Trust is the <kid>.pem public files in hanzo_iam.dir, read on
every connection, so a removed file revokes its key at once; nothing here
calls IAM. The key must be RSA of 2048 bits or more, in a file of at most
16 KiB.

The token is at most 8192 bytes, and each of its three parts decodes into a
buffer with its own capacity, so the size check is not the only bound. iss is
https://hanzo.id, aud holds hanzo-sql, typ is sql (a claim; the JOSE header's
typ is not read), act is absent, sub is sql:<role>, exp and iat are required,
exp is at most 60 s past, iat and nbf (optional) at most 60 s ahead, and
exp - iat is at most 600 s. The claims are not parsed until the signature
verifies. JSON is read with PostgreSQL's jsonapi, escapes decoded, and a
member a check names may appear once however it is spelled.

authn_id is the role, and the connection is authorized only when it equals the
role requested (delegate_ident_mapping=1). A refusal logs one reason from a
fixed list and never names the client's role; a key file that cannot be read
is also named by its path, for the operator.

Built with PGXS against PostgreSQL 18 and copied into the image. The TAP test
signs tokens with keys it makes and checks each refusal by the reason logged:
the size bound at 8192 and 8193 bytes, the key rules (EC, DSA, 1024-bit RSA,
private key, certificate, empty, directory, 16 KiB and over), and JSON escapes
in member names and values. make fuzz builds a libFuzzer target over the
parser, run with -max_len=9500 from seeds on the bound. CI does not run
either; LLM.md says so.

Claude-Session: https://claude.ai/code/session_01SCPMGSQsLNF2YtHFL4bwyp
2026-10-09 10:19:04 -07:00

11 B