aboutsummaryrefslogtreecommitdiffstats
path: root/src/api/mod.rs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2026-11-19 20:11:05 +0000
committertv <tv@krebsco.de>2026-11-19 21:27:21 +0100
commit9bf334bedbc4b0cc3ce32fcd3baef27d3072f194 (patch)
tree6236db6799c2523ccdb899e6a42cc2153ce4eb08 /src/api/mod.rs
parentfc6c7101cdb42666c1f79df4206029c7cf7e61c6 (diff)
federated nodes: a party's keys log in as the party, for federation work
A party's people work with the federation by signing as the party, with a key of its set; what they need of a node is to read and to put events, which a node's users, its operators, may do with every power besides. POST /auth/login/party takes a challenge (POST /auth/challenge) signed with one of the keys that sign for the party (fold::State::signing_keys: those its current version names, and its key set as it counts), for the namespace continuum-login, armored or as the federation spells a signature (keys::signer, keys::verifies_in: the federation's checks, but for the namespace), and answers a token as the party. Logins by key are counted per party as per user (challenge::take_with, shared with logging in by a registry's keys). The token names the key (Claims::party). Such a session does federation work alone (api::access::federated): what --store-readers do, and POST /events; anything else is 403. Every request checks that the key still signs for the party: once a version or the party's key set drops it, 401. A build from before reads no token naming a key, as its claims deny fields they don't know, so never takes a party's session for a user's; and only the node that issued it takes it, as every token in a federated swarm.
Diffstat (limited to 'src/api/mod.rs')
-rw-r--r--src/api/mod.rs93
1 files changed, 50 insertions, 43 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs
index d91c434..c4265fb 100644
--- a/src/api/mod.rs
+++ b/src/api/mod.rs
@@ -44,7 +44,8 @@ use crate::state::AppState;
/// Builds the complete HTTP router. Everything except the API description (`/swagger-ui`,
/// `/openapi.yaml`), `/health`, `/ready` and logging in by key (`/auth/challenge`,
-/// `/auth/login/key`, which prove the user themselves) is authenticated.
+/// `/auth/login/key`, `/auth/login/party`, which prove the user themselves) is
+/// authenticated.
pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) -> Router {
let mut api: Router<AppState> = Router::new()
.route("/store", get(store::get_store_root))
@@ -118,48 +119,54 @@ pub(crate) fn router(state: AppState, auth_state: AuthState, debug_api: bool) ->
}
// Inside authentication, which finds the user: what the user may do.
- api.layer(middleware::from_fn_with_state(
- state.clone(),
- access::authorize,
- ))
- .layer(middleware::from_fn_with_state(
- auth_state.clone(),
- basic_auth,
- ))
- // Who has a password here (`/auth/keys`: a user's last key goes only then).
- .layer(axum::Extension(auth_state))
- // A stream answered to a token ends with it (expired, revoked, its session ended).
- .layer(middleware::from_fn_with_state(
- state.clone(),
- login::streams_end,
- ))
- // Outside authentication: a token, if the request brings one, names the user.
- .layer(middleware::from_fn_with_state(state.clone(), login::bearer))
- // Outermost: pages of other origins, and their preflights, which bring no
- // credentials.
- .layer(middleware::from_fn_with_state(state.clone(), cors::cors))
- // The hand-written spec (`docs/openapi.yaml`), and the Swagger UI showing it.
- .merge(
- // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that
- // serves the API under a path of its own too.
- SwaggerUi::new("/swagger-ui").config(utoipa_swagger_ui::Config::from("../openapi.yaml")),
- )
- .route("/openapi.yaml", get(openapi_spec))
- // Logging in by key: a challenge, and the token for it signed, without a password.
- .route("/auth/challenge", axum::routing::post(login::challenge))
- .route("/auth/login/key", axum::routing::post(login::login_key))
- .route("/health", get(health::node_health))
- // To log in to the dashboard on, and the dashboard's page, without authentication
- // (they hold nothing).
- .route("/login", get(dashboard_login))
- .route("/admin/dashboard", get(dashboard_page))
- .route("/ready", get(health::ready))
- // Outermost, so authentication failures get the error body too.
- .layer(middleware::from_fn(json_errors))
- .layer(middleware::from_fn(relative_redirects))
- // A line per request, as it is answered.
- .layer(middleware::from_fn(request_log::log_requests))
- .with_state(state)
+ let router = api
+ .layer(middleware::from_fn_with_state(
+ state.clone(),
+ access::authorize,
+ ))
+ .layer(middleware::from_fn_with_state(
+ auth_state.clone(),
+ basic_auth,
+ ))
+ // Who has a password here (`/auth/keys`: a user's last key goes only then).
+ .layer(axum::Extension(auth_state))
+ // A stream answered to a token ends with it (expired, revoked, its session ended).
+ .layer(middleware::from_fn_with_state(
+ state.clone(),
+ login::streams_end,
+ ))
+ // Outside authentication: a token, if the request brings one, names the user.
+ .layer(middleware::from_fn_with_state(state.clone(), login::bearer))
+ // Outermost: pages of other origins, and their preflights, which bring no
+ // credentials.
+ .layer(middleware::from_fn_with_state(state.clone(), cors::cors))
+ // The hand-written spec (`docs/openapi.yaml`), and the Swagger UI showing it.
+ .merge(
+ // Relative to the UI's page (`/swagger-ui/`), so it is found behind a proxy that
+ // serves the API under a path of its own too.
+ SwaggerUi::new("/swagger-ui")
+ .config(utoipa_swagger_ui::Config::from("../openapi.yaml")),
+ )
+ .route("/openapi.yaml", get(openapi_spec))
+ // Logging in by key: a challenge, and the token for it signed, without a password.
+ .route("/auth/challenge", axum::routing::post(login::challenge))
+ .route("/auth/login/key", axum::routing::post(login::login_key));
+ // A party's login by its key, on a node holding a federated store.
+ #[cfg(feature = "federation")]
+ let router = router.route("/auth/login/party", axum::routing::post(login::login_party));
+ router
+ .route("/health", get(health::node_health))
+ // To log in to the dashboard on, and the dashboard's page, without authentication
+ // (they hold nothing).
+ .route("/login", get(dashboard_login))
+ .route("/admin/dashboard", get(dashboard_page))
+ .route("/ready", get(health::ready))
+ // Outermost, so authentication failures get the error body too.
+ .layer(middleware::from_fn(json_errors))
+ .layer(middleware::from_fn(relative_redirects))
+ // A line per request, as it is answered.
+ .layer(middleware::from_fn(request_log::log_requests))
+ .with_state(state)
}
/// The HTTP router of a node that only relays (`--relay-only`): its figures and the log