fixed #1442 - unnecessary get_info auth restrictions

This commit is contained in:
Eugene 2025-08-03 16:27:52 +02:00
parent 4b0e5dfa72
commit 8ad6972371
No known key found for this signature in database
GPG key ID: 5896FCBBDD1CF4F4
5 changed files with 19 additions and 22 deletions

View file

@ -233,7 +233,7 @@ impl Api {
#[oai(
path = "/auth/state",
method = "get",
operation_id = "getDefaultAuthState"
operation_id = "get_default_auth_state"
)]
async fn api_default_auth_state(
&self,
@ -256,7 +256,7 @@ impl Api {
#[oai(
path = "/auth/state",
method = "delete",
operation_id = "cancelDefaultAuth"
operation_id = "cancel_default_auth"
)]
async fn api_cancel_default_auth(
&self,

View file

@ -83,8 +83,8 @@ impl Api {
let targets = p.list_targets().await?;
(users, targets)
};
let user_is_admin = if let Some(auth) = request_authorization {
is_user_admin(req, &auth).await?
let user_is_admin = if let Some(auth) = &request_authorization {
is_user_admin(req, auth).await?
} else {
false
};
@ -104,8 +104,8 @@ impl Api {
};
Ok(InstanceInfoResponse::Ok(Json(Info {
version: session
.is_authenticated()
version: request_authorization
.is_some()
.then(|| warpgate_version().to_string()),
username: session.get_username(),
selected_target: session.get_target_name(),
@ -117,8 +117,8 @@ impl Api {
authorized_via_sso_with_single_logout: session
.get_sso_login_state()
.is_some_and(|state| state.supports_single_logout),
ports: if session.is_authenticated() {
PortsInfo {
ports: match request_authorization {
Some(_) => PortsInfo {
ssh: if config.store.ssh.enable {
Some(config.store.ssh.external_port())
} else {
@ -139,14 +139,13 @@ impl Api {
} else {
None
},
}
} else {
PortsInfo {
},
None => PortsInfo {
ssh: None,
http: None,
mysql: None,
postgres: None,
}
},
},
own_credential_management_allowed: parameters.allow_own_credential_management,
setup_state,

View file

@ -35,7 +35,6 @@ pub struct SsoLoginState {
pub trait SessionExt {
fn get_target_name(&self) -> Option<String>;
fn set_target_name(&self, target_name: String);
fn is_authenticated(&self) -> bool;
fn get_username(&self) -> Option<String>;
fn get_auth(&self) -> Option<SessionAuthorization>;
fn set_auth(&self, auth: SessionAuthorization);
@ -55,10 +54,6 @@ impl SessionExt for Session {
self.set(TARGET_SESSION_KEY, target_name);
}
fn is_authenticated(&self) -> bool {
self.get_username().is_some()
}
fn get_username(&self) -> Option<String> {
self.get_auth().map(|x| x.username().to_owned())
}

View file

@ -42,13 +42,16 @@ impl ChannelWriter {
}
pub fn write_extended(&self, handle: Handle, channel: ChannelId, ext: u32, data: CryptoVec) {
let _ = self.tx.send(ChannelWriteOperation::ExtendedData(handle, channel, ext, data));
let _ = self.tx.send(ChannelWriteOperation::ExtendedData(
handle, channel, ext, data,
));
}
/// Flush all pending writes. Returns when all previously queued operations have completed.
pub async fn flush(&self) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let (tx, rx) = tokio::sync::oneshot::channel();
self.tx.send(ChannelWriteOperation::Flush(tx))
self.tx
.send(ChannelWriteOperation::Flush(tx))
.map_err(|_| "ChannelWriter task has stopped")?;
rx.await.map_err(|_| "ChannelWriter flush failed")?;
Ok(())

View file

@ -736,7 +736,7 @@ impl ServerSession {
RCEvent::Close(channel) => {
// Flush any pending writes before closing the channel
let _ = self.channel_writer.flush().await;
let server_channel_id = self.map_channel_reverse(&channel)?;
let _ = self
.maybe_with_session(|handle| async move {
@ -750,7 +750,7 @@ impl ServerSession {
RCEvent::Eof(channel) => {
// Flush any pending writes before sending EOF
let _ = self.channel_writer.flush().await;
let server_channel_id = self.map_channel_reverse(&channel)?;
self.maybe_with_session(|handle| async move {
handle
@ -763,7 +763,7 @@ impl ServerSession {
RCEvent::ExitStatus(channel, code) => {
// Flush any pending writes before sending exit status
let _ = self.channel_writer.flush().await;
let server_channel_id = self.map_channel_reverse(&channel)?;
self.maybe_with_session(|handle| async move {
handle