Skip to content

Commit 76c207f

Browse files
committed
nvidia: complete local RIM verification and add optional NRAS mode
Signed-off-by: Jiale Zhang <zhangjiale@linux.alibaba.com>
1 parent 0215708 commit 76c207f

26 files changed

Lines changed: 1537 additions & 1245 deletions

‎Cargo.lock‎

Lines changed: 0 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎attestation-service/docs/config.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ section:
1818
| `storage_backend` | SharedStorageConfiguration | Optional namespaced backend for AS policies and built-in RVPS reference values. | False | None |
1919
| `work_dir` | String | The location for Attestation Service to store data. | False | Firstly try to read from ENV `AS_WORK_DIR`. If not any, use `/opt/confidential-containers/attestation-service` |
2020
| `rvps_config` | [RVPSConfiguration][2] | RVPS configuration | False | - |
21+
| `nvidia_verifier` | [NVIDIA verification](../../deps/verifier/src/nvidia/README.md) | Local RIM or optional NRAS verification; environment variables override file settings. | False | Local RIM with NVIDIA NVAT 2.x |
2122
| `artifact_server_address` | String | Artifact Server URL used by policy `query_artifact_server`. | False | `https://attest-pre.aliyuncs.com` |
2223
| `attestation_token_broker` | [AttestationTokeBroker][1] | Attestation result token configuration. | False | - |
2324
| `challenge_key_path` | String | Path to the RSA private key (PEM) used to sign and verify attestation challenge (nonce) tokens. The key is generated atomically on the first challenge request if the file does not exist, and is reloaded for every signing and verification request. | False | `/etc/trustee/attestation-service/nonce_token_issuer/key.pem` |

‎attestation-service/src/config.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ pub const DEFAULT_ARTIFACT_SERVER_ADDRESS: &str = "https://attest-pre.aliyuncs.c
1414

1515
#[derive(Clone, Debug, Deserialize, PartialEq)]
1616
pub struct Config {
17+
/// NVIDIA verification defaults to local RIM; environment overrides apply
18+
/// when verifying GPU evidence. Also used by KBS's built-in AS.
19+
#[serde(default)]
20+
pub nvidia_verifier: verifier::nvidia_config::NvidiaVerifierConfig,
1721
/// Optional shared backend for AS policy and built-in RVPS state.
1822
#[serde(default)]
1923
pub storage_backend: Option<StorageBackendConfig>,
@@ -67,6 +71,7 @@ impl Default for Config {
6771
// Construct a default instance of `Config`
6872
fn default() -> Config {
6973
Config {
74+
nvidia_verifier: Default::default(),
7075
storage_backend: None,
7176
work_dir: default_work_dir(),
7277
rvps_config: RvpsConfig::default(),
@@ -103,6 +108,15 @@ impl TryFrom<&Path> for Config {
103108

104109
#[cfg(test)]
105110
mod tests {
111+
#[test]
112+
fn nvidia_config_is_optional_and_selects_local_rim_by_default() {
113+
use verifier::nvidia_config::NvidiaVerificationMode;
114+
let config: super::Config = serde_json::from_str("{}").unwrap();
115+
assert_eq!(config.nvidia_verifier.mode, NvidiaVerificationMode::Rim);
116+
let config: super::Config =
117+
serde_json::from_str(r#"{"nvidia_verifier":{"mode":"nras"}}"#).unwrap();
118+
assert_eq!(config.nvidia_verifier.mode, NvidiaVerificationMode::Nras);
119+
}
106120
use rstest::rstest;
107121
use std::path::PathBuf;
108122

@@ -130,6 +144,7 @@ mod tests {
130144
signer: None,
131145
policy_dir: "/var/lib/attestation-service/policies".into(),
132146
}),
147+
nvidia_verifier: Default::default(),
133148
challenge_key_path: None,
134149
artifact_server_address: DEFAULT_ARTIFACT_SERVER_ADDRESS.to_string(),
135150
})]
@@ -152,6 +167,7 @@ mod tests {
152167
cert_path: Some("/etc/cert.pem".into())
153168
}),
154169
}),
170+
nvidia_verifier: Default::default(),
155171
challenge_key_path: None,
156172
artifact_server_address: DEFAULT_ARTIFACT_SERVER_ADDRESS.to_string(),
157173
})]
@@ -173,6 +189,7 @@ mod tests {
173189
signer: None,
174190
policy_dir: "/var/lib/attestation-service/policies".into(),
175191
}),
192+
nvidia_verifier: Default::default(),
176193
challenge_key_path: None,
177194
artifact_server_address: DEFAULT_ARTIFACT_SERVER_ADDRESS.to_string(),
178195
})]
@@ -198,6 +215,7 @@ mod tests {
198215
cert_path: Some("/etc/cert.pem".into())
199216
}),
200217
}),
218+
nvidia_verifier: Default::default(),
201219
challenge_key_path: None,
202220
artifact_server_address: DEFAULT_ARTIFACT_SERVER_ADDRESS.to_string(),
203221
})]
@@ -228,6 +246,7 @@ mod tests {
228246
}),
229247
policy_dir: "/var/lib/attestation-service/policies".into(),
230248
}),
249+
nvidia_verifier: Default::default(),
231250
challenge_key_path: None,
232251
artifact_server_address: DEFAULT_ARTIFACT_SERVER_ADDRESS.to_string(),
233252
})]

