latent.serve.auth¶
Application-layer per-request HMAC mutual auth for /stream (ADR-009 D1).
The signature scheme — :func:sign, :func:verify, :func:request_target, the
header names and :class:InMemoryNonceStore — is studio_contracts.signing,
the one Python implementation Studio's signer and every pod's verifier share;
vectors/hmac.json in the same package holds it and the TypeScript signer to
the same bytes. What stays here is the part that reads latent's configuration:
:func:require_secure_studio_url and :func:build_nonce_store.
Functions¶
build_nonce_store¶
Build the replay-guard store from config.
Returns a :class:~latent.serve.nonce_studio.StudioNonceStore when the studio
is configured (an agent-studio URL and key are present — the same credential
the registration client uses) — cluster-wide replay protection over Postgres
via the studio nonce route — otherwise the per-process
:class:InMemoryNonceStore for standalone/dev/single-pod serving. The studio
store and its httpx/workspace deps are imported lazily, so a caller that
only signs or verifies never loads latent's configuration.
require_secure_studio_url¶
Reject a studio config that would send a bad credential.
Both the register call (POSTs the HMAC secret K) and the nonce route (POSTs
the project key) send a secret to the studio, so an empty key is refused (it
would send Authorization: Bearer None). The URL scheme is intentionally
unconstrained: a deployed pod reaches the studio over cluster-internal http
(a ClusterIP that never leaves the node — the same way the runtime worker
POSTs its key), while a dev tunnel uses https. Raises :class:ValueError on
an empty key.