Watch
0
0
Fork
You've already forked hyperhive
0

swarm-nats-auth: fix four doc comments, and record why the request goes unchecked

- request.rs pointed at module docs on main.rs for why the request signature
  is not verified; they said nothing. It now says why, here and in
  docs/4-implementation/swarm/credentials.md ("What authenticates a callout
  request"), and so do xkey::open and main.rs's module docs: only the
  responder's own key can publish to the request subject, a forger with a
  valid bearer gets what a normal connect gets, and nats-server makes a new
  xkey at each start and has no option to set it, so there is no key to pin.
  The guard is the module-eval case "the callout account has exactly one member
  and no system account is configured"; the docs say to revisit this if that
  changes.
- request.rs said base64url is written out rather than pulled in; it calls
  data_encoding, a direct dependency.
- respond.rs said `now` is injected into sign(); sign() takes no clock.
- oidc_secret.rs named swarm-bao.nix for natsAuthReaders; it is in
  swarm-bao-readers.nix.
This commit is contained in:
maia 2026-11-30 14:40:25 +01:00 • committed by mara
commit 31274ebf7f

View file

@ -142,6 +142,25 @@ the create that makes a new key. No principal hyperhive configures may
delete either path's metadata, so run the two deletes with a token that may,
such as the root token.
## What authenticates a callout request
The responder never reads the signature segment of the request JWT.
`request::decode` splits the three segments and decodes the claims, and
nothing checks the third. The responder takes a request as the server's when
it opens: the server seals the request (a curve25519 box) to the callout
xkey, and the `Nats-Server-Xkey` header carries the key it sealed with. The
responder uses that key as sent, compares it with no key it holds, and seals
the reply back to it. A request without the header, or one that doesn't open,
gets no reply.
The signature and the sender key stay unchecked on purpose, for three reasons.
- Only the responder's own key can publish to `$SYS.REQ.USER.AUTH`. It's the one member of the callout account (`AUTH`) and the one `auth_users` bypass in `swarm-nats.nix`. The server has no system account, and no account shares anything with `AUTH`. Whoever holds that seed can already read the issuer seed and mint any user JWT, so a forged request gives them nothing new.
- A forger with a valid bearer gets what a normal connect gets: the responder decides the permissions from the bearer inside the request.
- Pinning has no key to pin. `nats-server` 2.14.4 makes a new random nkey and xkey at each start and has no option to set either, so the responder holds no server key to compare the header with. Under FIPS mode the server makes no xkey, so no header arrives and the responder refuses the request.
The guard is the module-eval case `the callout account has exactly one member and no system account is configured` in `nix/module-eval/nats-authelia.nix`. An extra member of `AUTH` could subscribe to the subject and read every client's token, which no signature check would stop. Revisit this decision if that case changes: when `AUTH` gains a member, or the server gets a system account.
## Per-principal identities
Bao matches a cert-auth role on the certificate's subject, so a certificate is an