‎attestation-service/src/lib.rs‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ pub struct VerificationRequest {
219219
}
220220

221221
pub struct AttestationService {
222+
nvidia_config: verifier::nvidia_config::NvidiaVerifierConfig,
222223
rvps: Arc<dyn RvpsApi>,
223224
token_broker: Box<dyn AttestationTokenBroker + Send + Sync>,
224225
challenger: JwtChallenger,
@@ -296,7 +297,9 @@ impl AttestationService {
296297
None => JwtChallenger::new_with_private_key_default_path().await?,
297298
};
298299

299-
Ok(Self::from_components(rvps, token_broker, challenger))
300+
let mut service = Self::from_components(rvps, token_broker, challenger);
301+
service.nvidia_config = config.nvidia_verifier;
302+
Ok(service)
300303
}
301304

302305
/// Assemble an [`AttestationService`] from already-constructed component
@@ -308,12 +311,23 @@ impl AttestationService {
308311
challenger: JwtChallenger,
309312
) -> Self {
310313
Self {
314+
nvidia_config: Default::default(),
311315
rvps,
312316
token_broker,
313317
challenger,
314318
}
315319
}
316320

321+
/// Configure a library/wasm AS instance without filesystem or global state.
322+
/// Per-process environment overrides, when available, retain priority.
323+
pub fn with_nvidia_config(
324+
mut self,
325+
config: verifier::nvidia_config::NvidiaVerifierConfig,
326+
) -> Self {
327+
self.nvidia_config = config;
328+
self
329+
}
330+
317331
/// Return AS and verifier dependency status without performing network I/O.
318332
pub async fn status(&self) -> ServiceStatus {
319333
let dependencies = verifier::dependency_statuses().await;
@@ -427,12 +441,14 @@ impl AttestationService {
427441
}
428442
}
429443

430-
let verifier = verifier::to_verifier(&verification_request.tee).map_err(|source| {
431-
AttestationError::UnsupportedTee {
432-
request_index,
433-
tee: verification_request.tee,
434-
source,
435-
}
444+
let verifier = verifier::to_verifier_with_nvidia_config(
445+
&verification_request.tee,
446+
&self.nvidia_config,
447+
)
448+
.map_err(|source| AttestationError::UnsupportedTee {
449+
request_index,
450+
tee: verification_request.tee,
451+
source,
436452
})?;
437453

438454
let (report_data, runtime_data_claims) = parse_runtime_data(
@@ -589,7 +605,7 @@ impl AttestationService {
589605
tee: Tee,
590606
tee_parameters: String,
591607
) -> Result<String> {
592-
let verifier = verifier::to_verifier(&tee)?;
608+
let verifier = verifier::to_verifier_with_nvidia_config(&tee, &self.nvidia_config)?;
593609
verifier
594610
.generate_supplemental_challenge(tee_parameters)
595611
.await

‎attestation-service/tests/challenge_key_rotation.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ fn config(work_dir: &Path, challenge_key_path: &Path) -> Config {
4040
signer: None,
4141
policy_dir: work_dir.join("policies").to_string_lossy().into_owned(),
4242
}),
43+
nvidia_verifier: Default::default(),
4344
challenge_key_path: Some(challenge_key_path.to_path_buf()),
4445
..Config::default()
4546
}

‎attestation-service/tests/policy_rvps.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ fn as_config(work_dir: &Path, rvps_config: RvpsConfig) -> Config {
8282
policy_dir: work_dir.join("policies").to_string_lossy().into_owned(),
8383
..Default::default()
8484
}),
85+
nvidia_verifier: Default::default(),
8586
challenge_key_path: None,
8687
artifact_server_address: attestation_service::config::DEFAULT_ARTIFACT_SERVER_ADDRESS
8788
.to_string(),

‎deps/verifier/Cargo.toml‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,12 @@ se-verifier = ["openssl", "pv", "serde_with", "tokio/sync"]
7474
system-verifier = []
7575
tpm-verifier = ["openssl", "openssl-sys", "tss-esapi", "reqwest", "uuid"]
7676
gpu-verifier = [
77+
"jsonwebtoken",
78+
"dep:tempfile",
79+
"tokio/rt",
80+
"tokio/time",
7781
"reqwest",
78-
"quick-xml",
79-
"uuid",
8082
"chrono",
81-
"regex",
82-
"futures",
8383
"tokio/sync",
8484
"tokio/macros",
8585
]
@@ -107,7 +107,6 @@ csv-rs = { git = "https://github.com/openanolis/csv-rs.git", rev = "86d68fd4e1b5
107107
] }
108108
eventlog = { path = "../eventlog" }
109109
eventlog-rs = { git = "https://github.com/inclavare-containers/eventlog-rs.git", rev = "bc342f0534f2e2ef3a9c4a34a4838b88fdf81725" }
110-
futures = { version = "0.3", optional = true }
111110
hex.workspace = true
112111
jsonwebkey = "0.3.5"
113112
jsonwebtoken = { workspace = true, default-features = false, optional = true }
@@ -116,9 +115,7 @@ log.workspace = true
116115
openssl = { version = "0.10.55", optional = true }
117116
openssl-sys = { version = "0.9", optional = true }
118117
pv = { version = "0.10.0", package = "s390_pv", optional = true }
119-
quick-xml = { version = "0.41.0", optional = true }
120118
reqwest = { workspace = true, optional = true }
121-
regex = { version = "1.10", optional = true }
122119
scroll = { version = "0.11.0", default-features = false, features = [
123120
"derive",
124121
], optional = true }
@@ -166,11 +163,13 @@ ear = { workspace = true, optional = true }
166163
x509-parser = { version = "0.14.0", optional = true }
167164
bitflags = { version = "2.8.0", features = ["serde"] }
168165

