Skip to content

Commit c5ec81d

Browse files
committed
operator: KBS API for LUKS key registration
- Right before the trustee first deploys the operator, create an auth key for the KBS API and save it as a kube secret. - Replacing the patch mechanism with API calls - Add a reconcile loop that watches for changes in the trustee deployment and sync LUKS key that was lost. Test: test_luks_key_sync - this test checks that the luks key is first sent to tustee and validates that after trustee restarts, the keys are sent again. Signed-off-by: Roy Kaufman <rkaufman@redhat.com>
1 parent 1e57bb7 commit c5ec81d

11 files changed

Lines changed: 2212 additions & 586 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ anyhow = "1.0.102"
1616
chrono = "0.4.44"
1717
clap = { version = "4.6.0", features = ["derive"] }
1818
clevis-pin-trustee-lib = { git = "https://github.com/latchset/clevis-pin-trustee" }
19-
compute-pcrs-lib = { git = "https://github.com/trusted-execution-clusters/compute-pcrs" }
19+
compute-pcrs-lib = { git = "https://github.com/trusted-execution-clusters/compute-pcrs", rev = "1e7b9f74206e436d1426c335e30b2f1a6bd1681e"}
2020
env_logger = { version = "0.11.10", default-features = false }
2121
http = "1.4.0"
2222
ignition-config = "0.6.1"

Containerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ RUN sed -i 's/members = .*/members = ["lib", "operator"]/' Cargo.toml && \
2323
# In debug builds, build dependencies to avoid full rebuild.
2424
RUN if [ "$build_type" = debug ]; then cargo build -p operator; fi
2525

26+
RUN dnf install -y perl-FindBin perl-core
27+
2628
# Target build stage
2729
COPY operator/src operator/src
2830
RUN cargo build -p operator $(if [ "$build_type" = release ]; then echo --release; fi)

operator/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ serde.workspace = true
3030
serde_json.workspace = true
3131
thiserror = "2.0.18"
3232
tokio.workspace = true
33+
kbs-client = {git = "https://github.com/confidential-containers/trustee.git"}
3334

3435
[dev-dependencies]
3536
http.workspace = true

operator/src/kbs-config.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ insecure_http = true
44

55
[admin]
66
insecure_api = true
7+
auth_public_key="/key/public.pub"
78
type = "InsecureAllowAll"
89

910
[attestation_token]
@@ -32,8 +33,7 @@ policy_engine = "opa"
3233

3334
[[plugins]]
3435
name = "resource"
35-
type = "LocalFs"
36-
dir_path = "/opt/trustee/kbs-repository"
36+
type = "kvstorage"
3737

3838
[policy_engine]
3939
policy_path = "/opt/trustee/policy.rego"

operator/src/main.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ async fn install_trustee_configuration(
179179
Err(e) => error!("Failed to create the attestation policy configmap: {e}"),
180180
}
181181

182+
match trustee::generate_trustee_auth_keys_secret(client.clone(), owner_reference.clone()).await
183+
{
184+
Ok(_) => info!("Generate auth keys for the KBS API",),
185+
Err(e) => error!("Failed to create the auth keys: {e}"),
186+
}
187+
182188
let kbs_port = cluster.spec.trustee_kbs_port;
183189
match trustee::generate_kbs_service(client.clone(), owner_reference.clone(), kbs_port).await {
184190
Ok(_) => info!("Generate the KBS service"),
@@ -190,7 +196,7 @@ async fn install_trustee_configuration(
190196
"RELATED_IMAGE_TRUSTEE",
191197
"quay.io/trusted-execution-clusters/key-broker-service:20260106",
192198
);
193-
match trustee::generate_kbs_deployment(client, owner_reference, &trustee_image).await {
199+
match trustee::generate_kbs_deployment(client.clone(), owner_reference, &trustee_image).await {
194200
Ok(_) => info!("Generate the KBS deployment"),
195201
Err(e) => error!("Failed to create the KBS deployment: {e}"),
196202
}
@@ -278,6 +284,7 @@ async fn main() -> Result<()> {
278284
attestation_key_register::launch_ak_controller(kube_client.clone()).await;
279285
attestation_key_register::launch_machine_ak_controller(kube_client.clone()).await;
280286
attestation_key_register::launch_secret_ak_controller(kube_client.clone()).await;
287+
trustee::launch_trustee_sync_controller(kube_client.clone()).await;
281288

282289
let ctx = Arc::new(ClusterContext {
283290
client: kube_client,

operator/src/register_server.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async fn keygen_reconcile(
132132
async {
133133
let owner_reference = generate_owner_reference(&Arc::unwrap_or_clone(machine))?;
134134
trustee::generate_secret(kube_client.clone(), id, owner_reference).await?;
135-
trustee::mount_secret(kube_client, id).await
135+
trustee::send_secret(kube_client, id).await
136136
}
137137
.await
138138
.map(|_| Action::await_change())
@@ -178,10 +178,12 @@ async fn keygen_reconcile(
178178
}
179179
}
180180

181-
trustee::unmount_secret(kube_client, id)
182-
.await
183-
.map(|_| Action::await_change())
184-
.map_err(|e| finalizer::Error::<ControllerError>::CleanupFailed(e.into()))
181+
trustee::delete_secret(kube_client, id).await.map_err(|e| {
182+
finalizer::Error::<ControllerError>::CleanupFailed(
183+
anyhow!("failed to delete secret for machine {id}: {e}").into(),
184+
)
185+
})?;
186+
Ok(Action::await_change())
185187
}
186188
}
187189
})

0 commit comments

Comments
 (0)