← Back to Pull requests

Patch rats refactor #1

Merged
amd-kkin merged 17 files (794 lines) on Sep 10, 2026 18:53 UTC
View on GitHub
amd-kkin amd-kkin commented on Aug 28, 2026 17:12 UTC
Author

Remove circular dependency for verifier-sev path

endorser and verifier were mutually dependent: impl TryFrom<&cert::Chain> for Generation lived in endorser but called .verify() from the verifier's Verifiable trait. Because neither role could build without the other, lib.rs carried a compile_error! forcing consumers to enable both, and firmware/platform needed quadruple #[cfg] gates. Moving the impl to verifier/sev/chain.rs from endorser makes the dependency one-way (verifier → endorser). Also, endorser = ["evidence"] was spurious in the original PR; endorser never referenced evidence in code, only in doc comments. This commit let's endorser = [] drop its spurious evidence edge, and collapses the gates.

Clean up builds requiring different features

The previous commit made endorser-only builds reachable for the first time, which helped discover that they were broken. The moved impl was still feature-gated, so Generation::try_from(&chain) silently vanished without verifier, failing with an unsatisfied trait bound on a type the caller never wrote. Replaces it with verifier::sev::infer_generation(), so a missing feature yields an unresolved path naming the module to enable. Also drops type Error = () for a real io::Error, and repairs cached_chain.rs, which had a stale import predating this work.

Add feature isolation tests

Nothing in CI ever compiled a role by itself; every job enabled evidence,verifier,endorser,reference together, so cross-role reaches stayed invisible, which is also how cached_chain.rs rotted unnoticed. Adds a feature-isolation job covering each role alone (19 combos × 2 toolchains). Building the matrix surfaced a live bug: launch::sev requires verifier, but launch/linux/sev.rs was gated on sev alone, so sev,launch,endorser failed with an unresolved import — now a clear compile_error!.

Use rustls for reqwest so crypto-rust builds without OpenSSL

The clippy-crypto-rust CI job did not build at all. dangerous_hw_tests pulls in reqwest, whose default native-tls links openssl-sys — dragging OpenSSL into the very build that job exists to prove is OpenSSL-free. Switching to default-features = false + rustls-tls removes openssl-sys from the graph entirely.

Fix test cfg gates and extend feature isolation to all targets

The isolation job ran --lib, because tests/ was itself broken — leaving the same class of bug uncovered there. Four files had #[cfg] gates that didn't match their imports: measurement.rs and id-block.rs used reference without requiring it; certs.rs gated on any-of-five-roles while needing both endorser and verifier; snp_launch.rs imported PageType from launch instead of launch::snp. With those fixed, the job moves to --all-targets, so test-gate drift now fails CI. Test name lists are unchanged in all six CI configurations — the gates exclude only what genuinely needs the missing feature.

Diff: 794 lines (+354 / -440) across 17 files Reviewer: DGonzalezVillal Review duration: 18821m
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.71) × (1 − Review Confidence (0.76)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.71 · 794 lines diff across 17 files
0.71
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.53 · 5 substantive comment(s)
0.53
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
76%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.400
Mass File Touch mass_file_touch
0.080
Real PR Conversation Timeline
8 items
DGonzalezVillal DGonzalezVillal commented on code on Aug 31, 2026 21:19 UTC
Code Review
src/attestation/endorser/sev/cert/chain.rs:1
@@ -60,6 +60,7 @@ impl Encoder<()> for Chain {
     }
 }
 
-// `impl TryFrom<&Chain> for Generation` lives in `crate::attestation::verifier::sev::chain`:
-// inferring the generation requires `Verifiable`, and depending on the verifier
-// from here would make `endorser` and `verifier` mutually dependent.
+// Generation inference for a `Chain` lives in the verifier, as
+// `crate::attestation::verifier::sev::infer_generation`: it requires
+// `Verifiable`, and depending on the verifier from here would make `endorser`
+// and `verifier` mutually dependent.

No need to call this out

DGonzalezVillal DGonzalezVillal commented on code on Aug 31, 2026 21:22 UTC
Code Review
src/attestation/verifier/sev/mod.rs:1
@@ -5,3 +5,5 @@
 mod cert;
 mod chain;
 mod report;
+
+pub use self::chain::infer_generation;

No need to re-export it, if anything I want it to be known it's coming from chain, that way people know where to look for it.

