Skip to content

Commit 2dfe3d0

Browse files
authored
Merge pull request #128 from Dstack-TEE/det-rtmr3
Deterministic RTMR3
2 parents 2ea4062 + a8a3d2b commit 2dfe3d0

File tree

8 files changed

+37
-21
lines changed

8 files changed

+37
-21
lines changed

dstack-types/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ pub struct AppCompose {
2727
pub key_provider: Option<KeyProviderKind>,
2828
#[serde(default)]
2929
pub allowed_envs: Vec<String>,
30+
#[serde(default)]
31+
pub no_instance_id: bool,
3032
}
3133

3234
#[derive(Deserialize, Serialize, Debug, Clone, Copy)]

kms/tapp/deploy-to-teepod.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ $CLI compose \
9191
--local-key-provider \
9292
--public-logs \
9393
--public-sysinfo \
94+
--no-instance-id \
9495
--output .app-compose.json
9596

9697
# Remove the temporary file as it is no longer needed

ra-tls/src/attestation.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,28 @@ impl<T> Attestation<T> {
165165
} else {
166166
sha256(&[&key_provider_info])
167167
};
168-
let mr_aggregated = sha256(&[
168+
let mr_system = sha256(&[
169169
&td_report.mr_td,
170170
&rtmrs[0],
171171
&rtmrs[1],
172172
&rtmrs[2],
173173
&mr_key_provider,
174174
]);
175+
let mr_aggregated = sha256(&[&td_report.mr_td, &rtmrs[0], &rtmrs[1], &rtmrs[2], &rtmrs[3]]);
175176
let mr_image = sha256(&[&td_report.mr_td, &rtmrs[1], &rtmrs[2]]);
176177
Ok(AppInfo {
177-
app_id: self.find_event_payload("app-id")?,
178+
app_id: self.find_event_payload("app-id").unwrap_or_default(),
178179
compose_hash: self.find_event_payload("compose-hash")?,
179-
instance_id: self.find_event_payload("instance-id")?,
180+
instance_id: self.find_event_payload("instance-id").unwrap_or_default(),
180181
device_id,
181-
rootfs_hash: self.find_event_payload("rootfs-hash")?,
182182
mrtd: td_report.mr_td,
183183
rtmr0: rtmrs[0],
184184
rtmr1: rtmrs[1],
185185
rtmr2: rtmrs[2],
186186
rtmr3: rtmrs[3],
187-
mr_aggregated,
188187
mr_image,
188+
mr_system,
189+
mr_aggregated,
189190
mr_key_provider,
190191
key_provider_info,
191192
})
@@ -328,9 +329,6 @@ pub struct AppInfo {
328329
/// ID of the device
329330
#[serde(with = "hex_bytes")]
330331
pub device_id: Vec<u8>,
331-
/// Rootfs hash
332-
#[serde(with = "hex_bytes")]
333-
pub rootfs_hash: Vec<u8>,
334332
/// TCB info
335333
#[serde(with = "hex_bytes")]
336334
pub mrtd: [u8; 48],
@@ -346,6 +344,9 @@ pub struct AppInfo {
346344
/// Runtime MR3
347345
#[serde(with = "hex_bytes")]
348346
pub rtmr3: [u8; 48],
347+
/// Measurement of everything except the app info
348+
#[serde(with = "hex_bytes")]
349+
pub mr_system: [u8; 32],
349350
/// Measurement of the entire vm execution environment
350351
#[serde(with = "hex_bytes")]
351352
pub mr_aggregated: [u8; 32],

tdxctl/src/fde_setup.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use serde::{Deserialize, Serialize};
2121
use tracing::{info, warn};
2222

2323
use crate::{
24-
cmd_gen_app_keys, cmd_show,
24+
cmd_gen_app_keys, cmd_show_mrs,
2525
crypto::dh_decrypt,
2626
gen_app_keys_from_seed,
2727
host_api::HostApi,
@@ -554,7 +554,9 @@ impl SetupFdeArgs {
554554
rand_id
555555
};
556556
}
557-
let instance_id = {
557+
let instance_id = if host_shared.app_compose.no_instance_id {
558+
vec![]
559+
} else {
558560
let mut id_path = instance_info.instance_id_seed.clone();
559561
id_path.extend_from_slice(&instance_info.app_id);
560562
sha256(&id_path)[..20].to_vec()
@@ -567,15 +569,13 @@ impl SetupFdeArgs {
567569
host.notify_q("boot.progress", "extending RTMRs").await;
568570

569571
extend_rtmr3("system-preparing", &[])?;
570-
extend_rtmr3("rootfs-hash", &self.rootfs_hash)?;
571572
extend_rtmr3("app-id", &instance_info.app_id)?;
572573
extend_rtmr3("compose-hash", &compose_hash)?;
573574
extend_rtmr3("instance-id", &instance_id)?;
574575
extend_rtmr3("boot-mr-done", &[])?;
575576

576577
if host_shared.app_compose.key_provider().is_kms() {
577-
// Show the RTMR
578-
cmd_show()?;
578+
cmd_show_mrs()?;
579579
}
580580

581581
host.notify_q("boot.progress", "requesting app keys").await;
@@ -611,8 +611,7 @@ impl SetupFdeArgs {
611611
host.notify_q("boot.progress", "rootfs ready").await;
612612

613613
if !host_shared.app_compose.key_provider().is_kms() {
614-
// Show the RTMR
615-
cmd_show()?;
614+
cmd_show_mrs()?;
616615
}
617616
Ok(())
618617
}

tdxctl/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,10 @@ impl core::fmt::Debug for ParsedReport {
284284
}
285285
}
286286

287-
fn cmd_show() -> Result<()> {
287+
fn cmd_show_mrs() -> Result<()> {
288288
let attestation = ra_tls::attestation::Attestation::local()?;
289289
let app_info = attestation.decode_app_info(false)?;
290-
println!("========== App Info ==========");
290+
println!("========== Measurement Report ==========");
291291
serde_json::to_writer_pretty(io::stdout(), &app_info)?;
292292
println!();
293293
Ok(())
@@ -516,7 +516,7 @@ async fn main() -> Result<()> {
516516
match cli.command {
517517
Commands::Report => cmd_report()?,
518518
Commands::Quote => cmd_quote()?,
519-
Commands::Show => cmd_show()?,
519+
Commands::Show => cmd_show_mrs()?,
520520
Commands::Extend(extend_args) => {
521521
cmd_extend(extend_args)?;
522522
}

teepod/src/console.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1163,6 +1163,7 @@ <h3>Derive VM</h3>
11631163
"public_sysinfo": vmForm.value.public_sysinfo,
11641164
"local_key_provider_enabled": vmForm.value.local_key_provider_enabled,
11651165
"allowed_envs": vmForm.value.encrypted_envs.map(env => env.key),
1166+
"no_instance_id": !vmForm.value.tproxy_enabled,
11661167
};
11671168

11681169
if (vmForm.value.preLaunchScript?.trim()) {

teepod/src/teepod-cli.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -396,10 +396,17 @@ def calc_app_id(self, compose_file: str) -> str:
396396
compose_hash = hashlib.sha256(compose_file.encode()).hexdigest()
397397
return compose_hash[:40]
398398

399-
def create_app_compose(self, name: str, prelaunch_script: str, docker_compose: str,
400-
kms_enabled: bool, tproxy_enabled: bool, local_key_provider_enabled: bool,
401-
public_logs: bool, public_sysinfo: bool,
399+
def create_app_compose(self,
400+
name: str,
401+
prelaunch_script: str,
402+
docker_compose: str,
403+
kms_enabled: bool,
404+
tproxy_enabled: bool,
405+
local_key_provider_enabled: bool,
406+
public_logs: bool,
407+
public_sysinfo: bool,
402408
envs: Optional[Dict],
409+
no_instance_id: bool,
403410
output: str,
404411
) -> None:
405412
"""Create a new app compose file"""
@@ -414,6 +421,7 @@ def create_app_compose(self, name: str, prelaunch_script: str, docker_compose: s
414421
"public_logs": public_logs,
415422
"public_sysinfo": public_sysinfo,
416423
"allowed_envs": [k for k in envs.keys()],
424+
"no_instance_id": no_instance_id,
417425
}
418426
if prelaunch_script:
419427
app_compose["prelaunch_script"] = prelaunch_script
@@ -770,6 +778,8 @@ def main():
770778
'--public-sysinfo', action='store_true', help='Enable public sysinfo')
771779
compose_parser.add_argument(
772780
'--env-file', help='File with environment variables to encrypt', default=None)
781+
compose_parser.add_argument(
782+
'--no-instance-id', action='store_true', help='Disable instance ID')
773783
compose_parser.add_argument(
774784
'--output', required=True, help='Path to output app-compose.json file')
775785

@@ -856,6 +866,7 @@ def main():
856866
public_logs=args.public_logs,
857867
public_sysinfo=args.public_sysinfo,
858868
envs=parse_env_file(args.env_file),
869+
no_instance_id=args.no_instance_id,
859870
output=args.output
860871
)
861872
elif args.command == 'deploy':

tproxy/tapp/deploy-to-teepod.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ $CLI compose \
121121
--env-file .app_env \
122122
--public-logs \
123123
--public-sysinfo \
124+
--no-instance-id \
124125
--output .app-compose.json
125126

126127
# Remove the temporary file as it is no longer needed

0 commit comments

Comments
 (0)