@@ -19,9 +19,7 @@ use crate::{
1919} ;
2020use anyhow:: { bail, Context , Result } ;
2121use bon:: Builder ;
22- use dstack_types:: {
23- shared_filenames:: HOST_SHARED_DISK_LABEL , KeyProviderKind , TeeSimulatorConfig , TeeVariant ,
24- } ;
22+ use dstack_types:: { shared_filenames:: HOST_SHARED_DISK_LABEL , KeyProviderKind , TeeVariant } ;
2523use fs_err as fs;
2624use nix:: unistd:: User ;
2725use serde:: Serialize ;
@@ -179,15 +177,16 @@ struct PreparedVolume {
179177 source : String ,
180178}
181179
182- fn needs_qemu_swtpm ( key_provider : KeyProviderKind , simulator : Option < & TeeSimulatorConfig > ) -> bool {
183- if !matches ! ( key_provider, KeyProviderKind :: Tpm ) {
184- return false ;
185- }
186- !matches ! (
187- simulator. map( |config| config. platform) ,
180+ fn simulated_platform_provides_tpm ( platform : Option < TeeVariant > ) -> bool {
181+ matches ! (
182+ platform,
188183 Some ( TeeVariant :: DstackGcpTdx | TeeVariant :: DstackAwsNitroTpm )
189184 )
190185}
186+
187+ fn needs_qemu_swtpm ( key_provider : KeyProviderKind , simulated_tee : Option < TeeVariant > ) -> bool {
188+ matches ! ( key_provider, KeyProviderKind :: Tpm ) && !simulated_platform_provides_tpm ( simulated_tee)
189+ }
191190struct PreparedQemuLaunch {
192191 workdir : VmWorkDir ,
193192 platform : CvmPlatform ,
@@ -246,7 +245,7 @@ impl PreparedQemuLaunch {
246245 None
247246 } ;
248247 let ( swtpm_socket, swtpm_path) =
249- if needs_qemu_swtpm ( app_compose. key_provider ( ) , cfg . tee_simulator . as_ref ( ) ) {
248+ if needs_qemu_swtpm ( app_compose. key_provider ( ) , vm . manifest . simulated_tee ) {
250249 let swtpm_path = which:: which ( "swtpm" )
251250 . context ( "tpm key provider requested but swtpm is not installed" ) ?;
252251 let state_dir = workdir. swtpm_state_dir ( ) ;
@@ -989,20 +988,19 @@ mod tests {
989988 use crate :: app:: image:: { Image , ImageInfo } ;
990989 use crate :: app:: { GpuConfig , Manifest , PortMapping , VmVolume , VmWorkDir } ;
991990 use crate :: config:: { Config , CvmPlatform , Protocol , DEFAULT_CONFIG } ;
992- use dstack_types:: { KeyProviderKind , TeeSimulatorConfig , TeeVariant } ;
991+ use dstack_types:: { KeyProviderKind , TeeVariant } ;
993992
994993 #[ test]
995994 fn qemu_swtpm_is_omitted_when_simulator_provides_the_tpm ( ) {
996995 for platform in [ TeeVariant :: DstackGcpTdx , TeeVariant :: DstackAwsNitroTpm ] {
997- let simulator = TeeSimulatorConfig {
998- platform,
999- ..Default :: default ( )
1000- } ;
1001- assert ! ( !needs_qemu_swtpm( KeyProviderKind :: Tpm , Some ( & simulator) ) ) ;
996+ assert ! ( !needs_qemu_swtpm( KeyProviderKind :: Tpm , Some ( platform) ) ) ;
997+ assert ! ( !needs_qemu_swtpm( KeyProviderKind :: Kms , Some ( platform) ) ) ;
1002998 }
1003999
1004- let tdx = TeeSimulatorConfig :: default ( ) ;
1005- assert ! ( needs_qemu_swtpm( KeyProviderKind :: Tpm , Some ( & tdx) ) ) ;
1000+ assert ! ( needs_qemu_swtpm(
1001+ KeyProviderKind :: Tpm ,
1002+ Some ( TeeVariant :: DstackTdx )
1003+ ) ) ;
10061004 assert ! ( needs_qemu_swtpm( KeyProviderKind :: Tpm , None ) ) ;
10071005 assert ! ( !needs_qemu_swtpm( KeyProviderKind :: Kms , None ) ) ;
10081006 }
@@ -1070,6 +1068,7 @@ mod tests {
10701068 kms_urls : vec ! [ ] ,
10711069 gateway_urls : vec ! [ ] ,
10721070 no_tee : true ,
1071+ simulated_tee : None ,
10731072 networks : vec ! [ ] ,
10741073 volumes : vec ! [ VmVolume {
10751074 source: "/does-not-exist/volume.img" . into( ) ,
0 commit comments