From 2551418eede25d0ffaebef67f9950f13e3551567 Mon Sep 17 00:00:00 2001 From: Pjotr Date: Tue, 13 Oct 2026 06:06:37 +0000 Subject: auth: add gnauth compile-time tags (secured/token_only/disabled) Adds a gnauth-macros proc-macro crate and a private-field Authorized capability type in src/auth.rs, so #[gnauth(secured)] is a real, compile-time-checked guarantee that a handler performs the gn-auth resource-authorisation round trip before sharing trait/probeset values, rather than just a comment. #[gnauth(token_only)] marks handlers that require a token but skip the round trip, and #[gnauth(disabled)] marks the two handlers that need no token at all. Also fixes groups.rs: group_trait_values, group_trait_info and group_traits previously performed no gn-auth round trip at all for published-trait data; they now resolve the group's PublishFreeze row and call the same auth::check used elsewhere, denying by default when no such row exists. Co-Authored-By: Claude Sonnet 5 --- src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 75746d9..f011219 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use axum::Json; use axum::Router; +use gnauth_macros::gnauth; use tower_http::request_id::{MakeRequestUuid, PropagateRequestIdLayer, SetRequestIdLayer}; use utoipa::OpenApi; use utoipa_axum::router::OpenApiRouter; @@ -108,11 +109,13 @@ pub fn app() -> Router { // whose response is not wrapped in the envelope, like /openapi.json. // Both opt out of ApiDoc's default security requirement with an empty // security() -- neither takes an AuthToken, so documenting them as -// needing one would be wrong, not just inconsistent. +// needing one would be wrong, not just inconsistent. #[gnauth(disabled)] +// below makes that a compile-time assertion, not just this comment. #[utoipa::path(get, path = "/", summary = "Greeting; confirms the server is up", responses( (status = 200, description = "Greeting", body = String), (status = 500, description = "Internal error", body = ApiError) ), security())] +#[gnauth(disabled)] async fn hello_world() -> &'static str { "Hello, world!" } @@ -131,6 +134,7 @@ struct VersionInfo { (status = 200, description = "Build information", body = Envelope), (status = 500, description = "Internal error", body = ApiError) ), security())] +#[gnauth(disabled)] async fn version(ctx: Ctx) -> Json> { Json(ctx.envelope(VersionInfo { name: "GeneNetwork4", -- cgit 1.4.1