fix: evict finished reconstitute sessions, keep the mTLS listener alive on accept errors, drop dead code
Also removes OperatorActor.browser, unused since reconstitute targets are confined for every caller. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -292,8 +292,6 @@ pub struct BrowserSession {
|
||||
pub id: uuid::Uuid,
|
||||
pub csrf: String,
|
||||
pub actor: String,
|
||||
/// Read by per-user revoke and the OIDC login path (M3/M5).
|
||||
#[allow(dead_code)]
|
||||
pub user_id: String,
|
||||
pub auth_method: String,
|
||||
/// May use the management API. A signed-in user without a grant is `false`.
|
||||
|
||||
@@ -251,7 +251,6 @@ struct ReconstituteStartResponse {
|
||||
pub(super) struct OperatorActor {
|
||||
/// Display only. Never record this as "who did it": an IdP can call a user anything.
|
||||
pub(super) name: String,
|
||||
pub(super) browser: bool,
|
||||
pub(super) principal: Principal,
|
||||
pub(super) subject: Subject,
|
||||
pub(super) request_id: Uuid,
|
||||
@@ -318,7 +317,6 @@ fn authenticate_inner(
|
||||
) -> Result<OperatorActor, StatusCode> {
|
||||
let configured_admin = |name: &str, principal: Principal| OperatorActor {
|
||||
name: name.into(),
|
||||
browser: false,
|
||||
principal,
|
||||
subject: Subject {
|
||||
user_id: None,
|
||||
@@ -351,7 +349,6 @@ fn authenticate_inner(
|
||||
principal: session.principal(),
|
||||
subject: session.subject(),
|
||||
name: session.actor,
|
||||
browser: true,
|
||||
request_id,
|
||||
});
|
||||
}
|
||||
@@ -860,6 +857,7 @@ async fn start_reconstitute(
|
||||
let mut map = state_bg.reconstitute_sessions.write().await;
|
||||
if let Some(s) = map.get_mut(&session_id) {
|
||||
if s.state == ReconstituteState::Aborted {
|
||||
evict_reconstitute_later(&state_bg, session_id);
|
||||
return;
|
||||
}
|
||||
s.seconds_remaining = remaining;
|
||||
@@ -873,6 +871,7 @@ async fn start_reconstitute(
|
||||
return;
|
||||
};
|
||||
if s.state == ReconstituteState::Aborted {
|
||||
evict_reconstitute_later(&state_bg, session_id);
|
||||
return;
|
||||
}
|
||||
s.state = ReconstituteState::Restoring;
|
||||
@@ -891,6 +890,7 @@ async fn start_reconstitute(
|
||||
.db
|
||||
.audit("reconstitute.done", &format!("session={session_id}"))
|
||||
.await;
|
||||
evict_reconstitute_later(&state_bg, session_id);
|
||||
});
|
||||
|
||||
Ok(Json(ReconstituteStartResponse {
|
||||
@@ -899,6 +899,19 @@ async fn start_reconstitute(
|
||||
}))
|
||||
}
|
||||
|
||||
/// How long a finished restore session stays readable before its entry is dropped.
|
||||
const RECONSTITUTE_RETAIN: std::time::Duration = std::time::Duration::from_secs(3600);
|
||||
|
||||
/// Drops a finished session from the in-memory map after `RECONSTITUTE_RETAIN`, so the map does
|
||||
/// not grow for as long as the hub runs.
|
||||
fn evict_reconstitute_later(state: &HubState, id: Uuid) {
|
||||
let state = state.clone();
|
||||
tokio::spawn(async move {
|
||||
tokio::time::sleep(RECONSTITUTE_RETAIN).await;
|
||||
state.reconstitute_sessions.write().await.remove(&id);
|
||||
});
|
||||
}
|
||||
|
||||
fn browser_export_path(
|
||||
state: &HubState,
|
||||
requested: &str,
|
||||
|
||||
@@ -75,7 +75,16 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> {
|
||||
mtls.listen
|
||||
);
|
||||
loop {
|
||||
let (tcp, peer) = listener.accept().await.context("accept wormhole mTLS")?;
|
||||
let (tcp, peer) = match listener.accept().await {
|
||||
Ok(accepted) => accepted,
|
||||
Err(error) => {
|
||||
// Out of file descriptors, an aborted handshake and the like pass; stopping the
|
||||
// listener would end every Outpost's connection until a restart.
|
||||
tracing::warn!(%error, "wormhole mTLS accept failed; continuing");
|
||||
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
let acceptor = acceptor.clone();
|
||||
let app = app.clone();
|
||||
tokio::spawn(async move {
|
||||
|
||||
Reference in New Issue
Block a user