-
Notifications
You must be signed in to change notification settings - Fork 8
Compute PCRs #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compute PCRs #12
Changes from all commits
862f0dc
35d1b2d
8ab04d6
99bfe29
fc1b803
a5ed684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,17 @@ | ||
| [workspace] | ||
| members = ["crds", "operator", "manifest-gen"] | ||
| members = ["compute-pcrs", "crds", "operator", "manifest-gen"] | ||
| resolver = "3" | ||
|
|
||
| [workspace.package] | ||
| edition = "2024" | ||
|
|
||
| [workspace.dependencies] | ||
| anyhow = "1.0.99" | ||
| clap = "4.5.41" | ||
| env_logger = "0.11.8" | ||
| k8s-openapi = { version = "0.25.0", features = ["v1_33"] } | ||
| kube = "1.1.0" | ||
| log = "0.4.27" | ||
| serde = "1.0.219" | ||
| serde_json = "1.0.141" | ||
| tokio = "1.46.1" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| [package] | ||
| name = "compute-pcrs" | ||
| version = "0.1.0" | ||
| edition.workspace = true | ||
| description = "A cocl-operator optimized compute-pcrs interface" | ||
|
|
||
| [dependencies] | ||
| anyhow.workspace = true | ||
| chrono = "0.4.41" | ||
| clap = { workspace = true, features = ["derive"] } | ||
| compute-pcrs-lib = { git = "https://github.com/confidential-clusters/compute-pcrs", version = "0.1.0" } | ||
| k8s-openapi.workspace = true | ||
| kube.workspace = true | ||
| log.workspace = true | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json.workspace = true | ||
| tokio = { workspace = true, features = ["macros", "rt-multi-thread"] } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| FROM ghcr.io/confidential-clusters/compute-pcrs/buildroot AS builder | ||
| WORKDIR /compute-pcrs | ||
| COPY Cargo.toml Cargo.lock . | ||
| COPY compute-pcrs compute-pcrs | ||
| # Hack: Set compute-pcrs as sole member to avoid needing to copy other crates. | ||
| # In that case, a rebuild would be triggered upon any change in those crates. | ||
| RUN sed -i 's/members =.*/members = ["compute-pcrs"]/' Cargo.toml && \ | ||
| git clone --depth 1 https://github.com/confidential-clusters/reference-values && \ | ||
| cargo build --release -p compute-pcrs | ||
|
|
||
| FROM quay.io/fedora/fedora:42 | ||
| COPY --from=builder /compute-pcrs/target/release/compute-pcrs /usr/local/bin | ||
| COPY --from=builder /compute-pcrs/reference-values /reference-values | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| use anyhow::Result; | ||
| use chrono::{DateTime, TimeDelta, Utc}; | ||
| use clap::Parser; | ||
| use compute_pcrs_lib::*; | ||
| use k8s_openapi::api::core::v1::ConfigMap; | ||
| use kube::api::{ObjectMeta, PostParams}; | ||
| use kube::{Api, Client}; | ||
| use log::info; | ||
| use serde::{Serialize, Serializer}; | ||
| use std::collections::BTreeMap; | ||
|
|
||
| fn primitive_date_time_to_str<S>(d: &DateTime<Utc>, s: S) -> Result<S::Ok, S::Error> | ||
| where | ||
| S: Serializer, | ||
| { | ||
| s.serialize_str(&d.format("%Y-%m-%dT%H:%M:%SZ").to_string()) | ||
| } | ||
|
|
||
| /// Sync with Trustee | ||
| /// reference_value_provider_service::reference_value::ReferenceValue | ||
| /// (cannot import directly because its expiration doesn't serialize | ||
| /// right) | ||
| #[derive(Serialize)] | ||
| struct ReferenceValue { | ||
| pub version: String, | ||
| pub name: String, | ||
| #[serde(serialize_with = "primitive_date_time_to_str")] | ||
| pub expiration: DateTime<Utc>, | ||
| pub value: serde_json::Value, | ||
| } | ||
|
|
||
| #[derive(Parser)] | ||
| #[command(version, about)] | ||
| struct Args { | ||
| /// Path to the kernel modules directory | ||
| #[arg(short, long)] | ||
| kernels: String, | ||
| /// Path to the ESP directory | ||
| #[arg(short, long)] | ||
| esp: String, | ||
| /// Path to the directory storing EFIVar files | ||
| #[arg(short = 's', long)] | ||
| efivars: String, | ||
| /// Path to directory storing MokListRT, MokListTrustedRT and MokListXRT | ||
| #[arg(short, long)] | ||
| mokvars: String, | ||
| /// ConfigMap name to write to | ||
| #[arg(short, long)] | ||
| configmap: String, | ||
| /// Namespace to write ConfigMap to | ||
| #[arg(short, long)] | ||
| namespace: String, | ||
| } | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<()> { | ||
| let args = Args::parse(); | ||
|
|
||
| let mut pcrs: Vec<_> = [ | ||
| compute_pcr4(&args.kernels, &args.esp, false, true), | ||
| compute_pcr7(Some(&args.efivars), &args.esp, true), | ||
| compute_pcr14(&args.mokvars), | ||
| ] | ||
| .iter() | ||
| .map(|pcr| (format!("pcr{}", pcr.id), pcr.value.clone())) | ||
| .collect(); | ||
| pcrs.push(("svn".to_string(), "1".to_string())); | ||
|
|
||
| let reference_values: Vec<_> = pcrs | ||
| .iter() | ||
| .map(|(name, value)| ReferenceValue { | ||
| version: "0.1.0".to_string(), | ||
| name: format!("tpm_{name}"), | ||
| expiration: Utc::now() + TimeDelta::days(365), | ||
| value: serde_json::Value::Array(vec![serde_json::Value::String(value.to_string())]), | ||
| }) | ||
| .collect(); | ||
| let reference_values_json = serde_json::to_string(&reference_values)?; | ||
| let data = BTreeMap::from([( | ||
| "reference-values.json".to_string(), | ||
| reference_values_json.to_string(), | ||
| )]); | ||
|
|
||
| let config_map = ConfigMap { | ||
| metadata: ObjectMeta { | ||
| name: Some(args.configmap.clone()), | ||
| namespace: Some(args.namespace.clone()), | ||
| ..Default::default() | ||
| }, | ||
| data: Some(data), | ||
| ..Default::default() | ||
| }; | ||
|
|
||
| let client = Client::try_default().await?; | ||
| let config_maps: Api<ConfigMap> = Api::namespaced(client, &args.namespace); | ||
| match config_maps | ||
| .create(&PostParams::default(), &config_map) | ||
| .await | ||
| { | ||
| Ok(_) => info!("Create ConfigMap {}", args.configmap), | ||
| Err(kube::Error::Api(ae)) if ae.code == 409 => { | ||
| info!("ConfigMap {} already exists", args.configmap) | ||
| } | ||
| Err(e) => return Err(e.into()), | ||
| } | ||
|
Comment on lines
+94
to
+105
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if the config map already exists? You probably wants to retrieve its value check if it is different from the reference values, and if not then not update it. Right now, it make little sense but when we have more coreos versions to handle then the logic will become useful
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as per #13, the RVs will be computed statelessly, and the config map will be overwritten. the code that I wrote for this which I momentarily refuse to delete is at Jakob-Naucke:shelved-append-rvs. I'm in favor of merging this PR first and moving on from there. |
||
|
|
||
| Ok(()) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,11 @@ | ||
| [package] | ||
| name = "crds" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| k8s-openapi = { version = "0.25.0", features = ["v1_33"] } | ||
| kube = { version = "1.1.0", features = ["derive"] } | ||
| k8s-openapi.workspace = true | ||
| kube = { workspace = true, features = ["derive"] } | ||
| schemars = { version = "0.8", features = ["derive"] } | ||
| serde = { version = "1.0.219", features = ["derive"] } | ||
| serde_json = "1.0.141" | ||
| serde = { workspace = true, features = ["derive"] } | ||
| serde_json.workspace = true |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,3 +9,5 @@ nodes: | |
| extraPortMappings: | ||
| - containerPort: 31000 | ||
| hostPort: 8080 | ||
| featureGates: | ||
| "ImageVolume": true | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,14 @@ | ||
| [package] | ||
| name = "manifest-gen" | ||
| version = "0.1.0" | ||
| edition = "2024" | ||
| edition.workspace = true | ||
|
|
||
| [dependencies] | ||
| anyhow.workspace = true | ||
| env_logger.workspace = true | ||
| clap = { workspace = true, features = ["derive"] } | ||
| crds = { path = "../crds" } | ||
| anyhow = "1.0.98" | ||
| clap = { version = "4.5.41", features = ["derive"] } | ||
| kube = { version = "1.1.0", features = ["derive"] } | ||
| k8s-openapi.workspace = true | ||
| kube = { workspace = true, features = ["derive"] } | ||
| log.workspace = true | ||
| serde_yaml = "0.9" | ||
| k8s-openapi = { version = "0.25.0", features = ["v1_33"] } | ||
| log = "0.4.27" | ||
| env_logger = "0.11.8" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cannot you copy the Cargo.toml from
compute-pcrsinstead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it has workspace dependencies and I prefer workspace dependencies over potentially deviating versions