about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-10-04 09:20:41 +0000
committerPjotr <wrk@bosa.lan>2026-10-04 09:20:41 +0000
commit0a58bfdbec94d3c249a905226bd33480198f2e95 (patch)
tree1add70a7555473cd464f3e56ad53f8ebbfde60eb
parent6a5f9ef61d19b2a1a3204df223e2ffb21691a988 (diff)
downloadgenenetwork4-0a58bfdbec94d3c249a905226bd33480198f2e95.tar.gz
doc: Update gn-auth.md and RELEASE_NOTES.md for the Rust implementation.
* docs/gn-auth.md: Document the GN2 public>0 AND confidentiality<1
threshold (the test for whether data needs a gn-auth authorization
call at all, versus just a valid token), the now-implemented
src/auth.rs mechanism, and the four gn-auth bugs found and fixed while
building it.
* RELEASE_NOTES.md: Likewise.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
-rw-r--r--RELEASE_NOTES.md34
-rw-r--r--docs/gn-auth.md59
2 files changed, 72 insertions, 21 deletions
diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md
index 08a0cbc..2861f16 100644
--- a/RELEASE_NOTES.md
+++ b/RELEASE_NOTES.md
@@ -15,20 +15,29 @@ gn-auth. Not all endpoints will require a token -- see
   `GET /auth/resource/populations/resource-id/...` followed by
   `POST /auth/resource/authorisation`, mirroring
   `genenetwork3/gn3/api/case_attributes.py`.
-
-### In progress
-
-- A Rust/Axum extractor that verifies a bearer token's JWT signature
-  and standard claims against gn-auth's JWKS, and a caching layer so
-  repeated requests for the same (user, resource) pair don't each cost
-  a round trip to gn-auth.
+- `src/auth.rs`: `AuthToken`, an Axum extractor that verifies a bearer
+  token's RS256 signature and standard time claims against a cached,
+  periodically-refreshed JWKS; `is_publicly_readable(public,
+  confidentiality)`, matching GeneNetwork2's own threshold for whether
+  a dataset needs authorization at all; and `authorise(...)`, wrapping
+  gn-auth's resource-authorization check with a short-lived
+  per-(user, resource) cache. `tests/auth.rs` runs the whole flow
+  (including the cache) against a real gn-auth instance.
+- `jsonwebtoken` (RS256 verification) and `ureq` (gn-auth's HTTP API)
+  as new dependencies; `AUTH_SERVER_URL` as a new `Config` key,
+  matching GeneNetwork3's own config key of the same name.
+
+### Not yet done
+
+- Deciding which existing endpoints should require a token at all, and
+  which gn-auth privilege each should check -- `src/auth.rs` is built
+  and tested end-to-end, but not yet wired into any route.
 
 ### Found and fixed upstream, in gn-auth
 
 While standing up a from-scratch gn-auth instance to test against (no
-prior JWKs/users/sysadmins), three bugs surfaced that would have
-blocked this integration on any fresh gn-auth deployment; see
-gn-auth's own `RELEASE_NOTES.md` for details:
+prior JWKs/users/sysadmins), four bugs surfaced that blocked this
+integration; see gn-auth's own `RELEASE_NOTES.md` for details:
 
 - A freshly-started gn-auth could reject every token for up to 6 hours
   (stale/empty JWKS cache).
@@ -36,5 +45,8 @@ gn-auth's own `RELEASE_NOTES.md` for details:
   authenticate at all (unhashed client secret).
 - `POST /auth/resource/authorisation` -- the endpoint this integration
   depends on -- crashed with a 500 on every fresh deployment.
+- The same endpoint also crashed (instead of degrading to the
+  anonymous view, as it does for a missing token) on an invalid bearer
+  token.
 
-All three are fixed on gn-auth's `fix-fresh-deployment-bugs` branch.
+All four are fixed on gn-auth's `fix-fresh-deployment-bugs` branch.
diff --git a/docs/gn-auth.md b/docs/gn-auth.md
index 42ff910..27bcd88 100644
--- a/docs/gn-auth.md
+++ b/docs/gn-auth.md
@@ -185,14 +185,53 @@ has many more (`/auth/role/...`, `/auth/user/...`,
 genenetwork4 doesn't need to talk to gn-auth for every request -- only
 for the two things above: verifying a presented token's signature
 (cache the JWKS, refresh periodically, don't refetch per-request), and
--- for endpoints that should be scoped to a specific group/species --
-asking gn-auth what that token's holder is allowed to do on that
-resource. Endpoints with no sensitive data behind them don't need to
-call gn-auth at all.
-
-This document describes the mechanism; implementing it in Rust --
-likely a custom Axum extractor that verifies the JWT (e.g. via the
-`jsonwebtoken` or `josekit` crate for RS256) and yields the resolved
-user to handlers that opt in, so endpoints that don't need auth aren't
-forced to go through it -- is still to be done.
+-- for data that isn't public -- asking gn-auth what that token's
+holder is allowed to do on a specific resource. Endpoints with no
+sensitive data behind them don't need to call gn-auth at all.
+
+Whether data "is public" is answered by GeneNetwork's own schema, not
+by asking gn-auth: GeneNetwork2 treats a dataset (`ProbeSetFreeze`,
+`PublishFreeze`, `GenoFreeze`) as public exactly when
+`public > 0 AND confidentiality < 1` (`wqflask/api/router.py`, used
+consistently throughout GN2/GN3). `InbredSet`/group rows carry a
+`public` column too, but GN2 never actually filters on it anywhere --
+it's informational only there -- so groups/species endpoints need no
+gating at all, matching GN2's own behavior. For data that *is* public
+by this test, still require a valid token (don't skip verification
+entirely), but skip the resource-authorization call to gn-auth -- one
+less network round trip for what is, in practice, most of the data.
+
+### Implemented, in `src/auth.rs`
+
+- `AuthToken`, an Axum extractor (`impl FromRequestParts`): verifies a
+  bearer token's RS256 signature and standard time claims (`exp`/`nbf`,
+  checked when present -- gn-auth itself treats them as optional,
+  confirmed against its own validator) against a cached, periodically
+  refreshed JWKS. Add it as a handler parameter to require a valid
+  token; omit it for endpoints that don't need one.
+- `is_publicly_readable(public, confidentiality)`: the GN2 threshold
+  above, as a plain function a handler calls on its own fetched row.
+- `authorise(auth_server_url, token, resource_id, privilege)`: the two
+  gn-auth calls (resource-id resolution is the caller's job --
+  `GET /auth/resource/populations/resource-id/...` -- `authorise`
+  itself only wraps `POST /auth/resource/authorisation`), with the
+  per-(user, resource) answer cached briefly so repeated requests for
+  the same resource by the same user don't each cost a round trip.
+- `tests/auth.rs` runs all of this against a real gn-auth instance
+  (set `GN4_TEST_AUTH_TOKEN`/`GN4_TEST_RESOURCE_ID`; skips otherwise).
+
+Wiring this into specific existing endpoints (which ones should
+require a token at all, and which privilege string each should check)
+is a separate decision, not yet made here.
+
+### Found wrong in gn-auth while building this
+
+Four bugs in gn-auth itself blocked this integration before they were
+fixed (see gn-auth's own `RELEASE_NOTES.md` and its
+`fix-fresh-deployment-bugs` branch): a JWKS cache that could stay empty
+for hours after a fresh deployment's first token was issued, a dev
+client whose secret was never hashed so it could never authenticate,
+`public_resources()` crashing on every fresh deployment, and
+`POST /auth/resource/authorisation` crashing (instead of degrading to
+the anonymous view) on an invalid rather than missing bearer token.