Skip to content

Commit 0e074fb

Browse files
committed
feat(supervisor): host concurrent sessions on session-bound runtimes
SessionHost runs several supervisor sessions in one process. Each session gets its own Tokio runtime, and every thread that runtime starts, plus the thread driving it, is bound to the session's OCSF context, OCSF JSON settings, log sink, and denial log. Tasks, blocking work, reconnects, and credential renewal spawned by a session therefore keep its identity, while threads outside any session carry none and push no logs. Gateway credentials stay explicit per session. Removing a session stops its workload gracefully, or cancels it at once while it is still starting, then shuts down only its runtime and revokes its gateway credentials. The key stays registered until the session thread has finished, so the same generation cannot gain a second owner while one is stopping. A panicking session reports a failure, clears its readiness, and is revoked the same way. Hosted sessions get a private proxy trust directory and serve policy.local denials from their own log. A focused test runs two sessions concurrently and checks that nested and blocking tasks see their own identity, gateway requests carry their own bearer, log lines reach only their own stream, and removing one leaves the other supervising. Closes #4699 Signed-off-by: Drew Newberry <anewberry@nvidia.com>
1 parent daeba51 commit 0e074fb

5 files changed

Lines changed: 964 additions & 0 deletions

File tree

‎Cargo.lock‎

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/openshell-supervisor/Cargo.toml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ bundled-ca-roots = ["openshell-supervisor-network/bundled-ca-roots"]
5757
[dev-dependencies]
5858
openshell-sandbox-backend = { path = "../openshell-sandbox-backend", features = ["test-support"] }
5959

60+
bytes = { workspace = true }
61+
http = { workspace = true }
62+
http-body-util = { workspace = true }
63+
hyper = { workspace = true }
64+
hyper-util = { workspace = true }
6065
tokio = { workspace = true, features = ["test-util"] }
6166
futures = { workspace = true }
6267
temp-env = "0.3"

‎crates/openshell-supervisor/README.md‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,24 @@ readiness, and stops the session on SIGTERM or SIGINT. The binary shares one
4040
`GatewayCredentials` between log push and supervision, so renewal by either
4141
keeps both current.
4242

43+
`session_host::SessionHost` runs several sessions in one process. Each session
44+
gets its own Tokio runtime; every thread of that runtime, and the thread
45+
driving it, is bound to the session's OCSF context, OCSF JSON settings, log
46+
sink, and denial log. Spawned tasks, blocking work, callbacks, reconnects, and
47+
renewal therefore inherit the session's identity, and threads outside a
48+
session carry none and push no logs. The OCSF context also supplies the
49+
sandbox identity in middleware requests.
50+
51+
Removing a session stops its workload, shuts down only its runtime, and
52+
revokes its gateway credentials; the key stays registered until the session's
53+
thread has finished. A session that panics reports a failure and is revoked
54+
the same way. A session that is still starting is cancelled at once; the
55+
sandbox runtime then loses supervision and fails closed, as it does when a
56+
dedicated supervisor exits. A hosted session without an explicit proxy trust
57+
directory receives a private one for its lifetime. Hosted processes must
58+
install `LogPushLayer::thread_bound` and an `OcsfShorthandLayer` writing to
59+
`SessionDenialWriter`.
60+
4361
## Console logging
4462

4563
Diagnostics and OCSF shorthand share a bounded, nonblocking stderr writer. With `ocsf_json_enabled=true`, the same writer also receives timestamped `OCSF-JSON` records. Each formatter submits a complete line in one write so concurrent producers cannot interleave records in the queue. The 1,024-line queue drops new lines when full rather than waiting for stderr.

‎crates/openshell-supervisor/src/lib.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod denial_aggregator;
2323
mod endpoint_status;
2424
mod mechanistic_mapper;
2525
mod provider_readiness;
26+
pub mod session_host;
2627

2728
use miette::{IntoDiagnostic, Result, WrapErr};
2829
use std::future::Future;

0 commit comments

Comments
 (0)