Skip to content

Commit 858e398

Browse files
committed
Fix vm_config loading from sys-config.json
Previously the code was reading the entire sys-config.json file as the config, but it should only read the vm_config field within it. Extracted read_vm_config() function that properly parses SysConfig and returns the vm_config field.
1 parent 40b2fa6 commit 858e398

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

dstack-attest/src/attestation.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use dcap_qvl::{
1212
quote::{EnclaveReport, Quote, Report, TDReport10, TDReport15},
1313
verify::VerifiedReport as TdxVerifiedReport,
1414
};
15+
#[cfg(feature = "quote")]
16+
use dstack_types::SysConfig;
1517
use dstack_types::{Platform, VmConfig};
1618
use ez_hash::{sha256, Hasher, Sha384};
1719
use or_panic::ResultOrPanic;
@@ -23,6 +25,21 @@ use sha2::Digest as _;
2325
const DSTACK_TDX: &str = "dstack-tdx";
2426
const DSTACK_GCP_TDX: &str = "dstack-gcp-tdx";
2527
const DSTACK_NITRO_ENCLAVE: &str = "dstack-nitro-enclave";
28+
#[cfg(feature = "quote")]
29+
const SYS_CONFIG_PATH: &str = "/dstack/.host-shared/.sys-config.json";
30+
31+
/// Read vm_config from sys-config.json
32+
#[cfg(feature = "quote")]
33+
fn read_vm_config() -> Result<String> {
34+
let content = match fs_err::read_to_string(SYS_CONFIG_PATH) {
35+
Ok(content) => content,
36+
Err(err) if err.kind() == std::io::ErrorKind::NotFound => return Ok(String::new()),
37+
Err(err) => return Err(err).context("Failed to read sys-config"),
38+
};
39+
let sys_config: SysConfig =
40+
serde_json::from_str(&content).context("Failed to parse sys-config")?;
41+
Ok(sys_config.vm_config)
42+
}
2643

2744
/// Attestation mode
2845
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Encode, Decode, Serialize, Deserialize)]
@@ -578,10 +595,7 @@ impl Attestation {
578595
}
579596
};
580597
let config = match &quote {
581-
AttestationQuote::DstackTdx(_) => {
582-
// TODO: Find a better way handling this hardcode path
583-
fs_err::read_to_string("/dstack/.host-shared/.sys-config.json").unwrap_or_default()
584-
}
598+
AttestationQuote::DstackTdx(_) => read_vm_config()?,
585599
AttestationQuote::DstackGcpTdx | AttestationQuote::DstackNitroEnclave => {
586600
bail!("Unsupported attestation mode: {mode:?}");
587601
}

0 commit comments

Comments
 (0)