169-
# `uuid` is pulled in (optionally, via the `gpu-verifier` feature) for GPU
170-
# evidence parsing. On `wasm32-unknown-unknown` the `v4` RNG needs a wasm
166+
# `uuid` is pulled in optionally for TPM registrar identities.
167+
# On `wasm32-unknown-unknown` the `v4` RNG needs a wasm
171168
# backend, so mirror attestation-service's target-specific split: native uses
172169
# `["v4"]`, wasm adds the `js` feature (js-sys / wasm-bindgen RNG).
173170
[target.'cfg(not(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown")))'.dependencies]
171+
tempfile = { workspace = true, optional = true }
172+
tokio = { workspace = true, optional = true, features = ["process", "io-util"] }
174173
uuid = { version = "1.0", features = ["v4"], optional = true }
175174
[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"))'.dependencies]
176175
uuid = { version = "1.0", features = ["v4", "js"], optional = true }
@@ -182,6 +181,7 @@ shadow-rs.workspace = true
182181
tonic-build.workspace = true
183182

184183
[dev-dependencies]
184+
p384 = { version = "0.13", features = ["ecdsa", "pkcs8"] }
185185
assert-json-diff.workspace = true
186186
rstest.workspace = true
187187
serial_test.workspace = true

‎deps/verifier/src/lib.rs‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ pub use error::Error as VerifierError;
1111
pub mod status;
1212
pub use status::DependencyStatus;
1313

14+
pub mod nvidia_config;
1415
pub mod sample;
1516
pub mod sample_device;
1617

18+
#[cfg(feature = "gpu-verifier")]
19+
pub(crate) mod nvidia;
20+
1721
#[cfg(feature = "az-snp-vtpm-verifier")]
1822
pub mod az_snp_vtpm;
1923

@@ -54,6 +58,14 @@ pub mod hygon_tpm;
5458
pub mod tpm_registrar;
5559

5660
pub fn to_verifier(tee: &Tee) -> Result<Box<dyn Verifier + Send + Sync>> {
61+
to_verifier_with_nvidia_config(tee, &nvidia_config::NvidiaVerifierConfig::default())
62+
}
63+
64+
pub fn to_verifier_with_nvidia_config(
65+
tee: &Tee,
66+
nvidia_config: &nvidia_config::NvidiaVerifierConfig,
67+
) -> Result<Box<dyn Verifier + Send + Sync>> {
68+
let _ = nvidia_config;
5769
match tee {
5870
Tee::Sev => bail!("TEE `sev` verifier is not implemented."),
5971
Tee::Nvidia => bail!("TEE `nvidia` verifier is not implemented."),
@@ -79,7 +91,7 @@ pub fn to_verifier(tee: &Tee) -> Result<Box<dyn Verifier + Send + Sync>> {
7991
Tee::Tdx => {
8092
cfg_if::cfg_if! {
8193
if #[cfg(feature = "tdx-verifier")] {
82-
Ok(Box::<tdx::Tdx>::default() as Box<dyn Verifier + Send + Sync>)
94+
Ok(Box::new(tdx::Tdx { nvidia_config: nvidia_config.clone() }) as Box<dyn Verifier + Send + Sync>)
8395
} else {
8496
bail!("feature `tdx-verifier` is not enabled for `verifier` crate.")
8597
}

0 commit comments

Comments
 (0)