Skip to content

Caching support for VCEK certificates#138

Merged
lmilleri merged 1 commit intoopenshift:mainfrom
lmilleri:disconnected-ter
Nov 3, 2025
Merged

Caching support for VCEK certificates#138
lmilleri merged 1 commit intoopenshift:mainfrom
lmilleri:disconnected-ter

Conversation

@lmilleri
Copy link
Copy Markdown

@lmilleri lmilleri commented 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)

@openshift-ci openshift-ci bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 22, 2025
ProcessorGeneration::Turin => "turin",
};

let vcek_dir = Path::new("/etc/kbs/snp/ek").join(proc_dir);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The path can be a const.

bail!("{} directory not found", vcek_dir.display());
}

for entry in std::fs::read_dir(&vcek_dir)? {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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>
@lmilleri lmilleri marked this pull request as ready for review October 22, 2025 13:41
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 22, 2025
Copy link
Copy Markdown

@bpradipt bpradipt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Nov 3, 2025
@lmilleri lmilleri merged commit 5eb5c0f into openshift:main Nov 3, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants