@@ -1108,16 +1108,7 @@ impl App {
11081108 ) ?;
11091109 fs:: write ( shared_dir. join ( SYS_CONFIG ) , & sys_config_str)
11101110 . context ( "Failed to write vm config" ) ?;
1111- if let Some ( mut simulator_config) = cfg. cvm . tee_simulator . clone ( ) {
1112- let sys_config: dstack_types:: SysConfig = serde_json:: from_str ( & sys_config_str) ?;
1113- simulator_config. mr_config = sys_config. mr_config ;
1114- simulator_config. vm_config = Some ( sys_config. vm_config ) ;
1115- fs:: write (
1116- shared_dir. join ( TEE_SIMULATOR_CONFIG ) ,
1117- serde_json:: to_vec ( & simulator_config) ?,
1118- )
1119- . context ( "Failed to write TEE simulator config" ) ?;
1120- }
1111+ sync_tee_simulator_config ( & shared_dir, cfg. cvm . tee_simulator . as_ref ( ) , & sys_config_str) ?;
11211112 Ok ( ( ) )
11221113 }
11231114
@@ -1253,6 +1244,27 @@ fn rotate_serial_log(work_dir: &VmWorkDir, max_bytes: u64) {
12531244 }
12541245}
12551246
1247+ fn sync_tee_simulator_config (
1248+ shared_dir : & Path ,
1249+ simulator_config : Option < & dstack_types:: TeeSimulatorConfig > ,
1250+ sys_config : & str ,
1251+ ) -> Result < ( ) > {
1252+ let path = shared_dir. join ( TEE_SIMULATOR_CONFIG ) ;
1253+ let Some ( simulator_config) = simulator_config else {
1254+ if path. exists ( ) {
1255+ fs:: remove_file ( & path) . context ( "failed to remove stale TEE simulator config" ) ?;
1256+ }
1257+ return Ok ( ( ) ) ;
1258+ } ;
1259+
1260+ let sys_config: dstack_types:: SysConfig = serde_json:: from_str ( sys_config) ?;
1261+ let mut simulator_config = simulator_config. clone ( ) ;
1262+ simulator_config. mr_config = sys_config. mr_config ;
1263+ simulator_config. vm_config = Some ( sys_config. vm_config ) ;
1264+ fs:: write ( path, serde_json:: to_vec ( & simulator_config) ?)
1265+ . context ( "failed to write TEE simulator config" )
1266+ }
1267+
12561268pub ( crate ) fn make_sys_config (
12571269 cfg : & Config ,
12581270 manifest : & Manifest ,
@@ -1474,6 +1486,40 @@ mod tests {
14741486 hex:: encode ( vec ! [ byte; len] )
14751487 }
14761488
1489+ #[ test]
1490+ fn simulator_config_is_written_separately_with_measurement_inputs ( ) -> Result < ( ) > {
1491+ let dir = tempfile:: tempdir ( ) ?;
1492+ let config = dstack_types:: TeeSimulatorConfig {
1493+ platform : dstack_types:: TeeVariant :: DstackAmdSevSnp ,
1494+ mock_attestation_seed : Some ( "11" . repeat ( 32 ) ) ,
1495+ collateral_base_url : Some ( "http://127.0.0.1:18088" . into ( ) ) ,
1496+ ..Default :: default ( )
1497+ } ;
1498+ let mr_config = r#"{"version":3}"# ;
1499+ let vm_config = r#"{"image":"dev"}"# ;
1500+ let sys_config = serde_json:: json!( {
1501+ "kms_urls" : [ ] ,
1502+ "gateway_urls" : [ ] ,
1503+ "vm_config" : vm_config,
1504+ "mr_config" : mr_config,
1505+ } )
1506+ . to_string ( ) ;
1507+
1508+ sync_tee_simulator_config ( dir. path ( ) , Some ( & config) , & sys_config) ?;
1509+
1510+ let written: dstack_types:: TeeSimulatorConfig =
1511+ serde_json:: from_slice ( & fs:: read ( dir. path ( ) . join ( TEE_SIMULATOR_CONFIG ) ) ?) ?;
1512+ assert_eq ! ( written. platform, config. platform) ;
1513+ assert_eq ! ( written. mock_attestation_seed, config. mock_attestation_seed) ;
1514+ assert_eq ! ( written. collateral_base_url, config. collateral_base_url) ;
1515+ assert_eq ! ( written. mr_config. as_deref( ) , Some ( mr_config) ) ;
1516+ assert_eq ! ( written. vm_config. as_deref( ) , Some ( vm_config) ) ;
1517+
1518+ sync_tee_simulator_config ( dir. path ( ) , None , & sys_config) ?;
1519+ assert ! ( !dir. path( ) . join( TEE_SIMULATOR_CONFIG ) . exists( ) ) ;
1520+ Ok ( ( ) )
1521+ }
1522+
14771523 #[ test]
14781524 fn gpu_config_has_gpus_only_when_resolved_gpu_list_is_non_empty ( ) {
14791525 assert ! ( !GpuConfig :: default ( ) . has_gpus( ) ) ;
0 commit comments