@@ -54,6 +54,11 @@ pub fn run_boundary(config_path: &Path) -> Result<(), String> {
5454 let config: BoundaryConfig = serde_json:: from_slice ( & bytes)
5555 . map_err ( |error| format ! ( "decode boundary config {}: {error}" , config_path. display( ) ) ) ?;
5656 validate_config ( & config) ?;
57+ let runtime_directory = config_path
58+ . parent ( )
59+ . filter ( |path| path. is_absolute ( ) )
60+ . ok_or_else ( || "MXC bootstrap requires an absolute runtime directory" . to_string ( ) ) ?
61+ . to_path_buf ( ) ;
5762 std:: fs:: remove_file ( config_path)
5863 . map_err ( |error| format ! ( "consume boundary config {}: {error}" , config_path. display( ) ) ) ?;
5964
@@ -69,11 +74,8 @@ pub fn run_boundary(config_path: &Path) -> Result<(), String> {
6974 }
7075 } ;
7176 let tls = Arc :: new ( load_tls_server_config ( & tls) ?) ;
72- let listener = tokio:: net:: TcpListener :: bind ( address)
73- . await
74- . map_err ( |error| format ! ( "bind MXC boundary listener at {address}: {error}" ) ) ?;
75- let boundary = Arc :: new ( BoundaryRuntime :: new ( config) ?) ;
76- tracing:: info!( %address, "MXC Sandbox Protocol listener ready" ) ;
77+ let boundary = Arc :: new ( BoundaryRuntime :: new ( config, runtime_directory) ?) ;
78+ tracing:: info!( %address, "MXC Sandbox Protocol reverse control ready" ) ;
7779 loop {
7880 let ( stream, _) = listener
7981 . accept ( )
@@ -445,6 +447,8 @@ enum Lifecycle {
445447
446448struct BoundaryRuntime {
447449 config : BoundaryConfig ,
450+ runtime_directory : PathBuf ,
451+ proxy_url : String ,
448452 authenticator : SandboxProtocolAuthenticator ,
449453 connections : SandboxConnectionRegistry ,
450454 connection_shutdowns : Mutex < HashMap < SandboxConnectionId , tokio:: sync:: watch:: Sender < ( ) > > > ,
@@ -462,7 +466,11 @@ struct BoundaryRuntime {
462466}
463467
464468impl BoundaryRuntime {
465- fn new ( config : BoundaryConfig ) -> Result < Self , String > {
469+ fn new (
470+ launch : crate :: launch:: MxcBoundaryConfig ,
471+ runtime_directory : PathBuf ,
472+ ) -> Result < Self , String > {
473+ let config = launch. runtime ;
466474 let sandbox_id = SandboxId :: parse ( config. boundary_id . clone ( ) )
467475 . map_err ( |error| format ! ( "validate MXC sandbox ID: {error}" ) ) ?;
468476 let generation = openshell_core:: sandbox_generation:: SandboxGenerationId :: parse (
@@ -491,6 +499,8 @@ impl BoundaryRuntime {
491499 ) ,
492500 connections : SandboxConnectionRegistry :: new ( config. session_id , config. session_rotation ) ,
493501 config,
502+ runtime_directory,
503+ proxy_url : launch. proxy_url ,
494504 connection_shutdowns : Mutex :: new ( HashMap :: new ( ) ) ,
495505 active_connection : Mutex :: new ( None ) ,
496506 lifecycle : Mutex :: new ( Lifecycle :: AwaitingAttach ) ,
@@ -830,6 +840,7 @@ impl BoundaryRuntime {
830840 }
831841 }
832842 let ca_paths = match install_ca_material (
843+ & self . runtime_directory ,
833844 & self . config . generation ,
834845 ca_cert. as_deref ( ) . map ( str:: as_bytes) ,
835846 ca_bundle. as_deref ( ) . map ( str:: as_bytes) ,
@@ -1216,14 +1227,18 @@ fn workload_environment(
12161227}
12171228
12181229fn install_ca_material (
1230+ runtime_directory : & Path ,
12191231 generation : & str ,
12201232 certificate : Option < & [ u8 ] > ,
12211233 bundle : Option < & [ u8 ] > ,
12221234) -> Result < Option < ( PathBuf , PathBuf ) > , String > {
12231235 let ( Some ( certificate) , Some ( bundle) ) = ( certificate, bundle) else {
12241236 return Ok ( None ) ;
12251237 } ;
1226- let directory = std:: env:: temp_dir ( ) . join ( format ! ( "openshell-ca-{generation}" ) ) ;
1238+ // The driver already grants and protects the generation's boundary state.
1239+ // Host APPDATA/TEMP may be isolated or inaccessible inside ProcessContainer;
1240+ // never rely on those ambient paths or broaden workload filesystem grants.
1241+ let directory = runtime_directory. join ( format ! ( "openshell-ca-{generation}" ) ) ;
12271242 std:: fs:: create_dir_all ( & directory)
12281243 . map_err ( |error| format ! ( "create MXC CA directory: {error}" ) ) ?;
12291244 let certificate_path = directory. join ( "openshell-ca.pem" ) ;
@@ -1743,6 +1758,41 @@ mod tests {
17431758 . expect ( "shutdown notification" ) ;
17441759 }
17451760
1761+ #[ test]
1762+ fn ca_material_stays_under_the_explicit_boundary_runtime_directory ( ) {
1763+ let root = std:: env:: temp_dir ( ) . join ( format ! (
1764+ "openshell-ca-test-{}-{}" ,
1765+ std:: process:: id( ) ,
1766+ std:: time:: SystemTime :: now( )
1767+ . duration_since( std:: time:: UNIX_EPOCH )
1768+ . unwrap( )
1769+ . as_nanos( )
1770+ ) ) ;
1771+ let paths = install_ca_material ( & root, "test-generation" , Some ( b"cert" ) , Some ( b"bundle" ) )
1772+ . unwrap ( )
1773+ . unwrap ( ) ;
1774+ assert_eq ! (
1775+ paths. 0 ,
1776+ root. join( "openshell-ca-test-generation/openshell-ca.pem" )
1777+ ) ;
1778+ assert_eq ! (
1779+ paths. 1 ,
1780+ root. join( "openshell-ca-test-generation/ca-bundle.pem" )
1781+ ) ;
1782+ assert_eq ! ( std:: fs:: read( & paths. 0 ) . unwrap( ) , b"cert" ) ;
1783+ assert_eq ! ( std:: fs:: read( & paths. 1 ) . unwrap( ) , b"bundle" ) ;
1784+ assert ! (
1785+ install_ca_material( & root, "unused" , None , Some ( b"bundle" ) )
1786+ . unwrap( )
1787+ . is_none( )
1788+ ) ;
1789+ assert ! ( !root. join( "openshell-ca-unused" ) . exists( ) ) ;
1790+ std:: fs:: remove_file ( paths. 0 ) . unwrap ( ) ;
1791+ std:: fs:: remove_file ( paths. 1 ) . unwrap ( ) ;
1792+ std:: fs:: remove_dir ( root. join ( "openshell-ca-test-generation" ) ) . unwrap ( ) ;
1793+ std:: fs:: remove_dir ( root) . unwrap ( ) ;
1794+ }
1795+
17461796 #[ test]
17471797 fn installed_ca_replaces_case_insensitive_trust_overrides ( ) {
17481798 let certificate = Path :: new ( r"C:\trusted\ca.pem" ) ;
0 commit comments