about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-10-05 07:34:26 +0000
committerPjotr <wrk@bosa.lan>2026-10-05 07:34:26 +0000
commit649ff6395bdca06530ceabd3e216c66851dc60d6 (patch)
tree2bbe7008a8258b11ada120315fedff208d230206 /docs
parent693e7ee89f8618c1abbf8af5c0db23b071700803 (diff)
downloadgenenetwork4-649ff6395bdca06530ceabd3e216c66851dc60d6.tar.gz
Rename /dev/token to /get-test-token; require a token everywhere
Rename: POST /dev/token -> POST /get-test-token (src/routes/dev.rs,
TestToken replacing DevToken), matching tests/get_test_token.rs and
test/python/test_get_test_token.py (renamed from
tests/dev_token.rs/test_dev_token.py). Config::dev_token_enabled() and
the GN_AUTH_DEV_* config keys keep their names -- they're about the
dev-token feature generically, not tied to this one route's path.

Every endpoint now requires a valid token, not just the
dataset_probeset*/traits* family: species(_by_name/_datasets),
groups(_by_name/_strains/_traits*/_datasets) and dataset_by_name all
gain an AuthToken parameter. /, /version, /openapi.json and
/get-test-token itself are the only exceptions -- a health check, a
version check, the spec describing all this, and the endpoint that
hands out a token in the first place (which would be circular if it
needed one).

Rather than repeating security(("bearer_token" = [])) on every
#[utoipa::path], ApiDoc now declares it once as the document's default
security(...), and the three exceptions besides /get-test-token (/,
/version) override it with their own empty security() -- standard
OpenAPI semantics (an operation's own security, even empty, overrides
the document default; an absent one inherits it). error::Unauthorized,
a new #[derive(utoipa::IntoResponses)] type wrapping ApiError, is the
shared 401 every gated handler now references bare in its own
responses(...) list instead of writing out the same
(status = 401, description = "...", body = ApiError) tuple by hand.
Verified the resolved security per operation in a live /openapi.json.

tests/common::auth_token() (Rust) and the new
test/python/auth_helpers.auth_token() (Python, deduplicating what four
files previously each defined locally) now try this server's own
POST /get-test-token first, falling back to GN4_TEST_AUTH_TOKEN --
every previously-ungated test file gains a token check and switches to
get_with_token; the whole suite, both languages, now runs with zero
manually-provisioned tokens given GENENETWORK4_DEV_MODE=true
GENENETWORK4_BIND=127.0.0.1 for the test run. ServerTestCase gains
EXTRA_ENV so each Python test class can start its own server with dev
mode on. Verified both configured (auto-fetch) and unconfigured
(GN4_TEST_AUTH_TOKEN fallback, and full skip when neither is set, e.g.
the Guix build sandbox) paths.

README.md, docs/gn-auth.md and RELEASE_NOTES.md updated throughout for
the rename and the new blanket token requirement.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XDDpXvZBQat9uSgDeEMJ8d
Diffstat (limited to 'docs')
-rw-r--r--docs/gn-auth.md87
1 files changed, 63 insertions, 24 deletions
diff --git a/docs/gn-auth.md b/docs/gn-auth.md
index b07c2a9..c033d5d 100644
--- a/docs/gn-auth.md
+++ b/docs/gn-auth.md
@@ -186,18 +186,21 @@ 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 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
+holder is allowed to do on a specific resource. Every endpoint needs
+the first (see "Every endpoint requires a token" below); only some
+need the second.
+
+Whether data "is public" (and so skips the second, resource-level
+check) 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 *resource-level* gating, matching
+GN2's own behavior; they still need a valid token like every endpoint
+does. For dataset/trait data that *is* public by the threshold above,
+likewise 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.
 
