diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-10-04 11:37:55 +0000 |
|---|---|---|
| committer | Pjotr <wrk@bosa.lan> | 2026-10-04 11:37:55 +0000 |
| commit | 859a86bf39df6eafa6988215cb84556fc9623ea0 (patch) | |
| tree | e31e62d0d891dce85be8a09d5094d9d8f06cf7e0 /src/lib.rs | |
| parent | 0a58bfdbec94d3c249a905226bd33480198f2e95 (diff) | |
| download | genenetwork4-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 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs index 8377643..4013797 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,9 +21,31 @@ use error::ApiError; title = "GeneNetwork4 API", description = "GeneNetwork4 REST API", license(name = "AGPL-3.0-or-later") -))] +), modifiers(&SecurityAddon))] struct ApiDoc; +/// Registers the "bearer_token" scheme used by endpoints that require a +/// gn-auth token (see `security(...)` on their `#[utoipa::path]`, e.g. +/// `routes::datasets::dataset_probeset_info`). +struct SecurityAddon; + +impl utoipa::Modify for SecurityAddon { + fn modify(&self, openapi: &mut utoipa::openapi::OpenApi) { + use utoipa::openapi::security::{HttpAuthScheme, HttpBuilder, SecurityScheme}; + if let Some(components) = openapi.components.as_mut() { + components.add_security_scheme( + "bearer_token", + SecurityScheme::Http( + HttpBuilder::new() + .scheme(HttpAuthScheme::Bearer) + .bearer_format("JWT") + .build(), + ), + ); + } + } +} + /// Build the application router. Public so integration tests (tests/) and /// the binary (src/main.rs) can both use it without binding a real socket. pub fn app() -> Router { |
