Skip to content

Commit 4131b91

Browse files
bgartziYair Podemsky
andcommitted
rust: Update minimum toolchain to 1.88
Minimum rust version was set to 1.85. Fedora is way above that threshold at the moment. Future EL releases will be above that as well. While on it, fix some of the linter errors that arise from the minimum version update. Co-authored-by: Yair Podemsky <ypodemsk@redhat.com> Signed-off-by: Beñat Gartzia Arruabarrena <bgartzia@redhat.com>
1 parent cd41689 commit 4131b91

7 files changed

Lines changed: 69 additions & 78 deletions

File tree

attestation-key-register/src/main.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async fn handle_registration(
4242
client: Client,
4343
addr: Option<SocketAddr>,
4444
) -> Result<impl warp::Reply, Infallible> {
45-
info!("Received registration request: {:?}", registration);
45+
info!("Received registration request: {registration:?}");
4646

4747
let api: Api<AttestationKey> = Api::default_namespaced(client);
4848

@@ -52,8 +52,7 @@ async fn handle_registration(
5252
if key.spec.public_key == registration.public_key {
5353
let existing_name = key.metadata.name.unwrap_or_default();
5454
error!(
55-
"Duplicate public key detected: already exists in AttestationKey '{}'",
56-
existing_name
55+
"Duplicate public key detected: already exists in AttestationKey '{existing_name}'"
5756
);
5857
return Ok(reply::with_status(
5958
reply::json(&serde_json::json!({
@@ -66,11 +65,11 @@ async fn handle_registration(
6665
}
6766
}
6867
Err(e) => {
69-
error!("Failed to list AttestationKeys: {}", e);
68+
error!("Failed to list AttestationKeys: {e}");
7069
return Ok(reply::with_status(
7170
reply::json(&serde_json::json!({
7271
"status": "error",
73-
"message": format!("Failed to check for existing keys: {}", e),
72+
"message": format!("Failed to check for existing keys: {e}"),
7473
})),
7574
StatusCode::INTERNAL_SERVER_ERROR,
7675
));
@@ -108,11 +107,11 @@ async fn handle_registration(
108107
))
109108
}
110109
Err(e) => {
111-
error!("Failed to create AttestationKey: {}", e);
110+
error!("Failed to create AttestationKey: {e}");
112111
Ok(reply::with_status(
113112
reply::json(&serde_json::json!({
114113
"status": "error",
115-
"message": format!("Failed to create AttestationKey: {}", e),
114+
"message": format!("Failed to create AttestationKey: {e}"),
116115
})),
117116
StatusCode::INTERNAL_SERVER_ERROR,
118117
))
@@ -147,7 +146,7 @@ async fn main() -> anyhow::Result<()> {
147146
.and_then(handle_registration);
148147

149148
let addr = SocketAddr::from(([0, 0, 0, 0], args.port));
150-
info!("Listening on {}", addr);
149+
info!("Listening on {addr}");
151150

152151
warp::serve(register).run(addr).await;
153152

operator/src/attestation_key_register.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,13 @@ async fn ak_reconcile(
133133
client: Arc<Client>,
134134
) -> Result<Action, ControllerError> {
135135
let ak_name = ak.metadata.name.clone().unwrap_or_default();
136-
info!("Attestation Key reconciliation for: {}", ak_name);
136+
info!("Attestation Key reconciliation for: {ak_name}");
137137

138138
let client = Arc::unwrap_or_clone(client);
139139
let machines: Api<Machine> = Api::default_namespaced(client.clone());
140140
let lp = ListParams::default();
141141
let machine_list: ObjectList<Machine> = machines.list(&lp).await.map_err(|e| {
142-
eprintln!("Error fetching machine list: {}", e);
142+
eprintln!("Error fetching machine list: {e}");
143143
ControllerError::Anyhow(e.into())
144144
})?;
145145
for machine in &machine_list.items {
@@ -180,15 +180,15 @@ async fn machine_reconcile(
180180
let aks: Api<AttestationKey> = Api::default_namespaced(client.clone());
181181
let lp = ListParams::default();
182182
let ak_list: ObjectList<AttestationKey> = aks.list(&lp).await.map_err(|e| {
183-
eprintln!("Error fetching attestation key list: {}", e);
183+
eprintln!("Error fetching attestation key list: {e}");
184184
ControllerError::Anyhow(e.into())
185185
})?;
186186
for ak in ak_list.items {
187-
if let Some(ak_address) = &ak.spec.address {
188-
if *ak_address == machine_address {
189-
approve_ak(&ak, &machine, client.clone()).await?;
190-
return Ok(Action::await_change());
191-
}
187+
if let Some(ak_address) = &ak.spec.address
188+
&& *ak_address == machine_address
189+
{
190+
approve_ak(&ak, &machine, client.clone()).await?;
191+
return Ok(Action::await_change());
192192
}
193193
}
194194
Ok(Action::await_change())
@@ -313,10 +313,7 @@ async fn secret_reconcile(
313313
return Ok(Action::await_change());
314314
}
315315

316-
info!(
317-
"Secret reconciliation for AttestationKey secret: {}",
318-
secret_name
319-
);
316+
info!("Secret reconciliation for AttestationKey secret: {secret_name}");
320317

321318
let secrets: Api<Secret> = Api::default_namespaced(Arc::unwrap_or_clone(client.clone()));
322319
finalizer(&secrets, ATTESTATION_KEY_SECRET_FINALIZER, secret, |ev| async move {
@@ -328,15 +325,14 @@ async fn secret_reconcile(
328325
.await
329326
.map(|_| Action::await_change())
330327
.map_err(|e| {
331-
eprintln!("Error updating attestation key volumes on secret apply: {}", e);
328+
eprintln!("Error updating attestation key volumes on secret apply: {e}");
332329
finalizer::Error::<ControllerError>::ApplyFailed(e.into())
333330
})
334331
}
335332
Event::Cleanup(secret) => {
336333
let secret_name = secret.metadata.name.clone().unwrap_or_default();
337334
info!(
338-
"AttestationKey secret {} is being deleted, updating trustee deployment volumes",
339-
secret_name
335+
"AttestationKey secret {secret_name} is being deleted, updating trustee deployment volumes"
340336
);
341337
let client = Arc::unwrap_or_clone(client);
342338
// Update trustee deployment - secrets with deletion_timestamp will be filtered out
@@ -345,8 +341,7 @@ async fn secret_reconcile(
345341
.map(|_| Action::await_change())
346342
.map_err(|e| {
347343
eprintln!(
348-
"Error updating attestation key volumes during secret deletion: {}",
349-
e
344+
"Error updating attestation key volumes during secret deletion: {e}"
350345
);
351346
finalizer::Error::<ControllerError>::CleanupFailed(e.into())
352347
})

operator/src/reference_values.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,13 @@ pub async fn handle_new_image(
297297
let config_maps: Api<ConfigMap> = Api::default_namespaced(ctx.client.clone());
298298
let mut image_pcrs_map = config_maps.get(PCR_CONFIG_MAP).await?;
299299
let mut image_pcrs = get_image_pcrs(image_pcrs_map.clone())?;
300-
if let Some(pcr) = image_pcrs.0.get(resource_name) {
301-
if pcr.reference == boot_image {
302-
info!("Image {boot_image} was to be allowed, but already was allowed");
303-
return trustee::update_reference_values(ctx)
304-
.await
305-
.map(|_| COMMITTED_REASON);
306-
}
300+
if let Some(pcr) = image_pcrs.0.get(resource_name)
301+
&& pcr.reference == boot_image
302+
{
303+
info!("Image {boot_image} was to be allowed, but already was allowed");
304+
return trustee::update_reference_values(ctx)
305+
.await
306+
.map(|_| COMMITTED_REASON);
307307
}
308308
let image_ref: oci_client::Reference = boot_image.parse()?;
309309
if image_ref.digest().is_none() {

operator/src/trustee.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ pub async fn update_attestation_keys(client: Client) -> Result<()> {
256256
name: secret_name.to_string(),
257257
items: Some(vec![KeyToPath {
258258
key: "public_key".to_string(),
259-
path: format!("{}.pub", secret_name),
259+
path: format!("{secret_name}.pub"),
260260
..Default::default()
261261
}]),
262262
..Default::default()

test_utils/src/lib.rs

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,12 @@ impl TestContext {
370370
async move {
371371
let deployment = api.get(&name).await?;
372372

373-
if let Some(status) = &deployment.status {
374-
if let Some(available_replicas) = status.available_replicas {
375-
if available_replicas == 1 {
376-
test_info!(&tn, "{} deployment has 1 available replica", name);
377-
return Ok(());
378-
}
379-
}
373+
if let Some(status) = &deployment.status
374+
&& let Some(available_replicas) = status.available_replicas
375+
&& available_replicas == 1
376+
{
377+
test_info!(&tn, "{} deployment has 1 available replica", name);
378+
return Ok(());
380379
}
381380

382381
Err(anyhow!(
@@ -485,36 +484,36 @@ impl TestContext {
485484
let ns = self.test_namespace.clone();
486485
let sa_src = workspace_root.join("config/rbac/service_account.yaml");
487486
let sa_content = std::fs::read_to_string(&sa_src)?
488-
.replace("namespace: system", &format!("namespace: {}", ns));
487+
.replace("namespace: system", &format!("namespace: {ns}"));
489488
let sa_dst = rbac_temp_dir.join("service_account.yaml");
490489
std::fs::write(&sa_dst, sa_content)?;
491490

492491
let role_path = rbac_temp_dir.join("role.yaml");
493492
let role_content = std::fs::read_to_string(&role_path)?.replace(
494493
"name: trusted-cluster-operator-role",
495-
&format!("name: {}-trusted-cluster-operator-role", ns),
494+
&format!("name: {ns}-trusted-cluster-operator-role"),
496495
);
497496
std::fs::write(&role_path, role_content)?;
498497

499498
let rb_src = workspace_root.join("config/rbac/role_binding.yaml");
500499
let rb = "name: manager-rolebinding";
501500
let role = "name: trusted-cluster-operator-role";
502501
let rb_content = std::fs::read_to_string(&rb_src)?
503-
.replace(rb, &format!("name: {}-manager-rolebinding", ns))
504-
.replace(role, &format!("name: {}-trusted-cluster-operator-role", ns))
505-
.replace("namespace: system", &format!("namespace: {}", ns));
502+
.replace(rb, &format!("name: {ns}-manager-rolebinding"))
503+
.replace(role, &format!("name: {ns}-trusted-cluster-operator-role"))
504+
.replace("namespace: system", &format!("namespace: {ns}"));
506505
let rb_dst = rbac_temp_dir.join("role_binding.yaml");
507506
std::fs::write(&rb_dst, rb_content)?;
508507

509508
let le_role_src = workspace_root.join("config/rbac/leader_election_role.yaml");
510509
let le_role_content = std::fs::read_to_string(&le_role_src)?
511-
.replace("namespace: system", &format!("namespace: {}", ns));
510+
.replace("namespace: system", &format!("namespace: {ns}"));
512511
let le_role_dst = rbac_temp_dir.join("leader_election_role.yaml");
513512
std::fs::write(&le_role_dst, le_role_content)?;
514513

515514
let le_rb_src = workspace_root.join("config/rbac/leader_election_role_binding.yaml");
516515
let le_rb_content = std::fs::read_to_string(&le_rb_src)?
517-
.replace("namespace: system", &format!("namespace: {}", ns));
516+
.replace("namespace: system", &format!("namespace: {ns}"));
518517
let le_rb_dst = rbac_temp_dir.join("leader_election_role_binding.yaml");
519518
std::fs::write(&le_rb_dst, le_rb_content)?;
520519

@@ -570,13 +569,13 @@ impl TestContext {
570569
let cr_content = std::fs::read_to_string(&cr_manifest_path)?;
571570
let mut cr_value: serde_yaml::Value = serde_yaml::from_str(&cr_content)?;
572571

573-
if let Some(spec) = cr_value.get_mut("spec") {
574-
if let Some(spec_map) = spec.as_mapping_mut() {
575-
spec_map.insert(
576-
serde_yaml::Value::String("publicTrusteeAddr".to_string()),
577-
serde_yaml::Value::String(trustee_addr.clone()),
578-
);
579-
}
572+
if let Some(spec) = cr_value.get_mut("spec")
573+
&& let Some(spec_map) = spec.as_mapping_mut()
574+
{
575+
spec_map.insert(
576+
serde_yaml::Value::String("publicTrusteeAddr".to_string()),
577+
serde_yaml::Value::String(trustee_addr.clone()),
578+
);
580579
}
581580

582581
let updated_content = serde_yaml::to_string(&cr_value)?;

tests/attestation.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,17 @@ impl SingleAttestationContext {
3838
async fn new(vm_name: &str, test_ctx: &TestContext) -> Result<Self> {
3939
let client = test_ctx.client();
4040
let namespace = test_ctx.namespace();
41+
4142
let backend = virt::create_backend(client.clone(), namespace, vm_name)?;
4243

43-
test_ctx.info(format!("Creating VM: {}", vm_name));
44+
test_ctx.info(format!("Creating VM: {vm_name}"));
4445
backend.create_vm().await?;
4546

46-
test_ctx.info(format!("Waiting for VM {} to reach Running state", vm_name));
47+
test_ctx.info(format!("Waiting for VM {vm_name} to reach Running state"));
4748
backend.wait_for_running(600).await?;
48-
test_ctx.info(format!("VM {} is Running", vm_name));
49+
ttest_ctx.info(format!("VM {vm_name} is Running"));
4950

50-
test_ctx.info(format!("Waiting for SSH access to VM {}", vm_name));
51+
test_ctx.info(format!("Waiting for SSH access to VM {vm_name}"));
5152
backend.wait_for_vm_ssh_ready(600).await?;
5253
test_ctx.info("SSH access is ready");
5354

@@ -162,29 +163,29 @@ async fn test_vm_reboot_attestation() -> anyhow::Result<()> {
162163
// Perform multiple reboots
163164
let num_reboots = 3;
164165
for i in 1..=num_reboots {
165-
test_ctx.info(format!("Performing reboot {} of {}", i, num_reboots));
166+
test_ctx.info(format!("Performing reboot {i} of {num_reboots}"));
166167

167168
// Reboot the VM via SSH
168169
let _reboot_result = att_ctx.backend.ssh_exec("sudo systemctl reboot").await;
169170

170-
test_ctx.info(format!("Waiting for lack of SSH access after reboot {}", i));
171+
test_ctx.info(format!("Waiting for lack of SSH access after reboot {i}"));
171172
att_ctx.backend.wait_for_vm_ssh_unavail(30).await?;
172173

173-
test_ctx.info(format!("Waiting for SSH access after reboot {}", i));
174+
test_ctx.info(format!("Waiting for SSH access after reboot {i}"));
174175
att_ctx.backend.wait_for_vm_ssh_ready(300).await?;
175176

176177
// Verify encrypted root is still present after reboot
177-
test_ctx.info(format!("Verifying encrypted root after reboot {}", i));
178+
test_ctx.info(format!("Verifying encrypted root after reboot {i}"));
178179
let has_encrypted_root = att_ctx.verify_encrypted_root().await?;
179180
assert!(
180181
has_encrypted_root,
181182
"VM should have encrypted root device after reboot {i}"
182183
);
183-
test_ctx.info(format!("Reboot {}: attestation successful", i));
184+
test_ctx.info(format!("Reboot {i}: attestation successful"));
184185
}
185186

186187
test_ctx.info(format!(
187-
"VM successfully rebooted {num_reboots} times with encrypted root device maintained",
188+
"VM successfully rebooted {num_reboots} times with encrypted root device maintained"
188189
));
189190
att_ctx.cleanup().await?;
190191
test_ctx.cleanup().await?;

tests/trusted_execution_cluster.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ async fn test_image_pcrs_configmap_updates() -> anyhow::Result<()> {
6060
async move {
6161
let cm = api.get("image-pcrs").await?;
6262

63-
if let Some(data) = &cm.data {
64-
if let Some(image_pcrs_json) = data.get("image-pcrs.json") {
65-
if let Ok(image_pcrs) = serde_json::from_str::<ImagePcrs>(image_pcrs_json) {
66-
if !image_pcrs.0.is_empty() {
67-
return Ok(());
68-
}
69-
}
70-
}
63+
if let Some(data) = &cm.data
64+
&& let Some(image_pcrs_json) = data.get("image-pcrs.json")
65+
&& let Ok(image_pcrs) = serde_json::from_str::<ImagePcrs>(image_pcrs_json)
66+
&& !image_pcrs.0.is_empty()
67+
{
68+
return Ok(());
7169
}
7270

7371
Err(anyhow::anyhow!("image-pcrs ConfigMap not yet populated with image-pcrs.json data"))
@@ -167,12 +165,11 @@ async fn test_image_disallow() -> anyhow::Result<()> {
167165
let api = configmap_api.clone();
168166
async move {
169167
let cm = api.get("trustee-data").await?;
170-
if let Some(data) = &cm.data {
171-
if let Some(reference_values_json) = data.get("reference-values.json") {
172-
if !reference_values_json.contains(EXPECTED_PCR4) {
173-
return Ok(());
174-
}
175-
}
168+
if let Some(data) = &cm.data
169+
&& let Some(reference_values_json) = data.get("reference-values.json")
170+
&& !reference_values_json.contains(EXPECTED_PCR4)
171+
{
172+
return Ok(());
176173
}
177174
Err(anyhow::anyhow!("Reference value not yet removed"))
178175
}

0 commit comments

Comments
 (0)