From c3ae6548af0f0b4d918f750d5d0bab4826f8b958 Mon Sep 17 00:00:00 2001 From: Kevin Wang Date: Wed, 25 Nov 2026 19:58:43 -0800 Subject: [PATCH 1/2] feat(nvattest): expose signed PPCIe mode and NVSwitch lock claims A CC-off Protected PCIe launch must prove from signed evidence that the GPUs run in PPCIe mode and that every NVSwitch is locked. NVML and NSCQ report that state through the host-controlled driver. nvattest already parses both facts from the SPDM opaque data but drops them: the GPU mode derived from FEATURE_FLAG is never serialized, and SWITCH_LOCK_STATUS is never read. Patch nvattest to emit them as x-nvidia-gpu-mode and x-dstack-switch-lock-status. Signed-off-by: Kevin Wang --- .../components/nvattest/nvattest-build.sh | 2 + os/mkosi/components/nvattest/nvattest.sh | 3 +- .../0003-expose-signed-ppcie-claims.patch | 172 ++++++++++++++++++ os/mkosi/tests/acceptance.sh | 1 + 4 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 os/mkosi/components/nvattest/patches/0003-expose-signed-ppcie-claims.patch diff --git a/os/mkosi/components/nvattest/nvattest-build.sh b/os/mkosi/components/nvattest/nvattest-build.sh index cdee4b63b..33b006c91 100755 --- a/os/mkosi/components/nvattest/nvattest-build.sh +++ b/os/mkosi/components/nvattest/nvattest-build.sh @@ -41,6 +41,8 @@ patch -d "$src" -p1 --fuzz=0 < \ "$SELF/components/nvattest/patches/0001-pin-fetchcontent-inputs.patch" patch -d "$src" -p1 --fuzz=0 < \ "$SELF/components/nvattest/patches/0002-validate-ocsp-response-freshness.patch" +patch -d "$src" -p1 --fuzz=0 < \ + "$SELF/components/nvattest/patches/0003-expose-signed-ppcie-claims.patch" rm -rf "$build" export CFLAGS="${CFLAGS:-} -O2 -g0 -ffile-prefix-map=$canonical=/usr/src/nvattest -fmacro-prefix-map=$canonical=/usr/src/nvattest" diff --git a/os/mkosi/components/nvattest/nvattest.sh b/os/mkosi/components/nvattest/nvattest.sh index e31cf3a8b..bdc914478 100644 --- a/os/mkosi/components/nvattest/nvattest.sh +++ b/os/mkosi/components/nvattest/nvattest.sh @@ -9,7 +9,8 @@ component_cache_key() { key_value "$NVATTEST_VERSION" "$NVATTEST_REVISION" key_file "$COMPONENT_PATH/nvattest-build.sh" \ "$COMPONENT_PATH/patches/0001-pin-fetchcontent-inputs.patch" \ - "$COMPONENT_PATH/patches/0002-validate-ocsp-response-freshness.patch" + "$COMPONENT_PATH/patches/0002-validate-ocsp-response-freshness.patch" \ + "$COMPONENT_PATH/patches/0003-expose-signed-ppcie-claims.patch" key_tree os/yocto/layers/meta-nvidia/recipes-graphics/nvattest key_tools gcc cmake ninja rustc cargo key_packages libssl-dev libcurl4-openssl-dev diff --git a/os/mkosi/components/nvattest/patches/0003-expose-signed-ppcie-claims.patch b/os/mkosi/components/nvattest/patches/0003-expose-signed-ppcie-claims.patch new file mode 100644 index 000000000..4b10fcee4 --- /dev/null +++ b/os/mkosi/components/nvattest/patches/0003-expose-signed-ppcie-claims.patch @@ -0,0 +1,172 @@ +Subject: [PATCH] Expose signed PPCIe mode and NVSwitch lock claims + +A relying party needs to know that a CC-off Protected PCIe launch is really +in PPCIe mode with locked NVSwitches. NVML and NSCQ report that state from +the host-controlled driver, so it is not evidence. + +The signed SPDM opaque data already carries both facts. The GPU verifier +derives m_mode from FEATURE_FLAG but never serializes it, although the CLI +prints x-nvidia-gpu-mode. The switch parser reads SWITCH_LOCK_STATUS but +drops it. Emit both: x-nvidia-gpu-mode as the SDK names it, and the +little-endian lock status as x-dstack-switch-lock-status. + +Upstream-Status: Pending + +--- + .../include/nv_attestation/switch/claims.h | 1 + + .../include/nv_attestation/switch/evidence.h | 2 ++ + nv-attestation-sdk-cpp/src/gpu/claims.cpp | 5 ++++ + nv-attestation-sdk-cpp/src/switch/claims.cpp | 5 ++++ + .../src/switch/evidence.cpp | 27 +++++++++++++++++++ + nv-attestation-sdk-cpp/src/switch/verify.cpp | 1 + + 6 files changed, 41 insertions(+) + +diff --git a/nv-attestation-sdk-cpp/include/nv_attestation/switch/claims.h b/nv-attestation-sdk-cpp/include/nv_attestation/switch/claims.h +index e7f6a35..b21a00c 100644 +--- a/nv-attestation-sdk-cpp/include/nv_attestation/switch/claims.h ++++ b/nv-attestation-sdk-cpp/include/nv_attestation/switch/claims.h +@@ -45,6 +45,7 @@ class SerializableSwitchClaimsV3 : public Claims { + std::string m_switch_bios_version; + std::string m_switch_pdi; + std::vector m_switch_gpu_pdis; ++ std::shared_ptr m_switch_lock_status; + + // AR claims + SerializableCertChainClaims m_ar_cert_chain_claims; +diff --git a/nv-attestation-sdk-cpp/include/nv_attestation/switch/evidence.h b/nv-attestation-sdk-cpp/include/nv_attestation/switch/evidence.h +index f2cd412..245e20a 100644 +--- a/nv-attestation-sdk-cpp/include/nv_attestation/switch/evidence.h ++++ b/nv-attestation-sdk-cpp/include/nv_attestation/switch/evidence.h +@@ -75,6 +75,7 @@ class SwitchEvidenceClaims { + std::string m_switch_bios_version; + std::string m_switch_pdi; + std::vector m_switch_gpu_pdis; ++ std::shared_ptr m_switch_lock_status; + bool m_switch_ar_nonce_match; // true if nonce matches between switch evidence and switch attestation report + AttestationReportClaims m_attestation_report_claims; + }; +@@ -97,6 +98,7 @@ class SwitchEvidence { + Error get_vbios_version(std::string& out_bios_version) const; + Error get_switch_pdi(std::string& out_pdi) const; + Error get_switch_gpu_pdis(std::vector& out_pdis) const; ++ Error get_switch_lock_status(uint64_t& out_lock_status) const; + Error get_vbios_rim_id(std::string& out_vbios_rim_id, SwitchArchitecture architecture) const; + Error get_spdm_req_nonce(std::vector& out_nonce) const; + Error get_measurements(std::unordered_map>& out_measurements) const; +diff --git a/nv-attestation-sdk-cpp/src/gpu/claims.cpp b/nv-attestation-sdk-cpp/src/gpu/claims.cpp +index 69e7457..fd6ac1c 100644 +--- a/nv-attestation-sdk-cpp/src/gpu/claims.cpp ++++ b/nv-attestation-sdk-cpp/src/gpu/claims.cpp +@@ -180,6 +180,7 @@ namespace nvattestation + out_claims.m_vbios_rim_signature_verified = js.at("x-nvidia-gpu-vbios-rim-signature-verified").get(); + out_claims.m_vbios_rim_measurements_available = js.at("x-nvidia-gpu-vbios-rim-measurements-available").get(); + out_claims.m_vbios_index_no_conflict = js.at("x-nvidia-gpu-vbios-index-no-conflict").get(); ++ out_claims.m_mode = js.value("x-nvidia-gpu-mode", ""); + + if (js.contains("x-nvidia-attester-claims")) { + for (const auto& kv : js.at("x-nvidia-attester-claims").items()) { +@@ -242,6 +243,9 @@ namespace nvattestation + js["x-nvidia-gpu-vbios-rim-signature-verified"] = claims.m_vbios_rim_signature_verified; + js["x-nvidia-gpu-vbios-rim-measurements-available"] = claims.m_vbios_rim_measurements_available; + js["x-nvidia-gpu-vbios-index-no-conflict"] = claims.m_vbios_index_no_conflict; ++ if (!claims.m_mode.empty()) { ++ js["x-nvidia-gpu-mode"] = claims.m_mode; ++ } + + js["x-nvidia-attester-claims"] = nlohmann::json::object(); + for (const auto& kv : claims.m_attester_claims) { +@@ -289,6 +293,7 @@ namespace nvattestation + lhs.m_vbios_rim_signature_verified == rhs.m_vbios_rim_signature_verified && + lhs.m_vbios_rim_measurements_available == rhs.m_vbios_rim_measurements_available && + lhs.m_vbios_index_no_conflict == rhs.m_vbios_index_no_conflict && ++ lhs.m_mode == rhs.m_mode && + lhs.m_attester_claims == rhs.m_attester_claims && + compare_shared_ptr(lhs.m_mismatched_opaque_records, rhs.m_mismatched_opaque_records) && + lhs.m_version == rhs.m_version; +diff --git a/nv-attestation-sdk-cpp/src/switch/claims.cpp b/nv-attestation-sdk-cpp/src/switch/claims.cpp +index faeda08..b906aae 100644 +--- a/nv-attestation-sdk-cpp/src/switch/claims.cpp ++++ b/nv-attestation-sdk-cpp/src/switch/claims.cpp +@@ -101,6 +101,7 @@ namespace nvattestation { + if (js.contains("x-nvidia-switch-gpu-pdis")) { + out_claims.m_switch_gpu_pdis = js.at("x-nvidia-switch-gpu-pdis").get>(); + } ++ out_claims.m_switch_lock_status = deserialize_optional_shared_ptr(js, "x-dstack-switch-lock-status"); + + out_claims.m_ar_cert_chain_claims = js.at("x-nvidia-switch-attestation-report-cert-chain").get(); + out_claims.m_ar_cert_chain_fwid_match = js.at("x-nvidia-switch-attestation-report-cert-chain-fwid-match").get(); +@@ -138,6 +139,9 @@ namespace nvattestation { + if (!claims.m_switch_gpu_pdis.empty()) { + js["x-nvidia-switch-gpu-pdis"] = claims.m_switch_gpu_pdis; + } ++ if (claims.m_switch_lock_status) { ++ js["x-dstack-switch-lock-status"] = *claims.m_switch_lock_status; ++ } + + js["x-nvidia-switch-attestation-report-cert-chain"] = claims.m_ar_cert_chain_claims; + js["x-nvidia-switch-attestation-report-cert-chain-fwid-match"] = claims.m_ar_cert_chain_fwid_match; +@@ -173,6 +177,7 @@ namespace nvattestation { + lhs.m_switch_bios_version == rhs.m_switch_bios_version && + lhs.m_switch_pdi == rhs.m_switch_pdi && + lhs.m_switch_gpu_pdis == rhs.m_switch_gpu_pdis && ++ compare_shared_ptr(lhs.m_switch_lock_status, rhs.m_switch_lock_status) && + lhs.m_ar_cert_chain_claims == rhs.m_ar_cert_chain_claims && + lhs.m_ar_cert_chain_fwid_match == rhs.m_ar_cert_chain_fwid_match && + lhs.m_ar_parsed == rhs.m_ar_parsed && +diff --git a/nv-attestation-sdk-cpp/src/switch/evidence.cpp b/nv-attestation-sdk-cpp/src/switch/evidence.cpp +index 1c6bf88..ddea4af 100644 +--- a/nv-attestation-sdk-cpp/src/switch/evidence.cpp ++++ b/nv-attestation-sdk-cpp/src/switch/evidence.cpp +@@ -222,6 +222,14 @@ Error SwitchEvidence::generate_switch_evidence_claims(const AttestationReport& p + return error; + } + ++ uint64_t lock_status = 0; ++ error = parsed_attestation_report.get_switch_lock_status(lock_status); ++ if (error == Error::Ok) { ++ out_switch_evidence_claims.m_switch_lock_status = std::make_shared(lock_status); ++ } else if (error != Error::SpdmFieldNotFound) { ++ return error; ++ } ++ + error = parsed_attestation_report.generate_attestation_report_claims(ocsp_verify_options, ocsp_client, arch_data, out_switch_evidence_claims.m_attestation_report_claims); + if (error != Error::Ok) { + return error; +@@ -423,6 +431,25 @@ Error SwitchEvidence::AttestationReport::get_switch_gpu_pdis(std::vector* lock_status_data = nullptr; ++ error = lock_status_field->get_byte_vector(lock_status_data); ++ if (error != Error::Ok) { ++ return error; ++ } ++ if (lock_status_data->empty() || lock_status_data->size() > sizeof(out_lock_status) || ++ !read_little_endian(*lock_status_data, 0, lock_status_data->size(), out_lock_status)) { ++ LOG_ERROR("Invalid switch lock status size: " << lock_status_data->size()); ++ return Error::SpdmParseError; ++ } ++ return Error::Ok; ++} ++ + Error SwitchEvidence::AttestationReport::get_vbios_rim_id(std::string& out_vbios_rim_id, SwitchArchitecture architecture) const { + std::string vbios_version; + Error error = get_vbios_version(vbios_version); +diff --git a/nv-attestation-sdk-cpp/src/switch/verify.cpp b/nv-attestation-sdk-cpp/src/switch/verify.cpp +index 8e5d810..ccdd983 100644 +--- a/nv-attestation-sdk-cpp/src/switch/verify.cpp ++++ b/nv-attestation-sdk-cpp/src/switch/verify.cpp +@@ -132,6 +132,7 @@ Error LocalSwitchVerifier::set_switch_evidence_claims(const SwitchEvidenceClaims + out_serializable_claims.m_switch_bios_version = switch_evidence_claims.m_switch_bios_version; + out_serializable_claims.m_switch_pdi = switch_evidence_claims.m_switch_pdi; + out_serializable_claims.m_switch_gpu_pdis = switch_evidence_claims.m_switch_gpu_pdis; ++ out_serializable_claims.m_switch_lock_status = switch_evidence_claims.m_switch_lock_status; + + out_serializable_claims.m_ar_cert_chain_claims.m_cert_expiration_date = switch_evidence_claims.m_attestation_report_claims.m_cert_chain_claims.expiration_date; + out_serializable_claims.m_ar_cert_chain_claims.m_cert_status = to_string(switch_evidence_claims.m_attestation_report_claims.m_cert_chain_claims.status); diff --git a/os/mkosi/tests/acceptance.sh b/os/mkosi/tests/acceptance.sh index 512d9d2f8..5ef0e13f3 100755 --- a/os/mkosi/tests/acceptance.sh +++ b/os/mkosi/tests/acceptance.sh @@ -213,6 +213,7 @@ fi grep -q '"firmware_sev":"files/ovmf-sev.fd"' "$D/scripts/make-release-artifacts.sh" grep -q 'measurement.snp.cbor' "$D/tests/check-output.sh" grep -q '0002-validate-ocsp-response-freshness.patch' "$D/components/nvattest/nvattest-build.sh" +grep -q '0003-expose-signed-ppcie-claims.patch' "$D/components/nvattest/nvattest-build.sh" grep -q -- '--fuzz=0' "$D/components/nvattest/nvattest-build.sh" grep -q '0001-pin-fetchcontent-inputs.patch' "$D/components/nvattest/nvattest-build.sh" grep -q 'COMPONENT_PATH/patches/0001-pin-fetchcontent-inputs.patch' "$D/components/nvattest/nvattest.sh" From 053022b5d838637d13336fa51d42f587c17a38bd Mon Sep 17 00:00:00 2001 From: Leechael Yim Date: Wed, 25 Nov 2026 19:58:43 -0800 Subject: [PATCH 2/2] fix(dstack-util): accept H200 PPCIe under the default GPU policy An HGX H200 in Protected PCIe mode runs its 8 GPUs with CC off behind 4 NVSwitches. When NVML reports PPCIe, also attest the NVSwitches with the same nonce and accept CC off only if the signed claims show: - every GPU reports mode "ppcie"; - every NVSwitch reports the locked status; - GPU and NVSwitch PDIs describe one complete fabric. On the CC path, reject a GPU whose signed mode is not a CC mode. GPU and NVSwitch claims share one parser and appraisal; application Rego still receives the GPU claims only. Signed-off-by: Leechael Yim Signed-off-by: Kevin Wang --- docs/security/security-model.md | 14 +- dstack/dstack-util/src/system_setup.rs | 404 +++++++++++++++++++++---- dstack/nvattest/src/lib.rs | 20 +- 3 files changed, 364 insertions(+), 74 deletions(-) diff --git a/docs/security/security-model.md b/docs/security/security-model.md index a8bccfd23..7dc8a5cac 100644 --- a/docs/security/security-model.md +++ b/docs/security/security-model.md @@ -57,7 +57,7 @@ dstack supports NVIDIA H100, H200, and B200 GPUs in confidential compute mode fo ### How It Works -GPUs are passed through via VFIO to the TEE-protected CVM. Before key provisioning, `dstack-util setup` inventories every VGA/3D-controller PCI function, rejects non-NVIDIA display devices, and runs NVIDIA's local `nvattest` verifier over every NVIDIA-driver-visible GPU with a fresh nonce. dstack does not ship or pass a custom relying-party policy to this command; nvattest's built-in appraisal still applies. The complete JSON result (`result_code`, `result_message`, `claims`, and `detached_eat`) is saved at `/run/nvidia-gpu-attestation/attestation.out`. +GPUs are passed through via VFIO to the TEE-protected CVM. Before key provisioning, `dstack-util setup` inventories every VGA/3D-controller PCI function, rejects non-NVIDIA display devices, and runs NVIDIA's local `nvattest` verifier over every NVIDIA-driver-visible GPU with a fresh nonce. On PPCIe it also appraises the NVSwitches. Without a collateral proxy, dstack uses nvattest's built-in appraisal. The complete boot record is saved at `/run/nvidia-gpu-attestation/attestation.out`. An application may additionally set `requirements.gpu_policy` to an object with the following deny-unknown-fields schema: @@ -114,7 +114,9 @@ The policy digest is remotely verifiable on each supported platform, but through - **AWS NitroTPM:** the same `gpu-policy-hash` event is extended into non-resettable SHA384 PCR14. Replay the PCR14 event chain against the signed NitroTPM Attestation Document, then compare the payload with the expected digest. - **AMD SEV-SNP:** there is no quote-bound runtime event register in the current stack. The signed SNP report's `HOST_DATA` binds the exact MrConfigV3 document, whose `compose_hash` covers the app-compose file and so the policy in it; the guest stops boot if that file does not match. GPU launches also put the digest in `MrConfigV3.gpu_policy_hash`. Verify the SNP report and `HOST_DATA` binding, then compare the policy, or the field when present, with the expected one. -For every NVML-enumerated GPU, dstack calls `Device::is_cc_enabled()` and `Device::is_cc_dev_mode_enabled()` and requires the NVML device count to match the expected GPU count. CC must always be ON; DevTools must be OFF unless the measured policy explicitly permits it. The typed claim checks always require `measres == "success"`; by default they also require `dbgstat == "disabled"` and `secboot == true`, with the latter two checks controlled by their explicit opt-ins. Only after the default appraisal, typed claim checks, optional Rego policy, and per-device NVML checks succeed does dstack call `Device::set_confidential_compute_state(true)` to set the GPU ready state. The dstack CPU/guest boot chain is verified independently through measured boot; a GPU claim named `secboot` refers to the GPU appraisal, not UEFI Secure Boot in the CVM. +The NVML GPU count must match the guest PCI inventory. The ordinary CC path requires NVML to report CC ON, and every GPU that reports a signed mode must report a CC mode (`spt` or `mpt`). On HGX H200, an 8-GPU, 4-NVSwitch Protected PCIe (PPCIe) launch can instead pass with CC OFF. NVML only selects this path; the decision rests on signed evidence. dstack verifies fresh GPU and NVSwitch claims against the same nonce, requires every GPU's signed mode to be `ppcie` and every NVSwitch's signed lock status to be locked, and checks that the device identities are distinct within each set and that the claims describe the expected fabric topology, following [NVIDIA's PPCIe verification flow](https://docs.nvidia.com/attestation/attestation-client-tools-ppcie-sdk-cpp/latest/ppcie_architecture.html). The image's `nvattest` is patched to expose the two signed fields: `x-nvidia-gpu-mode` from the GPU report's `FEATURE_FLAG`, and `x-dstack-switch-lock-status` from the NVSwitch report's `SWITCH_LOCK_STATUS`. Host-reported NVML and NSCQ state is not evidence. + +DevTools must be OFF unless the measured policy explicitly permits it. The typed claim checks always require `measres == "success"`; by default they also require `dbgstat == "disabled"` and `secboot == true` on every appraised device, including switches. The latter two checks have explicit opt-ins. Application Rego receives the GPU claims only, in both modes. dstack sets the GPU ready state only after the boot checks and optional Rego policy succeed. The dstack CPU/guest boot chain is verified independently through measured boot; `secboot` refers to NVIDIA's appraisal, not UEFI Secure Boot in the CVM. ### Dual Attestation @@ -156,7 +158,9 @@ mode enabled. `dbgstat` and `secboot` summarize the NVIDIA-signed claims: if every device reports secure boot. The complete per-device claims remain in the boot-time evidence committed by `evidence_sha256`. -`/v1/Attest` returns that complete boot-time `nvattest` record when the request sets `include_boottime_gpu_evidence`; it runs no new attestation. `AttestResponse.boottime_gpu_evidence` is a list of `GpuEvidenceBundle`, each carrying `vendor`, `format`, and `evidence`. The boot record is the bundle whose `vendor` is `nvidia` and whose `format` is `nvidia-nvattest-boottime-json-v1`; its `evidence` is hex-encoded bytes that decode to the exact UTF-8 nvattest output as the agent read it from disk. The other format, `nvidia-nvattest-collect-evidence-json-v1`, comes from `/v1/AttestGpu` and is fresh evidence against a caller nonce; the two are deliberately distinct because a verifier for one does not appraise the other. To bind the API result to TDX evidence: verify the quote, replay the event log to the quote's RTMR3, require exactly one pre-`system-ready` `gpu-attestation` event, decode its JSON payload, select the boot-time bundle by `format`, and compare `evidence_sha256` with `SHA-256(hex_decode(bundle.evidence))`. Hash the decoded bytes, not the JSON string as returned and not a re-serialized form: parsing and re-serializing changes the digest and breaks the comparison. Only after this comparison should the verifier inspect the returned claims. This exact-byte comparison includes any whitespace or trailing newline in the decoded record. +`/v1/Attest` returns that complete boot-time `nvattest` record when the request sets `include_boottime_gpu_evidence`; it runs no new attestation. `AttestResponse.boottime_gpu_evidence` is a list of `GpuEvidenceBundle`, each carrying `vendor`, `format`, and `evidence`. The boot record is the bundle whose `vendor` is `nvidia` and whose `format` is `nvidia-nvattest-boottime-json-v1`; its `evidence` is hex-encoded bytes that decode to the exact boot record as the agent read it from disk (the `nvattest` output for ordinary CC). The other format, `nvidia-nvattest-collect-evidence-json-v1`, comes from `/v1/AttestGpu` and is fresh evidence against a caller nonce; the two are deliberately distinct because a verifier for one does not appraise the other. To bind the API result to TDX evidence: verify the quote, replay the event log to the quote's RTMR3, require exactly one pre-`system-ready` `gpu-attestation` event, decode its JSON payload, select the boot-time bundle by `format`, and compare `evidence_sha256` with `SHA-256(hex_decode(bundle.evidence))`. Hash the decoded bytes, not the JSON string as returned and not a re-serialized form: parsing and re-serializing changes the digest and breaks the comparison. Only after this comparison should the verifier inspect the returned claims. This exact-byte comparison includes any whitespace or trailing newline in the decoded record. + +For PPCIe, the event has `version: 4` and `cc_mode: "ppcie"`; `devices` still counts GPUs. Its debug and secure-boot summaries cover both GPUs and NVSwitches. The boot evidence uses the same bundle tag. After verifying the digest, select the record layout using the measured event version and `cc_mode`, not by inspecting unverified evidence. For PPCIe the decoded record is a JSON object with `gpu_output` and `nvswitch_output` containing hex-encoded exact stdout from the two local `nvattest` runs. Ordinary CC launches keep the version 3 event and raw `nvattest` output. A verifier must replay the measured event log, require exactly one `gpu-policy-hash` event immediately after `compose-hash`, and compare its 32-byte payload with the expected policy digest (`SHA-256(JCS({}))` for the omitted/default policy). When MrConfigV3 includes `gpu_policy_hash`, it must match the same digest. When GPU protection is required, the verifier must also require exactly one pre-`system-ready` `gpu-attestation` event with `devices > 0` and, when applicable, the expected deployment count. The raw `attestation.out` file is not trusted by itself; if it is supplied for inspection, its digest must match the `gpu-attestation` event. @@ -164,10 +168,10 @@ A verifier must replay the measured event log, require exactly one `gpu-policy-h The GPU gate assumes a malicious host/VMM and untrusted host-provided PCI topology, while trusting the CPU TEE, the measured dstack guest/kernel, NVIDIA hardware/firmware roots, and the cryptography used by both attestation chains. Availability is out of scope. -The events make the following **boot-time** statement: immediately before key provisioning, all attached VGA/3D PCI functions were NVIDIA devices, their count matched the NVML inventory, nvattest returned one fresh successfully appraised claim for each device, the measured application policy accepted those claims and GPU state when present, every enumerated GPU passed the CC/DevTools NVML checks, and setting the GPU ready state succeeded. This closes these cases: +The events make the following **boot-time** statement: immediately before key provisioning, all attached VGA/3D PCI functions were NVIDIA devices, their count matched the NVML inventory, nvattest returned one fresh successfully appraised claim for each device, the measured application policy accepted those claims and GPU state when present, the NVML protection-mode and DevTools checks passed (and on PPCIe, the four NVSwitches also passed the switch-state, evidence, and fabric checks), and setting the GPU ready state succeeded. This closes these cases: - A GPU-less launch cannot be presented as a GPU-verified launch because it has no `gpu-attestation` event. -- A mixed launch cannot attest only its TEE-capable subset. Non-NVIDIA display GPUs are rejected, and the sysfs, NVML, and nvattest claim counts must all agree. A non-CC NVIDIA GPU either prevents evidence collection/appraisal or causes the default appraisal, application policy, or CC-state check to fail. +- A mixed launch cannot attest only its TEE-capable subset. Non-NVIDIA display GPUs are rejected, and the sysfs, NVML, and nvattest claim counts must all agree. A CC-off NVIDIA GPU outside an appraised PPCIe fabric cannot pass the gate. - Copying another CVM's result into a file or `report_data` does not work. Only measured pre-application code can place the event before `system-ready`, and event-log replay binds it to the quoted RTMR/PCR value. This is **not a lifetime or physical co-location guarantee**. After `system-ready`, an application with sufficient guest privileges can unload the NVIDIA driver, and a malicious host may attempt PCI hot-remove/replacement or proxy GPU traffic. The boot event remains a true historical statement but does not prove that the same device is still attached. dstack also cannot rule out a live relay/cuckoo attack to a genuine remote GPU: current Hopper/Blackwell deployments do not provide a CPU-TEE-verifiable TEE-I/O/TDISP device binding. Applications that mutate the driver or PCI topology are outside this guarantee; higher-assurance deployments must prevent that behavior and re-attest before using a newly initialized GPU; the guest-agent `/v1/AttestGpu` API does that re-check against a caller-chosen nonce, returning bundles tagged `nvidia-nvattest-collect-evidence-json-v1` rather than the boot-time format. Being an NVIDIA report, its result is subject to the same relay caveat as any attestation-time GPU sample: it establishes that a genuine CC-enabled GPU is reachable and responsive now, not that the device is bound to this TD, so it must not be forwarded to a remote relying party as proof of GPU possession. diff --git a/dstack/dstack-util/src/system_setup.rs b/dstack/dstack-util/src/system_setup.rs index 51ba3436a..7c88ebd19 100644 --- a/dstack/dstack-util/src/system_setup.rs +++ b/dstack/dstack-util/src/system_setup.rs @@ -15,7 +15,7 @@ use std::{ time::Duration, }; -use anyhow::{anyhow, bail, Context, Result}; +use anyhow::{anyhow, bail, ensure, Context, Result}; use dstack_attest::{default_verifier, emit_runtime_event, set_runtime_event_version}; use dstack_kms_rpc as rpc; use dstack_types::{ @@ -1540,6 +1540,11 @@ mod gpu { use super::*; const EVENT_VERSION: u32 = 3; + const PPCIE_EVENT_VERSION: u32 = 4; + const PPCIE_GPUS: usize = 8; + const PPCIE_SWITCHES: usize = 4; + /// Signed `SWITCH_LOCK_STATUS` value of a locked NVSwitch. + const SWITCH_LOCKED: u64 = 1; const POLICY_ENTRYPOINT: &str = "data.policy.nv_match"; /// Bound Rego evaluation so a runaway application policy cannot hang boot. const POLICY_TIMEOUT: Duration = Duration::from_secs(10); @@ -1559,10 +1564,13 @@ mod gpu { } pub(super) struct GpuAttestationResult { + /// GPU claims only: the application Rego input. claims: Vec, - parsed_claims: Vec, + /// Every appraised device: the GPUs, then any NVSwitches. + parsed_claims: Vec, output: Vec, devices: u32, + ppcie: bool, } impl GpuAttestationResult { @@ -1581,7 +1589,14 @@ mod gpu { NvidiaGpuDebugStatus::Disabled }; let secboot = self.parsed_claims.iter().all(|claim| claim.secboot); - attestation_event(&self.output, self.devices, devtools, dbgstat, secboot) + attestation_event( + &self.output, + self.devices, + devtools, + dbgstat, + secboot, + self.ppcie, + ) } pub(super) fn verify_claim_policy( @@ -1589,13 +1604,14 @@ mod gpu { state: &GpuState, policy: &GpuPolicy, ) -> Result<()> { - verify_claim_policy(&self.parsed_claims, &state.devices, policy) + verify_claim_policy(&self.parsed_claims, &state.devices, policy, state.ppcie) } } pub(super) struct GpuState { nvml: nvml_wrapper::Nvml, devices: Vec, + ppcie: bool, } impl GpuState { @@ -1620,16 +1636,63 @@ mod gpu { claims: Vec, } + /// One appraised GPU or NVSwitch. Every field is derived by nvattest from + /// the device-signed report; the host-reported NVML/NSCQ state is not. #[derive(Debug, Deserialize)] - struct NvidiaGpuClaim { + struct NvidiaClaim { #[serde(rename = "x-nvidia-device-type")] device_type: String, eat_nonce: String, - #[serde(rename = "x-nvidia-gpu-attestation-report-nonce-match")] + #[serde( + rename = "x-nvidia-gpu-attestation-report-nonce-match", + alias = "x-nvidia-switch-attestation-report-nonce-match" + )] nonce_match: bool, measres: String, secboot: bool, dbgstat: NvidiaGpuDebugStatus, + #[serde(default)] + ueid: String, + /// GPU mode from the signed `FEATURE_FLAG`; absent on old firmware. + #[serde(rename = "x-nvidia-gpu-mode")] + mode: Option, + #[serde(rename = "x-nvidia-switch-pdi")] + pdi: Option, + /// The PDIs of the devices on the other side of the fabric. + #[serde( + default, + rename = "x-nvidia-gpu-switch-pdis", + alias = "x-nvidia-switch-gpu-pdis" + )] + peer_pdis: Vec, + #[serde(rename = "x-dstack-switch-lock-status")] + lock_status: Option, + } + + impl NvidiaClaim { + fn verify(&self, policy: &GpuPolicy, ppcie: bool) -> Result<()> { + ensure!(self.measres == "success", "unsuccessful measurements"); + ensure!( + policy.allow_insecure_boot || self.secboot, + "secure boot is not asserted" + ); + ensure!( + policy.allow_debug || self.dbgstat == NvidiaGpuDebugStatus::Disabled, + "debug mode is not disabled" + ); + if self.device_type == "gpu" { + // CC modes are single- and multi-GPU passthrough. Firmware + // without the feature flag predates PPCIe and is CC-only. + let mode = self.mode.as_deref(); + let expected = if ppcie { + mode == Some("ppcie") + } else { + matches!(mode, None | Some("spt" | "mpt")) + }; + ensure!(expected, "unexpected signed GPU mode {mode:?}"); + } + Ok(()) + } } #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)] @@ -1641,7 +1704,7 @@ mod gpu { struct ValidatedClaims { raw: Vec, - parsed: Vec, + parsed: Vec, } /// Count passed-through display-class GPUs through sysfs so devices which @@ -1695,6 +1758,13 @@ mod gpu { /// call them for every handle so every expected device must be enumerable. pub(super) fn query_gpu_state(expected_devices: u32) -> Result { let nvml = init_nvml(expected_devices)?; + let ppcie = nvml + .device_by_index(0)? + .is_multi_gpu_protected_pcie_enabled() + .context("failed to query Protected PCIe mode")?; + if ppcie && expected_devices as usize != PPCIE_GPUS { + bail!("PPCIe requires {PPCIE_GPUS} GPUs, found {expected_devices}"); + } let mut devices = Vec::with_capacity(expected_devices as usize); for index in 0..expected_devices { let device = nvml @@ -1711,7 +1781,11 @@ mod gpu { devtools, }); } - Ok(GpuState { nvml, devices }) + Ok(GpuState { + nvml, + devices, + ppcie, + }) } /// Set the system-wide GPU ready state without appraisal for the explicit @@ -1724,7 +1798,8 @@ mod gpu { fn validate_attestation_output( stdout: &[u8], nonce: &str, - expected_devices: u32, + device_type: &str, + expected_devices: usize, ) -> Result { let output: NvattestOutput = serde_json::from_slice(stdout).context("failed to parse nvattest JSON output")?; @@ -1734,21 +1809,21 @@ mod gpu { output.result_code ); } - if output.claims.len() != expected_devices as usize { + if output.claims.len() != expected_devices { bail!( - "gpu attestation count mismatch: expected {expected_devices}, got {}", + "{device_type} attestation count mismatch: expected {expected_devices}, got {}", output.claims.len() ); } let mut parsed_claims = Vec::with_capacity(output.claims.len()); for (index, claim) in output.claims.iter().enumerate() { - let claim: NvidiaGpuClaim = serde_json::from_value(claim.clone()) - .with_context(|| format!("invalid GPU claim at index {index}"))?; - if claim.device_type != "gpu" { - bail!("gpu claim at index {index} has an invalid device type"); + let claim: NvidiaClaim = serde_json::from_value(claim.clone()) + .with_context(|| format!("invalid {device_type} claim at index {index}"))?; + if claim.device_type != device_type { + bail!("{device_type} claim at index {index} has an invalid device type"); } if claim.eat_nonce != nonce || !claim.nonce_match { - bail!("gpu claim at index {index} has an invalid nonce"); + bail!("{device_type} claim at index {index} has an invalid nonce"); } parsed_claims.push(claim); } @@ -1759,12 +1834,13 @@ mod gpu { } fn verify_claim_policy( - claims: &[NvidiaGpuClaim], + claims: &[NvidiaClaim], devices: &[GpuDeviceState], policy: &GpuPolicy, + ppcie: bool, ) -> Result<()> { for (index, device) in devices.iter().enumerate() { - if !device.cc_enabled { + if !ppcie && !device.cc_enabled { bail!("gpu at index {index} does not enable confidential compute mode"); } if device.devtools && !policy.allow_devtools { @@ -1772,15 +1848,9 @@ mod gpu { } } for (index, claim) in claims.iter().enumerate() { - if claim.measres != "success" { - bail!("gpu claim at index {index} has unsuccessful measurements"); - } - if !policy.allow_insecure_boot && !claim.secboot { - bail!("gpu claim at index {index} does not assert secure boot"); - } - if !policy.allow_debug && claim.dbgstat != NvidiaGpuDebugStatus::Disabled { - bail!("gpu claim at index {index} does not disable debug mode"); - } + claim.verify(policy, ppcie).with_context(|| { + format!("{} claim at index {index} rejected", claim.device_type) + })?; } Ok(()) } @@ -1791,12 +1861,17 @@ mod gpu { devtools: bool, dbgstat: NvidiaGpuDebugStatus, secboot: bool, + ppcie: bool, ) -> Result> { let event = GpuAttestationEvent { - version: EVENT_VERSION, + version: if ppcie { + PPCIE_EVENT_VERSION + } else { + EVENT_VERSION + }, provider: "nvidia", devices, - cc_mode: "on", + cc_mode: if ppcie { "ppcie" } else { "on" }, devtools, dbgstat, secboot, @@ -1805,13 +1880,66 @@ mod gpu { serde_json::to_vec(&event).context("failed to serialize GPU attestation event") } + /// Check the PPCIe fabric from signed claims: every NVSwitch is locked, + /// and the GPUs and NVSwitches each report exactly the other set. + fn verify_fabric(gpus: &[NvidiaClaim], switches: &[NvidiaClaim]) -> Result<()> { + let mut switch_pdis = BTreeSet::new(); + for switch in switches { + ensure!( + switch.lock_status == Some(SWITCH_LOCKED), + "NVSwitch is not locked (signed lock status {:?})", + switch.lock_status + ); + let pdi = switch + .pdi + .as_deref() + .and_then(normalize_pdi) + .context("NVSwitch has no PDI")?; + ensure!(switch_pdis.insert(pdi), "duplicate NVSwitch PDI"); + } + let gpu_pdis = switches + .first() + .map(|switch| topology_pdis(&switch.peer_pdis)) + .unwrap_or_default(); + ensure!( + gpu_pdis.len() == PPCIE_GPUS + && switches + .iter() + .all(|switch| topology_pdis(&switch.peer_pdis) == gpu_pdis), + "NVSwitches do not report the same full GPU set" + ); + let mut ueids = BTreeSet::new(); + for gpu in gpus { + ensure!( + !gpu.ueid.is_empty() && ueids.insert(&gpu.ueid), + "missing or duplicate GPU identity" + ); + ensure!( + topology_pdis(&gpu.peer_pdis) == switch_pdis, + "GPU does not report the attested NVSwitch set" + ); + } + Ok(()) + } + + /// An all-zero PDI marks an unpopulated topology slot. + fn normalize_pdi(pdi: &str) -> Option { + pdi.bytes() + .any(|b| b != b'0') + .then(|| pdi.to_ascii_uppercase()) + } + + fn topology_pdis(pdis: &[String]) -> BTreeSet { + pdis.iter().filter_map(|pdi| normalize_pdi(pdi)).collect() + } + /// Run local GPU attestation via nvattest with a fresh evidence nonce. If /// sys-config selects a collateral proxy, both RIM and OCSP traffic is /// routed through it and NVIDIA's Trust Outpost policy accepts cached OCSP /// responses whose responder nonce no longer matches. The independent GPU /// evidence nonce remains mandatory and is checked below. pub(super) async fn attest_gpu( - expected_devices: u32, + state: &GpuState, proxy_url: Option<&str>, ) -> Result { if !nvattest::available() { @@ -1823,18 +1951,37 @@ mod gpu { warn!("system clock not synchronized: {err:?}"); } let nonce: [u8; nvattest::NONCE_LEN] = rand::thread_rng().gen(); - let (nonce, output) = nvattest::run(&nonce, proxy_url, nvattest::DEFAULT_TIMEOUT).await?; + let run = |device| nvattest::run(device, &nonce, proxy_url, nvattest::DEFAULT_TIMEOUT); + let (nonce_hex, output) = run("gpu").await?; // Persist before judging the exit status: a failed appraisal is exactly // when the evidence is worth having on disk. save_attestation_output(&output.stdout).context("failed to save GPU attestation output")?; nvattest::check_status(&output)?; - let claims = validate_attestation_output(&output.stdout, &nonce, expected_devices)?; - Ok(GpuAttestationResult { - claims: claims.raw, - parsed_claims: claims.parsed, + let gpus = + validate_attestation_output(&output.stdout, &nonce_hex, "gpu", state.devices.len())?; + let mut result = GpuAttestationResult { + claims: gpus.raw, + parsed_claims: gpus.parsed, output: output.stdout, - devices: expected_devices, - }) + devices: state.devices.len() as u32, + ppcie: state.ppcie, + }; + if !state.ppcie { + return Ok(result); + } + let (_, switches) = run("nvswitch").await?; + result.output = serde_json::to_vec(&serde_json::json!({ + "gpu_output": hex::encode(&result.output), + "nvswitch_output": hex::encode(&switches.stdout), + }))?; + save_attestation_output(&result.output) + .context("failed to save PPCIe attestation output")?; + nvattest::check_status(&switches)?; + let switches = + validate_attestation_output(&switches.stdout, &nonce_hex, "nvswitch", PPCIE_SWITCHES)?; + verify_fabric(&result.parsed_claims, &switches.parsed)?; + result.parsed_claims.extend(switches.parsed); + Ok(result) } pub(super) fn measure_gpu_policy(compose_path: &Path) -> Result<[u8; 32]> { @@ -1990,26 +2137,29 @@ mod gpu { fn basic_policy_requires_cc_and_rejects_devtools_by_default() { let nonce = "44".repeat(32); let output = nvattest_output(&nonce, 1); - let claims = validate_attestation_output(&output, &nonce, 1).unwrap(); + let claims = validate_attestation_output(&output, &nonce, "gpu", 1).unwrap(); let production = [GpuDeviceState { cc_enabled: true, devtools: false, }]; - verify_claim_policy(&claims.parsed, &production, &GpuPolicy::default()).unwrap(); + verify_claim_policy(&claims.parsed, &production, &GpuPolicy::default(), false).unwrap(); let non_cc = [GpuDeviceState { cc_enabled: false, devtools: false, }]; - let err = - verify_claim_policy(&claims.parsed, &non_cc, &GpuPolicy::default()).unwrap_err(); + let err = verify_claim_policy(&claims.parsed, &non_cc, &GpuPolicy::default(), false) + .unwrap_err(); assert!(err.to_string().contains("confidential compute mode")); let devtools = [GpuDeviceState { cc_enabled: true, devtools: true, }]; - assert!(verify_claim_policy(&claims.parsed, &devtools, &GpuPolicy::default()).is_err()); + assert!( + verify_claim_policy(&claims.parsed, &devtools, &GpuPolicy::default(), false) + .is_err() + ); verify_claim_policy( &claims.parsed, &devtools, @@ -2017,48 +2167,170 @@ mod gpu { allow_devtools: true, ..Default::default() }, + false, ) .unwrap(); } + #[test] + fn ppcie_requires_signed_mode_locked_switches_and_matching_topology() { + use serde_json::json; + + let nonce = "55".repeat(32); + let switch_pdis = (1..=4).map(|id| format!("{id:016X}")).collect::>(); + let gpu_pdis = (1..=8).map(|id| format!("{id:016X}")).collect::>(); + let mut gpus: Value = serde_json::from_slice(&nvattest_output(&nonce, 8)).unwrap(); + for (id, gpu) in gpus["claims"] + .as_array_mut() + .unwrap() + .iter_mut() + .enumerate() + { + gpu["ueid"] = json!(id.to_string()); + gpu["x-nvidia-gpu-mode"] = json!("ppcie"); + gpu["x-nvidia-gpu-switch-pdis"] = json!(switch_pdis); + } + let switch_claims = switch_pdis + .iter() + .map(|pdi| { + json!({ + "x-nvidia-device-type": "nvswitch", + "eat_nonce": nonce, + "x-nvidia-switch-attestation-report-nonce-match": true, + "measres": "success", + "secboot": true, + "dbgstat": "disabled", + "x-dstack-switch-lock-status": 1, + "x-nvidia-switch-pdi": pdi, + "x-nvidia-switch-gpu-pdis": gpu_pdis, + }) + }) + .collect::>(); + let switches = json!({"result_code": 0, "claims": switch_claims}); + let cc_off = [GpuDeviceState { + cc_enabled: false, + devtools: false, + }; PPCIE_GPUS]; + let appraise = |gpus: &Value, switches: &Value| -> Result<()> { + let gpus = + validate_attestation_output(&serde_json::to_vec(gpus)?, &nonce, "gpu", 8)?; + let switches = validate_attestation_output( + &serde_json::to_vec(switches)?, + &nonce, + "nvswitch", + PPCIE_SWITCHES, + )?; + verify_fabric(&gpus.parsed, &switches.parsed)?; + let claims = gpus + .parsed + .into_iter() + .chain(switches.parsed) + .collect::>(); + verify_claim_policy(&claims, &cc_off, &GpuPolicy::default(), true) + }; + appraise(&gpus, &switches).unwrap(); + + for (key, value) in [ + ("x-dstack-switch-lock-status", json!(0)), + ("x-dstack-switch-lock-status", Value::Null), + ("eat_nonce", json!("stale")), + ("measres", json!("fail")), + ("x-nvidia-switch-pdi", json!(switch_pdis[1])), + ("x-nvidia-switch-gpu-pdis", json!(gpu_pdis[1..])), + ] { + let mut invalid = switches.clone(); + invalid["claims"][0][key] = value; + assert!( + appraise(&gpus, &invalid).is_err(), + "accepted NVSwitch {key}" + ); + } + for (key, value) in [ + ("x-nvidia-gpu-mode", json!("spt")), + ("x-nvidia-gpu-mode", Value::Null), + ("ueid", json!("1")), + ("x-nvidia-gpu-switch-pdis", json!(switch_pdis[1..])), + ] { + let mut invalid = gpus.clone(); + invalid["claims"][0][key] = value; + assert!(appraise(&invalid, &switches).is_err(), "accepted GPU {key}"); + } + let mut missing_switch = switches.clone(); + missing_switch["claims"].as_array_mut().unwrap().pop(); + assert!(appraise(&gpus, &missing_switch).is_err()); + } + + #[test] + fn cc_launch_rejects_a_gpu_signing_another_mode() { + let nonce = "66".repeat(32); + let devices = [GpuDeviceState { + cc_enabled: true, + devtools: false, + }]; + for (mode, accepted) in [ + (Value::Null, true), + (serde_json::json!("spt"), true), + (serde_json::json!("mpt"), true), + (serde_json::json!("ppcie"), false), + (serde_json::json!("invalid"), false), + ] { + let mut output: Value = + serde_json::from_slice(&nvattest_output(&nonce, 1)).unwrap(); + output["claims"][0]["x-nvidia-gpu-mode"] = mode; + let output = serde_json::to_vec(&output).unwrap(); + let claims = validate_attestation_output(&output, &nonce, "gpu", 1).unwrap(); + let result = + verify_claim_policy(&claims.parsed, &devices, &GpuPolicy::default(), false); + assert_eq!(result.is_ok(), accepted); + } + } + #[test] fn nvattest_output_requires_every_expected_gpu_and_fresh_nonce() { let nonce = "11".repeat(32); let valid = nvattest_output(&nonce, 2); - validate_attestation_output(&valid, &nonce, 2).unwrap(); - assert!(validate_attestation_output(&valid, &nonce, 1).is_err()); + validate_attestation_output(&valid, &nonce, "gpu", 2).unwrap(); + assert!(validate_attestation_output(&valid, &nonce, "gpu", 1).is_err()); let mut invalid: Value = serde_json::from_slice(&valid).unwrap(); invalid["claims"][1]["eat_nonce"] = Value::String("stale".to_string()); - assert!( - validate_attestation_output(&serde_json::to_vec(&invalid).unwrap(), &nonce, 2) - .is_err() - ); + assert!(validate_attestation_output( + &serde_json::to_vec(&invalid).unwrap(), + &nonce, + "gpu", + 2 + ) + .is_err()); // Basic claim settings are enforced after structural validation. let mut extra_claims: Value = serde_json::from_slice(&valid).unwrap(); extra_claims["claims"][0]["dbgstat"] = Value::String("enabled".to_string()); - validate_attestation_output(&serde_json::to_vec(&extra_claims).unwrap(), &nonce, 2) - .unwrap(); + validate_attestation_output( + &serde_json::to_vec(&extra_claims).unwrap(), + &nonce, + "gpu", + 2, + ) + .unwrap(); } #[test] fn basic_claim_policy_is_fail_closed_and_honors_opt_ins() { let nonce = "33".repeat(32); let output = nvattest_output(&nonce, 1); - let claims = validate_attestation_output(&output, &nonce, 1).unwrap(); + let claims = validate_attestation_output(&output, &nonce, "gpu", 1).unwrap(); let devices = [GpuDeviceState { cc_enabled: true, devtools: false, }]; - verify_claim_policy(&claims.parsed, &devices, &GpuPolicy::default()).unwrap(); + verify_claim_policy(&claims.parsed, &devices, &GpuPolicy::default(), false).unwrap(); let with_policy = |name: &str, value: Value, policy: &GpuPolicy| { let mut output: Value = serde_json::from_slice(&output).unwrap(); output["claims"][0][name] = value; let output = serde_json::to_vec(&output).unwrap(); - let claims = validate_attestation_output(&output, &nonce, 1).unwrap(); - verify_claim_policy(&claims.parsed, &devices, policy) + let claims = validate_attestation_output(&output, &nonce, "gpu", 1).unwrap(); + verify_claim_policy(&claims.parsed, &devices, policy, false) }; assert!(with_policy("secboot", Value::Bool(false), &GpuPolicy::default()).is_err()); @@ -2093,7 +2365,8 @@ mod gpu { assert!(validate_attestation_output( &serde_json::to_vec(&unknown_debug).unwrap(), &nonce, - 1, + "gpu", + 1 ) .is_err()); @@ -2117,7 +2390,8 @@ mod gpu { assert!(validate_attestation_output( &serde_json::to_vec(&missing).unwrap(), &nonce, - 1, + "gpu", + 1 ) .is_err()); } @@ -2126,7 +2400,8 @@ mod gpu { #[test] fn real_h100_attestation_fixture_validates_and_drives_rego() { let nonce = "11".repeat(32); - let claims = validate_attestation_output(H100_ATTESTATION_OUTPUT, &nonce, 1).unwrap(); + let claims = + validate_attestation_output(H100_ATTESTATION_OUTPUT, &nonce, "gpu", 1).unwrap(); assert_eq!(claims.raw[0]["hwmodel"], "GH100 A01 GSP BROM"); assert_eq!(claims.raw[0]["x-nvidia-gpu-claims-version"], "3.0"); verify_claim_policy( @@ -2136,6 +2411,7 @@ mod gpu { devtools: false, }], &GpuPolicy::default(), + false, ) .unwrap(); @@ -2157,7 +2433,15 @@ mod gpu { let nonce = "22".repeat(32); let output = nvattest_output(&nonce, 1); let event: Value = serde_json::from_slice( - &attestation_event(&output, 1, true, NvidiaGpuDebugStatus::Enabled, false).unwrap(), + &attestation_event( + &output, + 1, + true, + NvidiaGpuDebugStatus::Enabled, + false, + false, + ) + .unwrap(), ) .unwrap(); assert_eq!(event["version"], EVENT_VERSION); @@ -2312,8 +2596,9 @@ impl Stage0<'_> { } self.vmm.notify_q("boot.progress", "attesting GPU").await; info!("verifying GPU TEE attestation"); + let gpu_state = gpu::query_gpu_state(expected_devices)?; let attestation = gpu::attest_gpu( - expected_devices, + &gpu_state, self.shared .sys_config .nvidia_attestation_proxy_url @@ -2321,7 +2606,6 @@ impl Stage0<'_> { ) .await?; - let gpu_state = gpu::query_gpu_state(expected_devices)?; attestation .verify_claim_policy(&gpu_state, &gpu_policy) .context("failed to apply basic GPU policy")?; diff --git a/dstack/nvattest/src/lib.rs b/dstack/nvattest/src/lib.rs index f933ecd66..61d788fe9 100644 --- a/dstack/nvattest/src/lib.rs +++ b/dstack/nvattest/src/lib.rs @@ -97,12 +97,13 @@ pub fn normalize_proxy_url(proxy_url: Option<&str>) -> Result> { Ok(Some(parsed.as_str().trim_end_matches('/').to_string())) } -/// Build the CLI arguments for a local (self-verifying) GPU attestation. -pub fn args(nonce: &str, proxy_url: Option<&str>) -> Result> { +/// Build the CLI arguments for a local (self-verifying) attestation of +/// `device` (`gpu` or `nvswitch`). +pub fn args(device: &str, nonce: &str, proxy_url: Option<&str>) -> Result> { let mut args = vec![ "attest".to_string(), "--device".to_string(), - "gpu".to_string(), + device.to_string(), "--verifier".to_string(), "local".to_string(), "--nonce".to_string(), @@ -153,7 +154,7 @@ pub async fn attest( proxy_url: Option<&str>, timeout: Duration, ) -> Result { - let (nonce, output) = run(nonce, proxy_url, timeout).await?; + let (nonce, output) = run("gpu", nonce, proxy_url, timeout).await?; check_status(&output)?; let claims = check_nonce(&output.stdout, &nonce)?; Ok(Attestation { @@ -163,13 +164,14 @@ pub async fn attest( }) } -/// Run `nvattest` and hand back its raw output *whatever its exit status*, -/// along with the hex nonce it was given. +/// Run `nvattest` on `device` and hand back its raw output *whatever its +/// exit status*, along with the hex nonce it was given. /// /// Errors only when the tool could not be run at all. The boot gate persists /// stdout before judging the status, so a failed appraisal still leaves /// evidence on disk to debug; that is why the status check is separate. pub async fn run( + device: &str, nonce: &[u8], proxy_url: Option<&str>, timeout: Duration, @@ -178,7 +180,7 @@ pub async fn run( bail!("nvattest is not available in this image"); } let nonce = check_nonce_len(nonce)?; - let args = args(&nonce, proxy_url)?; + let args = args(device, &nonce, proxy_url)?; if args.iter().any(|arg| arg == "--relying-party-policy") && !Path::new(TRUST_OUTPOST_POLICY).is_file() { @@ -395,7 +397,7 @@ mod tests { #[test] fn proxy_routes_ocsp_and_rim_and_selects_outpost_policy() { - let proxied = args("aa", Some("http://10.0.2.2:8090/")).unwrap(); + let proxied = args("gpu", "aa", Some("http://10.0.2.2:8090/")).unwrap(); assert!(proxied .windows(2) .any(|w| w == ["--ocsp-url", "http://10.0.2.2:8090/ocsp"])); @@ -406,7 +408,7 @@ mod tests { .windows(2) .any(|w| w == ["--relying-party-policy", TRUST_OUTPOST_POLICY])); - let direct = args("aa", None).unwrap(); + let direct = args("gpu", "aa", None).unwrap(); assert!(!direct.iter().any(|a| a == "--ocsp-url")); assert!(!direct.iter().any(|a| a == "--relying-party-policy")); }