diff options
| author | Pjotr <wrk@bosa.lan> | 2026-11-06 22:19:19 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-11-06 22:19:19 +0000 |
| commit | 9a6c5f36e4435c3f8dd04b21458e18074310e2fa (patch) | |
| tree | 9b7b2fb454a1f2073869d4de2faf035cd06826e3 | |
| parent | 5c21b0513a26cce220ddfae560a1290e39522106 (diff) | |
| download | genenetwork4-9a6c5f36e4435c3f8dd04b21458e18074310e2fa.tar.gz | |
README: tokens are stateless, and `exp` is the only lifetime
Nothing about a bearer token is kept server side -- no session table, no issued-token list, no denylist -- so restarting genenetwork4 (or the auth server) loses no tokens, and restarting is not a way to revoke them. The two in-process caches (the key set for an hour, authorisation answers for a minute) are refresh intervals, not lifetimes; the hour only bites when the auth server is unreachable, after which every request is a 401 with a JWKS-fetch detail while the tokens themselves are still valid. Also records that `exp` is optional in this validation, so a hand-minted token without one never expires -- which is exactly what the gn-auth dev token mentioned a few paragraphs earlier is doing. * README.md (Development): "Tokens are stateless", plus a note on the gn-auth dev token not carrying `exp`, and the config keys paragraph moved back above the section it belongs to.
| -rw-r--r-- | README.md | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/README.md b/README.md index 6f3f511..f3079d1 100644 --- a/README.md +++ b/README.md @@ -1510,10 +1510,14 @@ a key for 7 days (`JWKS_ROTATION_AGE_DAYS`) and deletes it 14 days after its creation (`JWKS_DELETION_AGE_DAYS`), so a token lasts roughly 7 to 14 days, depending on where in the key's life it was issued. genenetwork4 caches the key set for an hour. When requests start -failing with `401 invalid_token`, fetch a new token. +failing with `401 invalid_token`, fetch a new token. (`exp` is optional +in genenetwork4's own validation, which is why a token without one like +this lives as long as its signing key does -- see "Tokens are +stateless" below.) The test suite uses this same endpoint automatically -- see [Tests](#tests) below. + Configuration is layered: built-in defaults, then `GN4_CONF` and `GN4_SECRETS` files of `KEY=VALUE` lines, then environment variables (which always win). Keys: `SQL_URI` (MariaDB), `GN3_URL` (GeneNetwork3 @@ -1522,6 +1526,51 @@ timeout, default 30), `GENENETWORK4_PORT`, `GENENETWORK4_BIND`, and `GENENETWORK4_TEST_TOKEN` (`false` turns `POST /get-test-token` off; see "Behind nginx or in a container"). +### Tokens are stateless + +Nothing about a bearer token is stored server side: there is no session +table, no list of issued tokens, no `jti` denylist. Verification is +signature + `iss` + `exp`/`nbf`, and that is all, so **restarting +genenetwork4 loses no tokens** -- a token minted before a redeploy keeps +working after it, as does one minted by a stub that has since been +restarted (its key is fixed). What the process does keep is two caches, +and restarting only empties them: + +- the signing keys (`JWKS_TTL`, an hour) -- how long a fetched copy of + the auth server's key set is reused before being re-fetched; +- authorisation answers (`AUTHORISATION_TTL`, a minute), per + `(subject, resource)`. + +Neither is a lifetime. The token's own `exp` is the only thing that ends +its life: it is validated on every request (`validation.validate_exp` in +`src/auth.rs`, with jsonwebtoken's default 60-second leeway), it is never +extended, and there is no refresh token. The hour matters in one case +only: if the auth server is unreachable, a cached key set keeps +verification working for up to `JWKS_TTL`, and past that every request +is `401 invalid_token` with a `fetching .../auth/public-jwks` detail -- +the tokens are still valid, the key lookup is not. Run the auth server +under the same supervision as genenetwork4 rather than from a shell. + +Consequences worth knowing: + +- **Restarting is not revocation.** Since no state exists, restarting + genenetwork4 or the auth server leaves every outstanding token valid. + To withdraw one, wait for its `exp` (hence short lifetimes for tokens + you may need to pull, e.g. `scripts/gn-auth-stub.py --expires-in`). To + withdraw all of them at once, change the signing key or + `AUTH_SERVER_URL` -- `iss` is compared against that string verbatim, + so a changed host, scheme or trailing slash invalidates everything + with `InvalidIssuer`. +- **`exp` is optional.** `required_spec_claims.clear()` means a token + without `exp` is accepted and never expires. gn-auth and + `scripts/gn-auth-stub.py` always set one; a hand-minted token (the + test key is in this repository) that omits it is a permanent + credential. + +Stub-minted tokens behave the same way (see [Tests](#tests)): `exp` is +whatever `--expires-in` said at mint time, and restarting the stub does +not invalidate them -- it always signs with the committed test key. + ## Running with Guix ``` |
