Skip to content

Commit 78a3551

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 78a3551

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

rust/tool/systemd/src/install.rs

+12-8
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.")?;
@@ -264,11 +264,11 @@ impl Installer {
264264
///
265265
/// An error should not be considered fatal; the generation should be (re-)installed instead.
266266
fn register_installed_generation(&mut self, generation: &Generation) -> Result<()> {
267-
let stub_target = self
268-
.esp_paths
269-
.linux
270-
.join(stub_name(generation, &self.key_pair.public_key)?);
271-
let stub = fs::read(&stub_target)?;
267+
let stub_target = self.esp_paths.linux.join(
268+
stub_name(generation, &self.key_pair.public_key).context("While getting stub name")?,
269+
);
270+
let stub = fs::read(&stub_target)
271+
.with_context(|| format!("Failed to read the stub: {}", stub_target.display()))?;
272272
let kernel_path = resolve_efi_path(
273273
&self.esp_paths.esp,
274274
pe::read_section_data(&stub, ".linux").context("Missing kernel path.")?,
@@ -369,7 +369,11 @@ fn stub_name(generation: &Generation, public_key: &Path) -> Result<PathBuf> {
369369
("toplevel", bootspec.toplevel.0.as_os_str().as_bytes()),
370370
// If the key is rotated, the signed stubs must be re-generated.
371371
// So we make their path depend on the public key used for signature.
372-
("public_key", &fs::read(public_key)?),
372+
(
373+
"public_key",
374+
&fs::read(public_key)
375+
.with_context(|| format!("Failed read public key '{}'", public_key.display()))?,
376+
),
373377
];
374378
let stub_input_hash = Base32Unpadded::encode_string(&Sha256::digest(
375379
serde_json::to_string(&stub_inputs).unwrap(),

0 commit comments

Comments
 (0)