auth revocation implemented

This commit is contained in:
Priec
2026-08-17 13:27:54 +02:00
parent f0d12584ef
commit a80b389a3f
6 changed files with 198 additions and 2 deletions

2
Cargo.lock generated
View File

@@ -6958,6 +6958,7 @@ dependencies = [
"flate2",
"futures",
"gtin-validate",
"http",
"iban_validate",
"jiff",
"jiff-sqlx",
@@ -6996,6 +6997,7 @@ dependencies = [
"tokio-test",
"tonic",
"tonic-reflection",
"tower",
"tracing",
"tracing-subscriber",
"tui-canvas-validation-core",

2
client

Submodule client updated: 7319ea4178...2031656932

View File

@@ -12,6 +12,16 @@ service AuthService {
rpc GetAuthorization(GetAuthorizationRequest) returns (AuthorizationSnapshot);
rpc SetTimezone(SetTimezoneRequest) returns (UserPreferences);
// Ends the caller's own sessions. Every token issued to them before this
// call, on every device, stops being accepted -- including the one used to
// make the call, so the caller must log in again afterwards. Discarding a
// token client-side is not a logout; this is.
rpc Logout(LogoutRequest) returns (LogoutResponse);
// Ends every session of another user, for a leaked token or a departing
// account. Requires the struct:user area, and the target must rank strictly
// below the caller.
rpc RevokeUserSessions(RevokeUserSessionsRequest) returns (RevokeUserSessionsResponse);
// Role administration. Every call requires the struct:role area, and every
// target role must rank strictly below the caller's own role.
rpc ListRoles(ListRolesRequest) returns (ListRolesResponse);
@@ -80,6 +90,16 @@ message UserPreferences {
string timezone = 1;
}
message LogoutRequest {}
message LogoutResponse {}
message RevokeUserSessionsRequest {
string username = 1;
}
message RevokeUserSessionsResponse {}
message GetAuthorizationRequest {}
message Permission {

Binary file not shown.

View File

@@ -88,6 +88,17 @@ pub struct UserPreferences {
pub timezone: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LogoutRequest {}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct LogoutResponse {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RevokeUserSessionsRequest {
#[prost(string, tag = "1")]
pub username: ::prost::alloc::string::String,
}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct RevokeUserSessionsResponse {}
#[derive(Clone, Copy, PartialEq, Eq, Hash, ::prost::Message)]
pub struct GetAuthorizationRequest {}
#[derive(Clone, PartialEq, Eq, Hash, ::prost::Message)]
pub struct Permission {
@@ -450,6 +461,60 @@ pub mod auth_service_client {
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "SetTimezone"));
self.inner.unary(req, path, codec).await
}
/// Ends the caller's own sessions. Every token issued to them before this
/// call, on every device, stops being accepted -- including the one used to
/// make the call, so the caller must log in again afterwards. Discarding a
/// token client-side is not a logout; this is.
pub async fn logout(
&mut self,
request: impl tonic::IntoRequest<super::LogoutRequest>,
) -> std::result::Result<tonic::Response<super::LogoutResponse>, tonic::Status> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/Logout",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(GrpcMethod::new("komp_ac.auth.AuthService", "Logout"));
self.inner.unary(req, path, codec).await
}
/// Ends every session of another user, for a leaked token or a departing
/// account. Requires the struct:user area, and the target must rank strictly
/// below the caller.
pub async fn revoke_user_sessions(
&mut self,
request: impl tonic::IntoRequest<super::RevokeUserSessionsRequest>,
) -> std::result::Result<
tonic::Response<super::RevokeUserSessionsResponse>,
tonic::Status,
> {
self.inner
.ready()
.await
.map_err(|e| {
tonic::Status::unknown(
format!("Service was not ready: {}", e.into()),
)
})?;
let codec = tonic_prost::ProstCodec::default();
let path = http::uri::PathAndQuery::from_static(
"/komp_ac.auth.AuthService/RevokeUserSessions",
);
let mut req = request.into_request();
req.extensions_mut()
.insert(
GrpcMethod::new("komp_ac.auth.AuthService", "RevokeUserSessions"),
);
self.inner.unary(req, path, codec).await
}
/// Role administration. Every call requires the struct:role area, and every
/// target role must rank strictly below the caller's own role.
pub async fn list_roles(
@@ -734,6 +799,24 @@ pub mod auth_service_server {
&self,
request: tonic::Request<super::SetTimezoneRequest>,
) -> std::result::Result<tonic::Response<super::UserPreferences>, tonic::Status>;
/// Ends the caller's own sessions. Every token issued to them before this
/// call, on every device, stops being accepted -- including the one used to
/// make the call, so the caller must log in again afterwards. Discarding a
/// token client-side is not a logout; this is.
async fn logout(
&self,
request: tonic::Request<super::LogoutRequest>,
) -> std::result::Result<tonic::Response<super::LogoutResponse>, tonic::Status>;
/// Ends every session of another user, for a leaked token or a departing
/// account. Requires the struct:user area, and the target must rank strictly
/// below the caller.
async fn revoke_user_sessions(
&self,
request: tonic::Request<super::RevokeUserSessionsRequest>,
) -> std::result::Result<
tonic::Response<super::RevokeUserSessionsResponse>,
tonic::Status,
>;
/// Role administration. Every call requires the struct:role area, and every
/// target role must rank strictly below the caller's own role.
async fn list_roles(
@@ -1091,6 +1174,97 @@ pub mod auth_service_server {
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/Logout" => {
#[allow(non_camel_case_types)]
struct LogoutSvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::LogoutRequest>
for LogoutSvc<T> {
type Response = super::LogoutResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::LogoutRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::logout(&inner, request).await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = LogoutSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/RevokeUserSessions" => {
#[allow(non_camel_case_types)]
struct RevokeUserSessionsSvc<T: AuthService>(pub Arc<T>);
impl<
T: AuthService,
> tonic::server::UnaryService<super::RevokeUserSessionsRequest>
for RevokeUserSessionsSvc<T> {
type Response = super::RevokeUserSessionsResponse;
type Future = BoxFuture<
tonic::Response<Self::Response>,
tonic::Status,
>;
fn call(
&mut self,
request: tonic::Request<super::RevokeUserSessionsRequest>,
) -> Self::Future {
let inner = Arc::clone(&self.0);
let fut = async move {
<T as AuthService>::revoke_user_sessions(&inner, request)
.await
};
Box::pin(fut)
}
}
let accept_compression_encodings = self.accept_compression_encodings;
let send_compression_encodings = self.send_compression_encodings;
let max_decoding_message_size = self.max_decoding_message_size;
let max_encoding_message_size = self.max_encoding_message_size;
let inner = self.inner.clone();
let fut = async move {
let method = RevokeUserSessionsSvc(inner);
let codec = tonic_prost::ProstCodec::default();
let mut grpc = tonic::server::Grpc::new(codec)
.apply_compression_config(
accept_compression_encodings,
send_compression_encodings,
)
.apply_max_message_size_config(
max_decoding_message_size,
max_encoding_message_size,
);
let res = grpc.unary(method, req).await;
Ok(res)
};
Box::pin(fut)
}
"/komp_ac.auth.AuthService/ListRoles" => {
#[allow(non_camel_case_types)]
struct ListRolesSvc<T: AuthService>(pub Arc<T>);

2
server

Submodule server updated: f3efeae04b...891aa0038b