about summary refs log tree commit diff
path: root/src/lib.rs
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-10-13 06:06:37 +0000
committerPjotr <wrk@bosa.lan>2026-10-13 06:06:37 +0000
commit2551418eede25d0ffaebef67f9950f13e3551567 (patch)
tree1d173432582191401f69622925d7337d5ebe81c8 /src/lib.rs
parent2456d66fc2c14345ab0730ef0a4ae07458af8ec6 (diff)
downloadgenenetwork4-2551418eede25d0ffaebef67f9950f13e3551567.tar.gz
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 <noreply@anthropic.com>
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs6
1 files changed, 5 insertions, 1 deletions
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<VersionInfo>),
     (status = 500, description = "Internal error", body = ApiError)
 ), security())]
+#[gnauth(disabled)]
 async fn version(ctx: Ctx) -> Json<Envelope<VersionInfo>> {
     Json(ctx.envelope(VersionInfo {
         name: "GeneNetwork4",