Skip to content

Commit 9f8b522

Browse files
committed
fix(tool): better error if public key is missing
Old: building the system configuration... Installing Lanzaboote to "/boot"... Failed to install generation.: No such file or directory (os error 2) Failed to install bootloader warning: error(s) occurred while switching to the new configuration New: building the system configuration... Installing Lanzaboote to "/boot"... Failed to install generation 1: get stub name: read public key '/etc/secureboot/keys/db/db.pem': No such file or directory (os error 2) Failed to install bootloader warning: error(s) occurred while switching to the new configuration
1 parent f3b4ade commit 9f8b522

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

rust/tool/systemd/src/install.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl Installer {
161161
// The kernels and initrds are content-addressed.
162162
// Thus, this cannot overwrite files of old generation with different content.
163163
self.install_generation(&generation)
164-
.context("Failed to install generation.")?;
164+
.with_context(|| format!("Failed to install generation {}", generation.version))?;
165165
for (name, bootspec) in &generation.spec.bootspec.specialisations {
166166
let specialised_generation = generation.specialise(name, bootspec);
167167
self.install_generation(&specialised_generation)
@@ -252,7 +252,7 @@ impl Installer {
252252
let stub_target = self
253253
.esp_paths
254254
.linux
255-
.join(stub_name(generation, &self.key_pair.public_key)?);
255+
.join(stub_name(generation, &self.key_pair.public_key).context("get stub name")?);
256256
self.gc_roots.extend([&stub_target]);
257257
install_signed(&self.key_pair, &lanzaboote_image, &stub_target)
258258
.context("Failed to install the Lanzaboote stub.")?;
@@ -267,8 +267,9 @@ impl Installer {
267267
let stub_target = self
268268
.esp_paths
269269
.linux
270-
.join(stub_name(generation, &self.key_pair.public_key)?);
271-
let stub = fs::read(&stub_target)?;
270+
.join(stub_name(generation, &self.key_pair.public_key).context("get stub name")?);
271+
let stub = fs::read(&stub_target)
272+
.with_context(|| format!("Failed to read the stub: {}", stub_target.display()))?;
272273
let kernel_path = resolve_efi_path(
273274
&self.esp_paths.esp,
274275
pe::read_section_data(&stub, ".linux").context("Missing kernel path.")?,
@@ -369,7 +370,7 @@ fn stub_name(generation: &Generation, public_key: &Path) -> Result<PathBuf> {
369370
("toplevel", bootspec.toplevel.0.as_os_str().as_bytes()),
370371
// If the key is rotated, the signed stubs must be re-generated.
371372
// So we make their path depend on the public key used for signature.
372-
("public_key", &fs::read(public_key)?),
373+
("public_key", &fs::read(public_key).with_context(|| format!("read public key '{}'", public_key.display()))?),
373374
];
374375
let stub_input_hash = Base32Unpadded::encode_string(&Sha256::digest(
375376
serde_json::to_string(&stub_inputs).unwrap(),

0 commit comments

Comments
 (0)