Skip to content

Commit 127f5de

Browse files
authored
Merge pull request #444 from Dstack-TEE/fix-vm-config-load
Fix vm_config loading from sys-config.json
2 parents 40b2fa6 + 08cc383 commit 127f5de

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

dstack-attest/src/attestation.rs

Lines changed: 18 additions & 2 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)]
@@ -579,8 +596,7 @@ impl Attestation {
579596
};
580597
let config = match &quote {
581598
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()
599+
read_vm_config().context("Failed to read VM config")?
584600
}
585601
AttestationQuote::DstackGcpTdx | AttestationQuote::DstackNitroEnclave => {
586602
bail!("Unsupported attestation mode: {mode:?}");

0 commit comments

Comments
 (0)