@@ -276,8 +279,10 @@ probeset in the list):
   against a real gn-auth instance.
 
 `GET /groups/{group}/traits` and its singular siblings (Publish/
-phenotype data) aren't gated at all yet -- that's a separate, not yet
-made decision, same as every other endpoint outside this family.
+phenotype data) require a token like every endpoint now (see "Every
+endpoint requires a token" below) but don't check any further
+resource-level authorization -- that remains a separate, not yet made
+decision, same as every endpoint outside this family and `/traits`.
 
 ### Wired into routes: `/traits/{dataset}/...`, spanning both categories
 
@@ -297,20 +302,45 @@ dataset names to `gn_auth/auth/authorisation/data/phenotypes.py`'s
 integration already relies on, so no gn-auth-side change was needed to
 extend gating to phenotype data through this endpoint.
 
-This is new protection for Publish data reached this way: `/traits/
-{group}` now requires a token even though `/groups/{group}/traits`
-(unchanged) still doesn't. No non-public `PublishFreeze` exists in the
-database this was tested against, so the deny path for the Publish
-branch specifically wasn't exercised against real data -- only against
-the already-proven ProbeSet branch and gn-auth's own "unlinked dataset"
-404-to-deny behavior, which this new branch calls unchanged.
-
-### Getting a token for local testing: `POST /dev/token`
+No non-public `PublishFreeze` exists in the database this was tested
+against, so the deny path for the Publish branch specifically wasn't
+exercised against real data -- only against the already-proven
+ProbeSet branch and gn-auth's own "unlinked dataset" 404-to-deny
+behavior, which this new branch calls unchanged.
+
+### Every endpoint requires a token
+
+Everything above was about *authorization* (is this specific resource
+public, does this user have a privilege on it) for the handful of
+endpoints that check it. Separately, and more broadly: every endpoint
+in this API now requires a valid token (`AuthToken`, checked by local
+JWKS signature verification as described above) just to be called at
+all -- `/`, `/version`, `/openapi.json` and `/get-test-token` itself
+are the only exceptions (a health check, a version check, the spec
+describing all this, and the endpoint that hands out a token in the
+first place would be circular if it needed one). This is a blanket
+requirement independent of whether an endpoint also checks
+resource-level authorization: `/species`, `/groups/{group}/strains`,
+`/datasets/{dataset}` and the like need a token now but don't check
+anything beyond that it's valid -- same as a `is_publicly_readable`
+dataset in the `dataset_probeset*`/`traits*` family skips the
+authorization call but still needs a valid token.
+
+`ApiDoc`'s `#[openapi(security(("bearer_token" = [])), ...)]`
+(`src/lib.rs`) makes this the OpenAPI document's default security
+requirement, so individual handlers don't each repeat `security(...)`;
+the three exceptions besides `/get-test-token` (`/`, `/version`)
+override it with their own empty `security()`. `error::Unauthorized` (a
+`#[derive(utoipa::IntoResponses)]` type wrapping `ApiError`) is the
+shared 401 response every gated handler references by name in its own
+`responses(...)` list instead of writing out the same tuple by hand.
+
+### Getting a token for local testing: `POST /get-test-token`
 
 Every live test in this repo (`tests/*.rs`, `test/python/test_*.py`)
 needs a real bearer token, obtained by hand so far (e.g.
 `test-token2.txt` in the setup notes). genenetwork4 can hand one out
-itself now: `POST /dev/token` (`src/routes/dev.rs`) calls gn-auth's own
+itself now: `POST /get-test-token` (`src/routes/dev.rs`) calls gn-auth's own
 password grant for gn-auth's well-known development user
 (`test@development.user`, from `flask init-dev-clients`/
 `gn_auth/wsgi.py`) and returns the result. See the README's
@@ -324,6 +354,15 @@ authorizes tokens (src/auth.rs) -- it is purely a convenience for
 obtaining one of the tokens that mechanism already accepts, scoped to
 local development by two independent config checks rather than one.
 
+The test suite uses it automatically: `tests/common::auth_token()`
+(Rust) and `test/python/auth_helpers.auth_token()` (Python) both try
+`POST /get-test-token` first, falling back to a `GN4_TEST_AUTH_TOKEN`
+env var only if that fails. Set `GENENETWORK4_DEV_MODE=true` and
+`GENENETWORK4_BIND=127.0.0.1` for the test run (plus a reachable
+gn-auth with `AUTHLIB_INSECURE_TRANSPORT` set) and the whole suite --
+every endpoint now needing a token -- runs with no token manually
+provisioned at all.
+
 ### Found wrong in gn-auth while building this
 
 Four bugs in gn-auth itself blocked this integration before they were