DGonzalezVillal DGonzalezVillal commented on code on Aug 31, 2026 21:23 UTC
Code Review
src/types/shared/generation.rs:1
@@ -32,14 +32,19 @@ use std::convert::TryFrom;
 /// assert_eq!(generation, Generation::Milan);
 ///
 /// // Legacy SEV: infer generation from an exported platform certificate chain
-/// // (`sev`, `crypto-openssl`, and `platform` features required).
-/// # #[cfg(all(feature = "crypto-openssl", feature = "sev", feature = "platform"))]
+/// // (`sev`, `crypto-openssl`, `platform`, and `verifier` features required).
+/// # #[cfg(all(
+/// #     feature = "crypto-openssl",
+/// #     feature = "sev",
+/// #     feature = "platform",
+/// #     feature = "verifier"
+/// # ))]
 /// # {
-/// # use std::convert::TryFrom;
+/// # use sev::attestation::verifier::sev::infer_generation;

For example here:
sev::attestation::verifier::sev::chain::infer_generation

Let's me know we are inferring from the chain and not from some native sev function

DGonzalezVillal DGonzalezVillal requested changes on Aug 31, 2026 21:47 UTC
Changes Requested Reviewer

Hey Katherine,

Thank you for the PR — I've been thinking about it all day.

I think moving the TryFrom impl to the verifier was the right call; great catch on your part. I'm less sure about replacing TryFrom with infer_generation.

My concern is that anyone already using Generation::try_from(&chain) would have to migrate to infer_generation. Losing the idiomatic Rust conversion feels worse to me than the silent disappearance of the trait when verifier isn't enabled.

After thinking about it more, I assume this is mostly used internally and in tests. Ideally we'd move this behavior into the test layer altogether. The function verifies a CEK against our built-in ASKs to infer the generation — if someone is doing that in production, they probably have a bigger problem. It feels like automation glue, not something people should rely on.

So changing TryFrom to infer_generation is OK for now; I think we're the only ones consuming it anyway.

I don't want to spend much time on legacy SEV — it's not what we're developing for anymore, and I'm not looking to polish that API further. Since this looks internal-only, I'm fine with the rename for now, even though I'm generally not a fan of changes that might break downstream behavior.

Same with the reqwest change: I don't think many users care, because I don't think anyone runs dangerous_hw_tests outside our CI. Not a big deal to change it, but probably low impact either way.

One small request: please drop the re-export of infer_generation from verifier/sev/mod.rs. If someone uses it, I'd rather they import it from the chain module explicitly. Also remove the comment in endorser about where infer_generation lives — I don't think we need that.

Otherwise, great work on the CI fixes. Even if we're the main consumers of those tests, we should still lint them properly — I definitely missed things there.

If you can make those two quick fixes, I'll merge into my branch and apply the other changes we discussed.

amd-kkin amd-kkin commented on code on Aug 31, 2026 22:53 UTC
Code Review
src/attestation/verifier/sev/mod.rs:1
@@ -5,3 +5,5 @@
 mod cert;
 mod chain;
 mod report;
+
+pub use self::chain::infer_generation;

Removed, but also changed mod chain; to pub(crate) mod chain; since a private module isn't reachable from a sibling, and pub(crate) mod reopens it crate-internally without duplicating the function's cfg gate on a re-export, so util::cached_chain can use it.

Since this is kind of weird, I'm also ok with keeping it where it is but changing it back from infer_generation to TryFrom.

DGonzalezVillal DGonzalezVillal commented on code on Sep 03, 2026 20:51 UTC
Code Review
src/attestation/verifier/sev/mod.rs:1
@@ -5,3 +5,5 @@
 mod cert;
 mod chain;
 mod report;
+
+pub use self::chain::infer_generation;

Ok this was my bad, small hiccup in my general understanding on rust visibility. I'm ok with the re-export in this scenario. So we can add back the pub use self::chain::infer_generation. Sorry for the confusion!

DGonzalezVillal DGonzalezVillal commented on code on Sep 03, 2026 20:54 UTC
Code Review
src/attestation/verifier/sev/mod.rs:1
@@ -5,3 +5,5 @@
 mod cert;
 mod chain;
 mod report;
+
+pub use self::chain::infer_generation;

Or keep the try_From I'm ok with either

Assignees
amd-kkin amd-kkin
Labels
risk: low confidence: 76.3% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 71.5% (HIGH) · Higher = larger blast radius
71.5%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 76.3% · Lower = rushed or shallow review
76.3%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 16.9% · Safe to merge
16.9%