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:
2026-11-16 21:19:58 +07:00
parent 6d2b882b3d
commit d14b27669a
3 changed files with 26 additions and 6 deletions

View File

@@ -292,8 +292,6 @@ pub struct BrowserSession {
pub id: uuid::Uuid, pub id: uuid::Uuid,
pub csrf: String, pub csrf: String,
pub actor: String, pub actor: String,
/// Read by per-user revoke and the OIDC login path (M3/M5).
#[allow(dead_code)]
pub user_id: String, pub user_id: String,
pub auth_method: String, pub auth_method: String,
/// May use the management API. A signed-in user without a grant is `false`. /// May use the management API. A signed-in user without a grant is `false`.

View File

@@ -251,7 +251,6 @@ struct ReconstituteStartResponse {
pub(super) struct OperatorActor { pub(super) struct OperatorActor {
/// Display only. Never record this as "who did it": an IdP can call a user anything. /// Display only. Never record this as "who did it": an IdP can call a user anything.
pub(super) name: String, pub(super) name: String,
pub(super) browser: bool,
pub(super) principal: Principal, pub(super) principal: Principal,
pub(super) subject: Subject, pub(super) subject: Subject,
pub(super) request_id: Uuid, pub(super) request_id: Uuid,
@@ -318,7 +317,6 @@ fn authenticate_inner(
) -> Result<OperatorActor, StatusCode> { ) -> Result<OperatorActor, StatusCode> {
let configured_admin = |name: &str, principal: Principal| OperatorActor { let configured_admin = |name: &str, principal: Principal| OperatorActor {
name: name.into(), name: name.into(),
browser: false,
principal, principal,
subject: Subject { subject: Subject {
user_id: None, user_id: None,
@@ -351,7 +349,6 @@ fn authenticate_inner(
principal: session.principal(), principal: session.principal(),
subject: session.subject(), subject: session.subject(),
name: session.actor, name: session.actor,
browser: true,
request_id, request_id,
}); });
} }
@@ -860,6 +857,7 @@ async fn start_reconstitute(
let mut map = state_bg.reconstitute_sessions.write().await; let mut map = state_bg.reconstitute_sessions.write().await;
if let Some(s) = map.get_mut(&session_id) { if let Some(s) = map.get_mut(&session_id) {
if s.state == ReconstituteState::Aborted { if s.state == ReconstituteState::Aborted {
evict_reconstitute_later(&state_bg, session_id);
return; return;
} }
s.seconds_remaining = remaining; s.seconds_remaining = remaining;
@@ -873,6 +871,7 @@ async fn start_reconstitute(
return; return;
}; };
if s.state == ReconstituteState::Aborted { if s.state == ReconstituteState::Aborted {
evict_reconstitute_later(&state_bg, session_id);
return; return;
} }
s.state = ReconstituteState::Restoring; s.state = ReconstituteState::Restoring;
@@ -891,6 +890,7 @@ async fn start_reconstitute(
.db .db
.audit("reconstitute.done", &format!("session={session_id}")) .audit("reconstitute.done", &format!("session={session_id}"))
.await; .await;
evict_reconstitute_later(&state_bg, session_id);
}); });
Ok(Json(ReconstituteStartResponse { 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( fn browser_export_path(
state: &HubState, state: &HubState,
requested: &str, requested: &str,

View File

@@ -75,7 +75,16 @@ pub async fn serve(mtls: WormholeMtls, app: Router) -> Result<()> {
mtls.listen mtls.listen
); );
loop { 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 acceptor = acceptor.clone();
let app = app.clone(); let app = app.clone();
tokio::spawn(async move { tokio::spawn(async move {