Caching support for VCEK certificates#138
Merged
lmilleri merged 1 commit intoopenshift:mainfrom Nov 3, 2025
Merged
Conversation
bpradipt
reviewed
Oct 22, 2025
deps/verifier/src/snp/mod.rs
Outdated
| ProcessorGeneration::Turin => "turin", | ||
| }; | ||
|
|
||
| let vcek_dir = Path::new("/etc/kbs/snp/ek").join(proc_dir); |
bpradipt
reviewed
Oct 22, 2025
deps/verifier/src/snp/mod.rs
Outdated
| bail!("{} directory not found", vcek_dir.display()); | ||
| } | ||
|
|
||
| for entry in std::fs::read_dir(&vcek_dir)? { |
There was a problem hiding this comment.
I think iterator is an idiomatic way in rust for these things. I asked copilot for an iterator implementation for this and it returned the following
let cert_data = fs::read_dir(&vcek_dir)?
// 1. Filter out directory entries that are errors.
.filter_map(Result::ok)
// 2. Keep only entries that are files.
.filter(|entry| entry.path().is_file())
// 3. Try to read and parse each file, returning the raw data and parsed cert.
// This filters out files that can't be read or parsed.
.filter_map(|entry| {
let path = entry.path();
let data = fs::read(&path).ok()?; // .ok() converts Result to Option
let cert = Certificate::from_bytes(&data).ok()?;
Some((data, cert, path)) // Pass data, cert, and path along
})
// 4. Find the first one that successfully verifies the report.
.find(|(_data, cert, path)| {
match (cert, report).verify() {
Ok(_) => {
log::info!("Found VCEK certificate that verifies report: {}", path.display());
true
}
Err(e) => {
log::debug!("Certificate {} does not verify report: {}", path.display(), e);
false
}
}
});
// 5. Handle the result of the `find` operation.
match cert_data {
Some((data, _cert, _path)) => Ok(data),
None => bail!(
"No VCEK certificate found in {} that verifies the report",
vcek_dir.display()
),
}
Most likely you'll need to adapt it.
6801341 to
7eba6f3
Compare
cclaudio
reviewed
Oct 22, 2025
VCEK certificates can be fetched in 3 ways:
(1) from the attestation report (it seems not safe to rely on this option)
(2) from local directory (depending on the processor generation):
└── etc
└── kbs
└── snp
└── ek
├── genoa
├── milan
└── turin
(3) from the AMD KDS (this option is not viable for disconnected environments)
Signed-off-by: Claudio Carvalho <cclaudio@linux.ibm.com>
Signed-off-by: Leonardo Milleri <lmilleri@redhat.com>
7eba6f3 to
710a266
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
VCEK certificates can be fetched in 3 ways:
(1) from the attestation report (it seems not safe to rely on this option)
(2) from local directory (depending on the processor generation):
(3) from the AMD KDS (this option is not viable for disconnected environments)