about summary refs log tree commit diff
path: root/docs
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-10-04 11:37:55 +0000
committerPjotr <wrk@bosa.lan>2026-10-04 11:37:55 +0000
commit859a86bf39df6eafa6988215cb84556fc9623ea0 (patch)
treee31e62d0d891dce85be8a09d5094d9d8f06cf7e0 /docs
parent0a58bfdbec94d3c249a905226bd33480198f2e95 (diff)
downloadgenenetwork4-859a86bf39df6eafa6988215cb84556fc9623ea0.tar.gz
Gate GET /datasets/{dataset}/probesets/{probeset} on gn-auth
Require a valid gn-auth bearer token on this endpoint unconditionally.
For a dataset that isn't publicly readable, check the
group:resource:view-resource privilege via a new auth::authorise_trait,
the "Dataset::Trait"-keyed equivalent of authorise (POST
/auth/data/authorisation instead of /auth/resource/authorisation) --
gn-auth resolves the resource itself from the dataset name, so no
separate resource-id lookup is needed here. A trait never linked to a
gn-auth resource (gn-auth answers 404) is treated as "no privileges",
not a request failure. Denied requests get a 403; a failure to
reach/parse gn-auth's answer gets a 502, distinct from both that and
this service's own 500s.

is_publicly_readable now also takes the dataset's CreateTime and treats
anything older than 5 years as public regardless of its
public/confidentiality flags -- a confidentiality embargo isn't meant
to last forever. No admin/sysadmin bypass is implemented.

Register a "bearer_token" OpenAPI security scheme (src/lib.rs) so the
new security(...) annotation on this endpoint's #[utoipa::path] has
something to point at.

tests/dataset_probeset_info.rs and its Python mirror gain cases for the
missing-token (401) and denied-but-existing (403) outcomes, run against
a real gn-auth instance set up as described in docs/gn-auth.md; the
403 case uses UTHSC_BXD_Cochlea_0225, a real non-public, non-embargoed
dataset never linked into gn-auth. tests/common gains get_with_token
and auth_server_available/auth_token helpers for this.

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.md53
1 files changed, 48 insertions, 5 deletions
diff --git a/docs/gn-auth.md b/docs/gn-auth.md
index 27bcd88..c33dc54 100644
--- a/docs/gn-auth.md
+++ b/docs/gn-auth.md
@@ -201,6 +201,27 @@ 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.
 
+A dataset older than 5 years is treated as public too, regardless of
+its `public`/`confidentiality` flags -- a confidentiality embargo isn't
+meant to last forever. This isn't a GN2 convention, just a rule applied
+here, based on `CreateTime`.
+
+### Resolving a probeset/trait to a gn-auth resource
+
+A group/`InbredSet` resource's id is resolved via
+`GET /auth/resource/populations/resource-id/<speciesid>/<inbredsetid>`
+(above). A probeset/trait doesn't have an equivalent "resolve this id
+to a resource id" endpoint -- instead, call
+`POST /auth/data/authorisation` directly with a `"Dataset::Trait"`
+string (e.g. `{"traits": ["HC_M2_0606_P::1442370_at"]}`); gn-auth
+resolves the resource itself, internally, via a join on
+`linked_mrna_data.dataset_name` (`gn_auth/auth/authorisation/data/
+mrna.py`'s `resources_by_datasets_and_traits`). If the trait's dataset
+was never linked to a gn-auth resource at all (the common case for
+data nobody has ever restricted), gn-auth answers with a 404, which
+genenetwork4 treats the same as "no privileges" -- not a request
+failure.
+
 ### Implemented, in `src/auth.rs`
 
 - `AuthToken`, an Axum extractor (`impl FromRequestParts`): verifies a
@@ -209,20 +230,42 @@ less network round trip for what is, in practice, most of the data.
   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.
+- `is_publicly_readable(public, confidentiality, create_time)`: the GN2
+  threshold above, plus the 5-year embargo-age rule, 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.
+- `authorise_trait(auth_server_url, token, dataset_name, trait_name,
+  privilege)`: the trait-keyed equivalent of `authorise`, wrapping
+  `POST /auth/data/authorisation` -- for data addressed by a
+  `(dataset, probeset)` pair rather than a resource id directly. Same
+  caching as `authorise`.
 - `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.
+### Wired into a route: `GET /datasets/{dataset}/probesets/{probeset}`
+
+This is the first (and so far only) endpoint gated this way:
+
+- An `AuthToken` is required unconditionally -- every caller needs a
+  valid token, even for public data.
+- If the dataset is publicly readable (`is_publicly_readable`), the
+  probeset's metadata is returned with no further gn-auth call.
+- Otherwise, `authorise_trait(..., "group:resource:view-resource")` is
+  called; a `false` result (including the "never linked, so no
+  privileges" 404 case above) is a 403, not a 404 -- the dataset and
+  probeset both exist, the caller just isn't allowed to see them.
+- A failure to reach/parse gn-auth's answer is a 502, distinct from a
+  403 (denied) or a 500 (this service's own database error) -- see
+  `tests/dataset_probeset_info.rs` for all of these cases exercised
+  against a real gn-auth instance.
+
+Which other endpoints should require a token, and which privilege each
+should check, remains a separate decision, not yet made here.
 
 ### Found wrong in gn-auth while building this