From 3e3a454c5b71cb19b88e620e0c0a43b3f6852621 Mon Sep 17 00:00:00 2001 From: Pedro Henrique Penna Date: Tue, 27 Oct 2026 09:48:56 -0700 Subject: [PATCH 1/2] microVM: recognize a NIC template by its complete deny-all policy A platform snapshot is a template that each clone restores, and a clone of a template with a NIC needs its own network policy. Restore requires the policy that the snapshot recorded, because the endpoint may have held flows, listeners, and forwards under it, and the guest may have learned a DNS server and announced its listeners under it. A NIC captured with a complete deny-all policy is different. The policy denies every guest frame, host loopback, and inbound access, and keeps no proxy endpoint, so the endpoint held no flows, listeners, or forwards, and the guest learned no DNS server and announces no listeners. Nothing in such a snapshot depends on the policy beyond the NIC's identity. Add microvm_network_template_policy, which binds that policy to a NIC's identity, as a capture with --network-egress deny and --host-loopback deny, without rules, a proxy, or ingress, records it. Add validate_microvm_network_replacement, which checks that a snapshot's network records exactly that policy for its own identity, and returns the policy for the restore contract, which keeps it whatever policy replaces it. The saved record must equal the template's in the encoding that the policy has today: version 3 without IPv6, or version 4 with it. Versions 0 to 2 encode neither the host-loopback action nor the proxy endpoint, so no snapshot that records one is a template, whatever its digest. A replacement keeps the captured identity, so it may name IPv6 destinations only when that identity has IPv6, rather than install rules that could never match. The manifest format does not change: a template is recognized from what every networked snapshot already records, including those captured before this change. Unit tests cover templates with and without IPv6, replacements that open every direction, the near misses (deny-all egress with host loopback, a proxy, ingress, host-loopback ingress, rules that deny every destination, and allow-all egress), the legacy encodings, a noncanonical identity, and IPv6 rules on templates with and without IPv6. See microsoft/nvx#536. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../openvmm_helpers/src/snapshot/microvm.rs | 207 ++++++++++++++++++ 1 file changed, 207 insertions(+) diff --git a/openvmm/openvmm_helpers/src/snapshot/microvm.rs b/openvmm/openvmm_helpers/src/snapshot/microvm.rs index f2258b48d56..7ed684acb0e 100644 --- a/openvmm/openvmm_helpers/src/snapshot/microvm.rs +++ b/openvmm/openvmm_helpers/src/snapshot/microvm.rs @@ -606,6 +606,66 @@ pub fn validate_microvm_network_policy( Ok(()) } +/// Returns the complete deny-all policy of a NIC template bound to `config`: +/// it denies every guest frame, host loopback, and inbound access, and keeps +/// no proxy endpoint. +/// +/// A capture with `--network-egress deny` and `--host-loopback deny`, without +/// rules, a proxy, or ingress, records this policy. Its guest learned no DNS +/// server and announces no listeners, and its endpoint held no flows, +/// listeners, or forwards, so nothing in the snapshot depends on the policy +/// beyond the NIC's identity. +pub fn microvm_network_template_policy( + config: &openvmm_defs::microvm::MicrovmNetworkConfig, +) -> anyhow::Result { + use net_backend_resources::egress::EgressAction; + + Ok(config + .bind_egress_policy(net_backend_resources::egress::EgressPolicyMode::DenyAll)? + .with_host_loopback(EgressAction::Deny, None)? + .with_ingress(EgressAction::Deny) + .with_host_loopback_ingress(EgressAction::Deny)) +} + +/// Validates a restore-time policy that replaces the policy of a NIC template, +/// and returns the template's policy, which the snapshot's contract records in +/// place of `policy`. +/// +/// `saved` must record the [complete deny-all policy](microvm_network_template_policy) +/// of its own identity in the encoding that the policy has today: version 3 +/// without IPv6, or version 4 with it. Versions 0 to 2 encode neither the +/// host-loopback action nor the proxy endpoint, so no snapshot that records +/// one is a template. `policy` must be bound to the identity that `saved` +/// records, which it keeps; it may name IPv6 destinations only when that +/// identity has IPv6. +pub fn validate_microvm_network_replacement( + saved: &SnapshotMicrovmNetwork, + policy: &net_backend_resources::egress::EgressPolicy, +) -> anyhow::Result { + let config = microvm_network_config_from_snapshot(saved)?; + let template = microvm_network_template_policy(&config)?; + anyhow::ensure!( + SnapshotMicrovmNetwork::new(&config, &template) == *saved, + "snapshot network policy is not a complete deny-all, so a restore cannot replace it; capture the template with --network-egress deny and --host-loopback deny, without egress rules, a proxy, or ingress" + ); + anyhow::ensure!( + config.ipv6.is_some() || !egress_policy_names_ipv6(policy), + "restore-time egress policy names IPv6 destinations, but the snapshot network has no IPv6 identity" + ); + Ok(template) +} + +/// Returns whether `policy` has a rule for an IPv6 destination. +fn egress_policy_names_ipv6(policy: &net_backend_resources::egress::EgressPolicy) -> bool { + match policy.mode() { + net_backend_resources::egress::EgressPolicyMode::Rules { allow, deny, .. } => allow + .iter() + .chain(deny) + .any(|rule| rule.destination().is_ipv6()), + _ => false, + } +} + /// Machine composition that becomes authoritative after capture. #[derive(Clone, Debug, PartialEq, Eq, Protobuf)] #[mesh(package = "openvmm.snapshot")] @@ -3554,6 +3614,153 @@ mod tests { assert!(error.to_string().contains("predates"), "{error:#}"); } + #[test] + fn only_a_complete_deny_all_network_is_a_template() { + use net_backend_resources::egress::EgressAction; + use net_backend_resources::egress::EgressPolicyMode; + + let dual_stack = "10.0.0.2/24" + .parse::() + .unwrap(); + for (network, encoding_version) in [ + (dual_stack.clone(), 4), + // A network that predates IPv6 keeps the encoding without it. + (dual_stack.clone().without_ipv6(), 3), + ] { + let template = microvm_network_template_policy(&network).unwrap(); + assert_eq!(template.mode_name(), "deny-all"); + assert_eq!(template.host_loopback_action(), EgressAction::Deny); + assert_eq!(template.proxy_endpoint(), None); + assert_eq!(template.ingress_action(), EgressAction::Deny); + assert_eq!(template.host_loopback_ingress_action(), EgressAction::Deny); + let saved = SnapshotMicrovmNetwork::new(&network, &template); + assert_eq!(saved.egress_policy_encoding_version, encoding_version); + + // Whatever replaces the template's policy, its contract keeps it. + let open = network + .bind_egress_policy(EgressPolicyMode::AllowAll) + .unwrap() + .with_host_loopback(EgressAction::Allow, None) + .unwrap() + .with_ingress(EgressAction::Allow) + .with_host_loopback_ingress(EgressAction::Allow); + for replacement in [&template, &open] { + assert_eq!( + validate_microvm_network_replacement(&saved, replacement).unwrap(), + template + ); + } + + let gateway_proxy = format!("{}:3128", network.derived_gateway_ipv4) + .parse() + .unwrap(); + for captured in [ + // Plain deny-all egress leaves host loopback allowed. + network + .bind_egress_policy(EgressPolicyMode::DenyAll) + .unwrap(), + network + .bind_egress_policy(EgressPolicyMode::DenyAll) + .unwrap() + .with_host_loopback(EgressAction::Deny, Some(gateway_proxy)) + .unwrap(), + template.clone().with_ingress(EgressAction::Allow), + template + .clone() + .with_host_loopback_ingress(EgressAction::Allow), + // Rules that deny every destination are not a deny-all. + network + .bind_egress_policy(EgressPolicyMode::Rules { + default_action: EgressAction::Deny, + allow: Vec::new(), + deny: vec!["0.0.0.0/0".parse().unwrap()], + }) + .unwrap() + .with_host_loopback(EgressAction::Deny, None) + .unwrap(), + network + .bind_egress_policy(EgressPolicyMode::AllowAll) + .unwrap() + .with_host_loopback(EgressAction::Deny, None) + .unwrap(), + ] { + let saved = SnapshotMicrovmNetwork::new(&network, &captured); + let error = validate_microvm_network_replacement(&saved, &template).unwrap_err(); + assert!( + error.to_string().contains("not a complete deny-all"), + "{error:#}" + ); + } + } + + // Encodings before version 3 cannot tell a complete deny-all from one + // with host loopback or a proxy, so they never record a template. + let ipv4_only = dual_stack.without_ipv6(); + let template = microvm_network_template_policy(&ipv4_only).unwrap(); + for version in [0, 1, 2] { + let mut saved = SnapshotMicrovmNetwork::new(&ipv4_only, &template); + saved.egress_policy_encoding_version = version; + saved.egress_policy_sha256 = sha2::Sha256::digest( + template + .canonical_bytes_for_version(version.max(1)) + .unwrap(), + ) + .to_vec(); + validate_microvm_network_policy(&saved, &template).unwrap(); + let error = validate_microvm_network_replacement(&saved, &template).unwrap_err(); + assert!( + error.to_string().contains("not a complete deny-all"), + "{error:#}" + ); + } + + // The template's identity must be canonical. + let mut saved = SnapshotMicrovmNetwork::new(&ipv4_only, &template); + saved.guest_mac[5] ^= 1; + let error = validate_microvm_network_replacement(&saved, &template).unwrap_err(); + assert!(error.to_string().contains("not canonical"), "{error:#}"); + } + + #[test] + fn a_template_replacement_names_ipv6_only_with_an_ipv6_identity() { + use net_backend_resources::egress::EgressAction; + use net_backend_resources::egress::EgressPolicyMode; + + let rules = |allow: &str| EgressPolicyMode::Rules { + default_action: EgressAction::Deny, + allow: vec![allow.parse().unwrap()], + deny: Vec::new(), + }; + let dual_stack = "10.0.0.2/24" + .parse::() + .unwrap(); + let saved = SnapshotMicrovmNetwork::new( + &dual_stack, + µvm_network_template_policy(&dual_stack).unwrap(), + ); + for allow in ["2001:db8::/32:tcp:443", "192.0.2.0/24:tcp:443"] { + let policy = dual_stack.bind_egress_policy(rules(allow)).unwrap(); + validate_microvm_network_replacement(&saved, &policy).unwrap(); + } + + // A template whose network predates IPv6 keeps that identity, so a + // replacement cannot reach IPv6 destinations. + let ipv4_only = dual_stack.without_ipv6(); + let saved = SnapshotMicrovmNetwork::new( + &ipv4_only, + µvm_network_template_policy(&ipv4_only).unwrap(), + ); + let ipv4_rules = ipv4_only + .bind_egress_policy(rules("192.0.2.0/24:tcp:443")) + .unwrap(); + validate_microvm_network_replacement(&saved, &ipv4_rules).unwrap(); + let ipv6_rules = ipv4_only + .bind_egress_policy(rules("2001:db8::/32:tcp:443")) + .unwrap(); + let error = validate_microvm_network_replacement(&saved, &ipv6_rules).unwrap_err(); + assert!(error.to_string().contains("no IPv6 identity"), "{error:#}"); + } + #[test] fn generated_microvm_filesystem_contract_has_fixed_abi() { for source_hypervisor in ["kvm", "mshv", "whp"] { From 57d0a18b3b542dce3f0787e60f3c48296b40d30e Mon Sep 17 00:00:00 2001 From: Pedro Henrique Penna Date: Tue, 27 Oct 2026 09:49:09 -0700 Subject: [PATCH 2/2] microVM: let a platform restore install a new policy on a NIC template A platform restore takes its NIC's identity from the snapshot and requires the captured policy, and every snapshot rejects private-network ingress, explicit host-loopback access, and host-loopback forwards, whose listeners and bound ports are live host attachments. One template therefore served one network policy, and none with inbound access. Add --restore-network-policy, with which a platform restore installs the network policy of its own options in place of the complete deny-all that its NIC template was captured with. The NIC keeps its captured identity: the restore binds the policy to it, as it binds a matching policy today, and still rejects --net. The same code as at a cold boot validates the policy, so the checks of its proxy, endpoints, rules, ingress, and forwards are a cold boot's, and only the IPv6 rule of validate_microvm_network_replacement is new. The device installs the policy when it is built, and the endpoint binds its forwards when it is resolved, both before any vCPU runs, so the restored guest never runs under the template's policy or a partial one, and a forward that cannot bind its port fails the restore. A restore that wants no connectivity passes the template's deny-all. The restore contract still compares the whole network record exactly: it expects the template's deny-all, which the record must hold, rather than the installed policy. The option therefore admits only a platform snapshot, which prepare_restore checks, with a NIC, which effective_microvm_network checks, whose record is the complete deny-all of its identity. Every other restore, of any tier, keeps the same-policy rule, and so does a template's restore without the option. With the option, a restore may also publish the guest's listeners and forward host ports: the snapshot refusals of --network-ingress allow, --host-loopback allow, and --host-loopback-forward admit such a restore, and keep refusing captures and every other restore. The option is refused on a cold boot, where clap's requirement of --restore-snapshot does not hold once --kernel is present, and on a standard machine. The guest keeps its captured command line, which has no virtnet_dns= or virtnet_ingress= token under a deny-all policy, so it learns its DNS server and whether to announce its listeners from its host after the restore. Unit tests cover the CLI rules, the restore's tier check, and restores of one template with eight policies: the template's deny-all, allow-all egress, IPv4 and IPv6 rules, exact endpoints, a proxy, explicit host loopback with TCP and UDP forwards, and private-network ingress with and without host loopback. Each installs the requested policy, keeps the identity, and expects the template's contract. They also cover the refusals of a snapshot that is not a template, of one without a NIC, of a proxy or endpoint that does not suit the captured identity, of a new address, and of IPv6 rules on a template that predates IPv6, and that a template's restore without the option keeps its policy. The CLI reference, the snapshot guide, and the snapshot format describe the option. See microsoft/nvx#536. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Guide/src/dev_guide/snapshot_format.md | 6 + Guide/src/reference/openvmm/management/cli.md | 50 ++- Guide/src/user_guide/openvmm/snapshots.md | 10 +- openvmm/openvmm_entry/src/cli_args/microvm.rs | 160 ++++++++- openvmm/openvmm_entry/src/microvm/config.rs | 4 +- openvmm/openvmm_entry/src/microvm/mod.rs | 5 +- openvmm/openvmm_entry/src/microvm/network.rs | 304 +++++++++++++++++- openvmm/openvmm_entry/src/microvm/restore.rs | 49 ++- 8 files changed, 552 insertions(+), 36 deletions(-) diff --git a/Guide/src/dev_guide/snapshot_format.md b/Guide/src/dev_guide/snapshot_format.md index ee5df5860ab..10917ca110f 100644 --- a/Guide/src/dev_guide/snapshot_format.md +++ b/Guide/src/dev_guide/snapshot_format.md @@ -50,6 +50,12 @@ bound egress policy. Encoding version 2 includes the static prefix, guest MAC, and canonical ARP next-hop set in addition to the policy rules. An absent encoding-version field denotes version 1, allowing network snapshots produced before endpoint next-hop binding to retain their original digest semantics. +A platform snapshot whose digest is that of the complete deny-all policy bound +to its identity, in encoding version 3, or version 4 with IPv6, is a NIC +template, whose restore may install another policy with +`--restore-network-policy`. Earlier encodings do not record the host-loopback +action or the proxy endpoint, so they never identify a template, and the +format records nothing else for it. ## Device state (`state.bin`) diff --git a/Guide/src/reference/openvmm/management/cli.md b/Guide/src/reference/openvmm/management/cli.md index c89d713b696..95aa187ec0d 100644 --- a/Guide/src/reference/openvmm/management/cli.md +++ b/Guide/src/reference/openvmm/management/cli.md @@ -166,8 +166,9 @@ describes the source definitions. each announced port, relaying only peers whose addresses are not globally reachable. Globally reachable peers are refused, and so is the host itself unless `--host-loopback allow` admits it. Replies to admitted peers pass - regardless of the egress policy. Snapshot capture and restore reject ingress - `allow`, because its listeners are live host attachments. + regardless of the egress policy. Snapshot capture rejects ingress `allow`, + because its listeners are live host attachments, and so does a restore, + unless it installs a new policy with `--restore-network-policy`. Egress `allow` may accompany `--block-host`; egress `deny` may accompany `--allow-host` or `--allow-endpoint`. Contradictory default and rule @@ -213,8 +214,10 @@ describes the source definitions. loopback at each announced port, never displacing a host listener that already holds the port. Replies to the host pass regardless of the egress policy. With `--network-ingress allow`, the listeners published to the - host's private networks admit the host instead. Snapshot capture and restore - reject explicit `allow`, because its listeners are live host attachments. + host's private networks admit the host instead. Snapshot capture rejects + explicit `allow`, because its listeners are live host attachments, and so + does a restore, unless it installs a new policy with + `--restore-network-policy`. Omitting the option preserves the existing guest-gateway-to-host-loopback mapping, from the IPv4 gateway to host IPv4 loopback and from the IPv6 gateway to host IPv6 loopback, without publishing guest ports. `deny` blocks @@ -231,17 +234,19 @@ describes the source definitions. port and forwards it into the guest, possibly to another guest port. It requires explicit `--host-loopback allow`; duplicate bindings and more than 64 forwards are rejected before resources are opened. Live forwards are - process-local attachments and are rejected for snapshot capture or restore. + process-local attachments: snapshot capture rejects them, and so does a + restore, unless it installs a new policy with `--restore-network-policy`. Networked snapshots record the `portable` profile, drain accepted TX and endpoint-ready RX at the capture boundary, rewind unused guest RX descriptors, and recreate a fresh Consomme endpoint generation on restore. - Restore of a networked snapshot requires `--network-profile portable` and - the same active egress policy rules. The policy digest binds the saved static - identity, including the IPv6 identity, and its derived ARP next hops, which - are reconstructed before vCPUs start. A snapshot whose network predates IPv6 - restores IPv4-only, with its original digest. Native sockets and NAT flow - tables are not serialized. The capture + Restore of a networked snapshot requires `--network-profile portable` and, + unless `--restore-network-policy` replaces a platform snapshot's complete + deny-all, the same active egress policy rules. The policy digest binds the + saved static identity, including the IPv6 identity, and its derived ARP + next hops, which are reconstructed before vCPUs start. A snapshot whose + network predates IPv6 restores IPv4-only, with its original digest. Native + sockets and NAT flow tables are not serialized. The capture protocol does not retain pre-capture endpoint completions; restored guest software must establish new host-side flows. * `--mount `: With `--machine microvm`, attach @@ -447,7 +452,8 @@ describes the source definitions. When the snapshot contains virtio-net, restore also requires `--network-profile portable`; the snapshot's profile and canonical egress - policy must match the supplied portable configuration. + policy must match the supplied portable configuration, unless + `--restore-network-policy` installs a new policy on a platform snapshot. For sandbox-block snapshots, restore repeats each read-only `--microvm-sandbox-block` argument. Its role, access, geometry, and SHA-256 @@ -519,6 +525,26 @@ describes the source definitions. for a cold boot, for a paired snapshot or one without sandbox blocks, and together with a scratch `--microvm-sandbox-block`. A scratch file, when given instead, keeps the exact captured length. +* `--restore-network-policy`: Restore a platform snapshot's NIC with the + network policy of this restore's options rather than the captured one. The + snapshot must be a NIC template: a platform snapshot whose NIC was captured + with a complete deny-all policy, `--network-egress deny` and + `--host-loopback deny` without egress rules, `--network-proxy`, or + ingress. Its guest learned no DNS server and announces no listeners, and its + endpoint held no flows, listeners, or forwards, so its clones may each + install their own policy, including `--network-ingress allow`, explicit + `--host-loopback allow`, and `--host-loopback-forward`. OpenVMM validates the + policy as at a cold boot, binds it to the captured identity, which the NIC + keeps, and installs it, with its forwards bound, before any vCPU runs; a + policy that fails validation, or a forward that cannot bind its port, fails + the restore. A restore that wants no connectivity passes the template's own + deny-all. The restore cannot readdress the NIC, and a policy may name IPv6 + destinations only when the captured identity has IPv6. OpenVMM rejects the + option before any vCPU starts for a cold boot, for a snapshot of another + tier, for a snapshot without a NIC, and for a NIC captured with any other + policy, including one whose digest encoding predates version 3. The guest + keeps its captured command line, so it learns its DNS server and whether + to announce its listeners from its host, after the restore. * `--restore-gate-timeout-ms `: Bound microVM guest repair and gate acknowledgement after restore. The default is 60000 milliseconds. * `--cpu-profile `: Select the microVM's pinned CPU profile, `auto` diff --git a/Guide/src/user_guide/openvmm/snapshots.md b/Guide/src/user_guide/openvmm/snapshots.md index 84a7021f015..96880f5e7ec 100644 --- a/Guide/src/user_guide/openvmm/snapshots.md +++ b/Guide/src/user_guide/openvmm/snapshots.md @@ -198,7 +198,15 @@ then attaches the scratch device with no file, at the captured length and block sizes. The device stays writable, as the guest negotiated it, but reads return zeros and writes fail with an I/O error: OpenVMM never drops a write or keeps one in host memory. Only a platform snapshot's fresh scratch may be -absent, and a scratch file, when given, keeps the exact captured length. An instance-checkpoint restore attempt atomically creates +absent, and a scratch file, when given, keeps the exact captured length. A +platform snapshot whose NIC was captured with a complete deny-all policy, +`--network-egress deny` and `--host-loopback deny` without egress rules, a +proxy, or ingress, is a NIC template: with `--restore-network-policy`, each +clone installs the policy of its own restore options, which may publish its +listeners and forward host ports, instead of the captured one. OpenVMM +validates that policy as at a cold boot and installs it before any vCPU runs, +and the NIC keeps its captured identity. Every other networked restore +requires the captured policy. An instance-checkpoint restore attempt atomically creates `resume.claim`; subsequent restores are rejected. The claim is committed after artifact and configuration validation but before worker construction, so the restore attempt remains consumed if later worker startup fails. diff --git a/openvmm/openvmm_entry/src/cli_args/microvm.rs b/openvmm/openvmm_entry/src/cli_args/microvm.rs index 710b8890edd..182ec4216f9 100644 --- a/openvmm/openvmm_entry/src/cli_args/microvm.rs +++ b/openvmm/openvmm_entry/src/cli_args/microvm.rs @@ -296,6 +296,18 @@ pub struct MicrovmCli { #[clap(long, requires = "restore_snapshot")] pub restore_absent_scratch: bool, + /// Install this restore's network policy in place of the complete + /// deny-all policy that a platform snapshot's NIC was captured with. + /// + /// The NIC keeps its captured identity. The network policy options of + /// this restore, which may include `--network-ingress allow`, + /// `--host-loopback allow`, and `--host-loopback-forward`, are validated + /// as at a cold boot, and the policy is installed before any vCPU runs. + /// The snapshot must have been captured with `--network-egress deny` and + /// `--host-loopback deny`, without egress rules, a proxy, or ingress. + #[clap(long, requires = "restore_snapshot")] + pub restore_network_policy: bool, + /// Maximum time allowed for a microVM guest to complete post-restore repair. #[clap(long, value_name = "MILLISECONDS", default_value_t = 60000)] pub restore_gate_timeout_ms: u64, @@ -386,7 +398,8 @@ pub struct MicrovmCli { /// addresses are not globally reachable. Globally reachable clients are /// refused, and so is the host itself unless `--host-loopback allow` /// admits it. Replies to admitted traffic pass regardless of the egress - /// policy. Snapshots do not support it. + /// policy. Snapshot capture does not support it, and a restore supports it + /// only with `--restore-network-policy`. #[clap(long, value_enum, value_name = "ACTION")] pub network_ingress: Option, @@ -416,7 +429,8 @@ pub struct MicrovmCli { /// replies to the host pass regardless of the egress policy. With /// `--network-ingress allow`, the listeners published to the host's /// private networks admit the host instead. Explicit forwards may publish - /// further ports. Snapshots do not support explicit `allow`. + /// further ports. Snapshot capture does not support explicit `allow`, and + /// a restore supports it only with `--restore-network-policy`. #[clap(long, value_enum, value_name = "ACTION")] pub host_loopback: Option, @@ -741,12 +755,22 @@ impl Options { anyhow::ensure!( self.machine != MachineProfileCli::Microvm || self.microvm.host_loopback != Some(MicrovmNetworkActionCli::Allow) - || (self.microvm.snapshot_destination.is_none() && self.restore_snapshot.is_none()), - "microVM snapshots do not support --host-loopback allow, whose published guest listeners are live host attachments" + || self.microvm_admits_live_network_attachments(), + "microVM snapshots do not support --host-loopback allow, whose published guest listeners are live host attachments, except at a restore with --restore-network-policy" ); Ok(()) } + /// Returns whether this launch may create live network attachments: the + /// guest listeners that ingress and explicit host-loopback access publish, + /// and host-loopback forwards. A snapshot cannot capture them, so a launch + /// may create them unless it captures one, and a restore only when it + /// installs a new policy with `--restore-network-policy`. + fn microvm_admits_live_network_attachments(&self) -> bool { + self.microvm.snapshot_destination.is_none() + && (self.restore_snapshot.is_none() || self.microvm.restore_network_policy) + } + pub(crate) fn validate_microvm_options(&self) -> anyhow::Result<()> { self.validate_microvm_host_loopback()?; if self.machine != MachineProfileCli::Microvm { @@ -777,13 +801,14 @@ impl Options { && self.microvm.restore_processors.is_none() && self.microvm.restore_memory.is_none() && !self.microvm.restore_absent_scratch + && !self.microvm.restore_network_policy && self.microvm.memory_capacity.is_none() && self.microvm.snapshot_block_identity.is_none() && self.microvm.snapshot_generation_id.is_none() && self.microvm.snapshot_scratch_restore_mode.is_none() && self.microvm.microvm_control_console.is_none() && !self.microvm.microvm_control_auth_stdin, - "--network-profile, --net-tap, --mount, --mount-aggregate, --microvm-sandbox-block, --microvm-workload-identity, --microvm-lifecycle, --microvm-control-console, --microvm-control-auth-stdin, --restore-processors, --restore-memory, --restore-absent-scratch, --memory-capacity, snapshot block policy, and microVM network policy require a microVM machine" + "--network-profile, --net-tap, --mount, --mount-aggregate, --microvm-sandbox-block, --microvm-workload-identity, --microvm-lifecycle, --microvm-control-console, --microvm-control-auth-stdin, --restore-processors, --restore-memory, --restore-absent-scratch, --restore-network-policy, --memory-capacity, snapshot block policy, and microVM network policy require a microVM machine" ); return Ok(()); } @@ -900,11 +925,15 @@ impl Options { } // Clap's `requires` does not hold when an option that conflicts with // --restore-snapshot, such as --kernel, is present, so a cold boot - // would otherwise ignore the declaration. + // would otherwise ignore these declarations. anyhow::ensure!( self.restore_snapshot.is_some() || !self.microvm.restore_absent_scratch, "--restore-absent-scratch requires --restore-snapshot" ); + anyhow::ensure!( + self.restore_snapshot.is_some() || !self.microvm.restore_network_policy, + "--restore-network-policy requires --restore-snapshot" + ); if self.restore_snapshot.is_some() { anyhow::ensure!( self.microvm.microvm_workload_identity.is_none(), @@ -1241,8 +1270,8 @@ impl Options { ); anyhow::ensure!( self.microvm.network_ingress != Some(MicrovmNetworkActionCli::Allow) - || (self.microvm.snapshot_destination.is_none() && self.restore_snapshot.is_none()), - "microVM snapshots do not support --network-ingress allow, whose published guest listeners are live host attachments" + || self.microvm_admits_live_network_attachments(), + "microVM snapshots do not support --network-ingress allow, whose published guest listeners are live host attachments, except at a restore with --restore-network-policy" ); anyhow::ensure!( self.microvm.network_egress_allow.len() <= 256 @@ -1259,8 +1288,8 @@ impl Options { "--host-loopback-forward requires explicit --host-loopback allow" ); anyhow::ensure!( - self.microvm.snapshot_destination.is_none() && self.restore_snapshot.is_none(), - "microVM snapshots do not support live host-loopback port forwards" + self.microvm_admits_live_network_attachments(), + "microVM snapshots do not support live host-loopback port forwards, except at a restore with --restore-network-policy" ); let mut forwards = self.microvm.host_loopback_forward.clone(); forwards.sort_unstable(); @@ -1646,6 +1675,66 @@ mod tests { assert!(standard.validate_microvm_options().is_err()); } + #[cfg(guest_arch = "x86_64")] + #[test] + fn test_microvm_restore_network_policy_requires_a_microvm_restore() { + let restore = Options::try_parse_from([ + "openvmm", + "--machine", + "microvm", + "--restore-snapshot", + "snapshot", + "--network-profile", + "portable", + "--restore-network-policy", + ]) + .unwrap(); + restore.validate_microvm_options().unwrap(); + assert!(restore.microvm.restore_network_policy); + + // A cold boot has no captured policy to replace. + assert!( + Options::try_parse_from([ + "openvmm", + "--machine", + "microvm", + "--restore-network-policy", + ]) + .is_err() + ); + // Clap accepts it when --kernel, which conflicts with --restore-snapshot, + // lifts the requirement, so the validation refuses it. + let cold_boot = Options::try_parse_from([ + "openvmm", + "--machine", + "microvm", + "--kernel", + "vmlinux", + "--net", + "10.0.0.2/24", + "--network-profile", + "portable", + "--restore-network-policy", + ]) + .unwrap(); + assert_eq!( + cold_boot + .validate_microvm_options() + .unwrap_err() + .to_string(), + "--restore-network-policy requires --restore-snapshot" + ); + // Nor does a standard machine. + let standard = Options::try_parse_from([ + "openvmm", + "--restore-snapshot", + "snapshot", + "--restore-network-policy", + ]) + .unwrap(); + assert!(standard.validate_microvm_options().is_err()); + } + #[cfg(guest_arch = "x86_64")] #[test] fn test_microvm_sandbox_block_parser_and_validation() { @@ -2422,18 +2511,42 @@ mod tests { assert_eq!(policy.host_loopback_ingress_action(), EgressAction::Allow); assert_eq!(options.microvm_private_network_ingress(), None); } - // Snapshots cannot carry published listeners. + // Snapshots cannot carry published listeners: neither a capture nor a + // restore that keeps the captured policy may publish them. for extra in [ vec!["--net", "10.0.0.2/24", "--snapshot-destination", "snapshot"], vec!["--restore-snapshot", "snapshot"], ] { let options = Options::try_parse_from(common.into_iter().chain(extra)).unwrap(); - let error = options.validate_microvm_options().unwrap_err(); - assert!( - error.to_string().contains("--host-loopback allow"), - "{error}" - ); + for error in [ + options.validate_microvm_host_loopback().unwrap_err(), + options.validate_microvm_options().unwrap_err(), + ] { + assert!( + error.to_string().contains("--host-loopback allow"), + "{error}" + ); + } } + // A restore that installs a new policy may, as a cold boot may, with + // forwards. + let replacement = Options::try_parse_from(common.into_iter().chain([ + "--restore-snapshot", + "snapshot", + "--restore-network-policy", + "--host-loopback-forward", + "tcp:3000:8080", + ])) + .unwrap(); + replacement.validate_microvm_host_loopback().unwrap(); + replacement.validate_microvm_options().unwrap(); + let mut kept = replacement; + kept.microvm.restore_network_policy = false; + let error = kept.validate_microvm_options().unwrap_err(); + assert!( + error.to_string().contains("--host-loopback allow"), + "{error}" + ); // Omitted or denied host loopback publishes nothing. for host_loopback in [None, Some("deny")] { let options = Options::try_parse_from( @@ -3185,7 +3298,8 @@ mod tests { ); assert_eq!(denied.microvm_private_network_ingress(), None); - // Snapshots cannot carry published listeners. + // Snapshots cannot carry published listeners: neither a capture nor a + // restore that keeps the captured policy may publish them. for arguments in [ [ "--net", @@ -3210,6 +3324,18 @@ mod tests { "{error}" ); } + // A restore that installs a new policy may, as a cold boot may. + parse(&[ + "--restore-snapshot", + "snapshot", + "--restore-network-policy", + "--network-ingress", + "allow", + "--host-loopback", + "allow", + ]) + .validate_microvm_options() + .unwrap(); } #[test] diff --git a/openvmm/openvmm_entry/src/microvm/config.rs b/openvmm/openvmm_entry/src/microvm/config.rs index 7a10f11926f..e9fc9298d4c 100644 --- a/openvmm/openvmm_entry/src/microvm/config.rs +++ b/openvmm/openvmm_entry/src/microvm/config.rs @@ -202,7 +202,9 @@ impl<'a> MicrovmConfigBuilder<'a> { .as_ref() .map(|(_, _, attachment)| attachment.clone()), network_attachment: network.as_ref().map(|network| network.attachment.clone()), - egress_policy: network.as_ref().map(|network| network.policy.clone()), + egress_policy: network + .as_ref() + .map(|network| network.contract_policy.clone()), filesystem: filesystem .as_ref() .map(|filesystem| super::MicrovmFilesystemHost { diff --git a/openvmm/openvmm_entry/src/microvm/mod.rs b/openvmm/openvmm_entry/src/microvm/mod.rs index f68c40ccd1c..2d86ac08aa1 100644 --- a/openvmm/openvmm_entry/src/microvm/mod.rs +++ b/openvmm/openvmm_entry/src/microvm/mod.rs @@ -106,7 +106,10 @@ pub(crate) struct MicrovmResources { pub(crate) control_console_socket_cleanup: Option, /// Snapshot identity of the portable network attachment. pub(crate) network_attachment: Option, - /// The bound run-scoped egress policy. + /// The egress policy that the snapshot contract records: the bound + /// run-scoped policy, except at a restore with `--restore-network-policy`, + /// where it is the complete deny-all of the template whose policy the + /// restore replaces. pub(crate) egress_policy: Option, /// The live host side of the attached filesystem. pub(crate) filesystem: Option, diff --git a/openvmm/openvmm_entry/src/microvm/network.rs b/openvmm/openvmm_entry/src/microvm/network.rs index 069de2ec567..77cd6404838 100644 --- a/openvmm/openvmm_entry/src/microvm/network.rs +++ b/openvmm/openvmm_entry/src/microvm/network.rs @@ -15,10 +15,15 @@ use vm_resource::kind::NetEndpointHandleKind; const MICROVM_NETWORK_STABLE_ID: &str = "net:microvm0"; -#[derive(Clone)] +#[derive(Clone, Debug)] pub(super) struct EffectiveMicrovmNetwork { pub(super) config: openvmm_defs::microvm::MicrovmNetworkConfig, + /// The policy that the device installs before any vCPU runs. pub(super) policy: net_backend_resources::egress::EgressPolicy, + /// The policy that the snapshot contract records: `policy`, except at a + /// restore with `--restore-network-policy`, where `policy` replaces the + /// template's complete deny-all, which the contract keeps. + pub(super) contract_policy: net_backend_resources::egress::EgressPolicy, pub(super) attachment: openvmm_helpers::snapshot::microvm::SnapshotAttachment, } @@ -59,6 +64,7 @@ pub(super) fn effective_microvm_network( let policy = opt.microvm_egress_policy(&config)?; Ok(EffectiveMicrovmNetwork { config, + contract_policy: policy.clone(), policy, attachment: microvm_network_attachment(), }) @@ -83,6 +89,10 @@ pub(super) fn effective_microvm_network( "snapshot microVM network device, identity, and attachment inventories disagree" ); let Some(saved) = restore.microvm_network.as_ref() else { + anyhow::ensure!( + !opt.microvm.restore_network_policy, + "--restore-network-policy requires a snapshot with a NIC" + ); anyhow::ensure!( opt.microvm.network_profile.is_none() && opt.microvm.net_tap.is_none() @@ -109,8 +119,15 @@ pub(super) fn effective_microvm_network( "networked microVM snapshot restore requires --network-profile portable" ); let config = microvm_network_from_snapshot(saved)?; + // The restore binds its policy to the captured identity, which a template + // keeps whatever policy replaces its own. let policy = opt.microvm_egress_policy(&config)?; - openvmm_helpers::snapshot::microvm::validate_microvm_network_policy(saved, &policy)?; + let contract_policy = if opt.microvm.restore_network_policy { + openvmm_helpers::snapshot::microvm::validate_microvm_network_replacement(saved, &policy)? + } else { + openvmm_helpers::snapshot::microvm::validate_microvm_network_policy(saved, &policy)?; + policy.clone() + }; let attachment = microvm_network_attachment(); anyhow::ensure!( Some(&attachment) == saved_attachment, @@ -119,6 +136,7 @@ pub(super) fn effective_microvm_network( Ok(Some(EffectiveMicrovmNetwork { config, policy, + contract_policy, attachment, })) } @@ -217,6 +235,26 @@ pub(crate) mod tests { ]), ) .unwrap(); + contract_with_policy(network, &policy) + } + + /// Returns the contract of a platform template whose NIC has the identity + /// `network` and the complete deny-all policy. + fn template_contract_for( + network: &openvmm_defs::microvm::MicrovmNetworkConfig, + ) -> openvmm_helpers::snapshot::microvm::SnapshotMachineContract { + contract_with_policy( + network, + &openvmm_helpers::snapshot::microvm::microvm_network_template_policy(network).unwrap(), + ) + } + + /// Returns the contract of a snapshot whose NIC has the identity `network` + /// and was captured with `policy`. + fn contract_with_policy( + network: &openvmm_defs::microvm::MicrovmNetworkConfig, + policy: &net_backend_resources::egress::EgressPolicy, + ) -> openvmm_helpers::snapshot::microvm::SnapshotMachineContract { let source_hypervisor = if cfg!(windows) { "whp" } else { "kvm" }; let irq = openvmm_defs::microvm::microvm_virtio_net_irq(Some(source_hypervisor)).unwrap(); let mut command_line = build_microvm_command_line(&[], false).unwrap(); @@ -234,7 +272,7 @@ pub(crate) mod tests { source_hypervisor, openvmm_helpers::snapshot::microvm::MICROVM_BOOT_LAYOUT_VERSION, command_line, - Some((network, &policy, microvm_network_attachment())), + Some((network, policy, microvm_network_attachment())), false, None, None, @@ -455,4 +493,264 @@ pub(crate) mod tests { assert_eq!(microvm_ingress(&policy), expected, "{arguments:?}"); } } + + /// Parses the options of a networked restore with `arguments`. + fn restore_options(arguments: &[&str]) -> Options { + Options::try_parse_from( + [ + "openvmm", + "--machine", + "microvm", + "--restore-snapshot", + "snapshot", + "--network-profile", + "portable", + ] + .into_iter() + .chain(arguments.iter().copied()), + ) + .unwrap() + } + + #[cfg(guest_arch = "x86_64")] + #[test] + fn a_complete_deny_all_capture_records_a_template() { + let network: openvmm_defs::microvm::MicrovmNetworkConfig = "10.0.0.2/24".parse().unwrap(); + let template = + openvmm_helpers::snapshot::microvm::microvm_network_template_policy(&network).unwrap(); + let capture = |arguments: &[&str]| { + let options = Options::try_parse_from( + [ + "openvmm", + "--machine", + "microvm", + "--net", + "10.0.0.2/24", + "--network-profile", + "portable", + "--snapshot-destination", + "snapshot", + ] + .into_iter() + .chain(arguments.iter().copied()), + ) + .unwrap(); + options.validate_microvm_options().unwrap(); + options.microvm_egress_policy(&network).unwrap() + }; + assert_eq!( + capture(&["--network-egress", "deny", "--host-loopback", "deny"]), + template + ); + // Deny-all egress alone leaves host loopback allowed. + assert_ne!(capture(&["--network-egress", "deny"]), template); + } + + #[cfg(guest_arch = "x86_64")] + #[test] + fn a_template_restore_installs_a_new_policy_and_keeps_the_identity() { + let network: openvmm_defs::microvm::MicrovmNetworkConfig = "10.0.0.2/24".parse().unwrap(); + let contract = template_contract_for(&network); + let template = + openvmm_helpers::snapshot::microvm::microvm_network_template_policy(&network).unwrap(); + for arguments in [ + // A clone without connectivity keeps the template's policy. + &["--network-egress", "deny", "--host-loopback", "deny"][..], + &["--network-egress", "allow"][..], + &[ + "--network-egress", + "deny", + "--network-egress-allow", + "10.0.0.1/32:tcp:8080", + "--network-egress-allow", + "fd00::a00:1/128:tcp:8080", + "--host-loopback", + "deny", + ][..], + &[ + "--network-egress", + "deny", + "--allow-endpoint", + "192.0.2.7:443", + ][..], + &[ + "--network-egress", + "deny", + "--host-loopback", + "deny", + "--network-proxy", + "10.0.0.1:3128", + ][..], + &[ + "--network-egress", + "deny", + "--host-loopback", + "allow", + "--host-loopback-forward", + "tcp:3000:8080", + "--host-loopback-forward", + "udp:3000:8080", + ][..], + &["--network-ingress", "allow"][..], + &["--network-ingress", "allow", "--host-loopback", "allow"][..], + ] { + let options = restore_options(&[&["--restore-network-policy"][..], arguments].concat()); + options.validate_microvm_options().unwrap(); + let restored = effective_microvm_network(&options, Some(&contract)) + .unwrap() + .unwrap(); + // The device installs the requested policy, bound to the + // template's identity, which the contract checks with the + // template's policy. + assert_eq!(restored.config, network, "{arguments:?}"); + assert_eq!( + restored.policy, + options.microvm_egress_policy(&network).unwrap(), + "{arguments:?}" + ); + assert_eq!(restored.contract_policy, template, "{arguments:?}"); + assert_eq!( + contract_with_policy(&restored.config, &restored.contract_policy).microvm_network, + contract.microvm_network, + "{arguments:?}" + ); + } + let deny_all = restore_options(&[ + "--restore-network-policy", + "--network-egress", + "deny", + "--host-loopback", + "deny", + ]); + let restored = effective_microvm_network(&deny_all, Some(&contract)) + .unwrap() + .unwrap(); + assert_eq!(restored.policy, template); + + // Without the option, the template's restore keeps its policy. + let kept = effective_microvm_network( + &restore_options(&["--network-egress", "deny", "--host-loopback", "deny"]), + Some(&contract), + ) + .unwrap() + .unwrap(); + assert_eq!(kept.policy, template); + assert_eq!(kept.contract_policy, template); + let error = effective_microvm_network( + &restore_options(&["--network-egress", "allow"]), + Some(&contract), + ) + .unwrap_err(); + assert!(error.to_string().contains("does not match"), "{error:#}"); + } + + #[test] + fn only_a_template_admits_a_new_policy() { + let network: openvmm_defs::microvm::MicrovmNetworkConfig = "10.0.0.2/24".parse().unwrap(); + let replacement = + restore_options(&["--restore-network-policy", "--network-egress", "allow"]); + let deny_all_with_host_loopback = network + .bind_egress_policy(net_backend_resources::egress::EgressPolicyMode::DenyAll) + .unwrap(); + for contract in [ + network_contract(), + contract_with_policy(&network, &deny_all_with_host_loopback), + ] { + let error = effective_microvm_network(&replacement, Some(&contract)).unwrap_err(); + assert!( + error.to_string().contains("not a complete deny-all"), + "{error:#}" + ); + } + + // A template without a NIC has no policy to replace. + let mut contract = template_contract_for(&network); + contract.microvm_network = None; + contract + .devices + .retain(|device| device.stable_id != MICROVM_NETWORK_STABLE_ID); + contract + .attachments + .retain(|attachment| attachment.stable_id != MICROVM_NETWORK_STABLE_ID); + let error = effective_microvm_network(&replacement, Some(&contract)).unwrap_err(); + assert_eq!( + error.to_string(), + "--restore-network-policy requires a snapshot with a NIC" + ); + } + + #[test] + fn a_template_restore_binds_its_policy_to_the_captured_identity() { + let network: openvmm_defs::microvm::MicrovmNetworkConfig = "10.0.0.2/24".parse().unwrap(); + let contract = template_contract_for(&network); + for (arguments, expected) in [ + // The proxy and the endpoints must suit the captured identity, as + // at a cold boot. + ( + &[ + "--network-egress", + "deny", + "--host-loopback", + "deny", + "--network-proxy", + "10.0.0.9:3128", + ][..], + "must match the guest gateway", + ), + ( + &[ + "--network-egress", + "deny", + "--allow-endpoint", + "10.0.0.2:443", + ][..], + "matches the guest IPv4 address", + ), + ] { + let options = restore_options(&[&["--restore-network-policy"][..], arguments].concat()); + let error = effective_microvm_network(&options, Some(&contract)).unwrap_err(); + assert!(error.to_string().contains(expected), "{error:#}"); + } + // The restore cannot readdress the template's NIC. + let readdressed = Options::try_parse_from([ + "openvmm", + "--machine", + "microvm", + "--restore-snapshot", + "snapshot", + "--network-profile", + "portable", + "--restore-network-policy", + "--net", + "10.1.0.2/24", + ]) + .unwrap(); + let error = effective_microvm_network(&readdressed, Some(&contract)).unwrap_err(); + assert!(error.to_string().contains("from saved state"), "{error:#}"); + + // A template whose network predates IPv6 keeps no IPv6 identity. + let ipv4_only = network.without_ipv6(); + let contract = template_contract_for(&ipv4_only); + let ipv4_rules = restore_options(&[ + "--restore-network-policy", + "--network-egress", + "deny", + "--network-egress-allow", + "192.0.2.0/24:tcp:443", + ]); + let restored = effective_microvm_network(&ipv4_rules, Some(&contract)) + .unwrap() + .unwrap(); + assert_eq!(restored.config, ipv4_only); + assert!(restored.policy.ipv6_link().is_none()); + let ipv6_rules = restore_options(&[ + "--restore-network-policy", + "--network-egress", + "deny", + "--network-egress-allow", + "2001:db8::/32:tcp:443", + ]); + let error = effective_microvm_network(&ipv6_rules, Some(&contract)).unwrap_err(); + assert!(error.to_string().contains("no IPv6 identity"), "{error:#}"); + } } diff --git a/openvmm/openvmm_entry/src/microvm/restore.rs b/openvmm/openvmm_entry/src/microvm/restore.rs index e1d7c9ceb86..d02bdc4a699 100644 --- a/openvmm/openvmm_entry/src/microvm/restore.rs +++ b/openvmm/openvmm_entry/src/microvm/restore.rs @@ -200,7 +200,8 @@ pub(crate) fn restore_packet_base( /// image is replaced by a private copy, and restore gates require entropy. A /// platform snapshot's `distro` block keeps its captured capacity, whatever /// the length of the image that the restore attaches to it, and -/// `--restore-absent-scratch` attaches its fresh scratch with no file. +/// `--restore-absent-scratch` attaches its fresh scratch with no file. Only a +/// platform snapshot admits `--restore-network-policy`. pub(crate) fn prepare_restore( opt: &mut Options, restore_snapshot: Option<&OpenedSnapshot>, @@ -240,6 +241,10 @@ pub(crate) fn prepare_restore( if let Some(time) = &contract.time { openvmm_helpers::snapshot::time::validate_time_contract(time)?; } + validate_network_policy_restore( + &manifest.snapshot_tier, + opt.microvm.restore_network_policy, + )?; if let Some(restore_processors) = opt.microvm.restore_processors { openvmm_helpers::snapshot::microvm::validate_restore_online_vp_count( manifest, @@ -393,6 +398,23 @@ pub(crate) fn prepare_restore( }) } +/// Rejects `--restore-network-policy`, which `restore_network_policy` +/// reports, for a snapshot of a tier other than the platform tier. +/// +/// A platform snapshot is captured before any tenant input. Later tiers carry +/// a workload that ran under the captured policy, so they keep it. +fn validate_network_policy_restore( + snapshot_tier: &str, + restore_network_policy: bool, +) -> anyhow::Result<()> { + anyhow::ensure!( + !restore_network_policy + || snapshot_tier == openvmm_helpers::snapshot::format::SNAPSHOT_TIER_PLATFORM, + "--restore-network-policy requires a platform snapshot" + ); + Ok(()) +} + /// How a restore attaches the sandbox blocks of a snapshot. #[derive(Debug, Default, PartialEq, Eq)] struct SandboxBlockRestore<'a> { @@ -858,6 +880,31 @@ pub(crate) mod tests { ); } + #[test] + fn only_a_platform_restore_replaces_the_network_policy() { + use openvmm_helpers::snapshot::format::SNAPSHOT_TIER_INSTANCE_CHECKPOINT; + use openvmm_helpers::snapshot::format::SNAPSHOT_TIER_PLATFORM; + use openvmm_helpers::snapshot::format::SNAPSHOT_TIER_WORKLOAD_START; + + for tier in [ + SNAPSHOT_TIER_PLATFORM, + SNAPSHOT_TIER_WORKLOAD_START, + SNAPSHOT_TIER_INSTANCE_CHECKPOINT, + "", + ] { + validate_network_policy_restore(tier, false).unwrap(); + let replaced = validate_network_policy_restore(tier, true); + if tier == SNAPSHOT_TIER_PLATFORM { + replaced.unwrap(); + } else { + assert_eq!( + replaced.unwrap_err().to_string(), + "--restore-network-policy requires a platform snapshot" + ); + } + } + } + fn time_abi_restore(capture_generation: u32) -> MicrovmRestore { let mut contract: SnapshotMachineContract = mesh::payload::decode(&[]).unwrap(); contract.time = Some(SnapshotTimeContract {