Skip to content

Commit 1677346

Browse files
committed
add header file export before path check
header file info would not be added to the image if a path was used for the device. This should fix that. also improves comments Closes: #302 Signed-off-by: Zen <[email protected]>
1 parent 6370d12 commit 1677346

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/ugrd/crypto/cryptsetup.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "4.1.2"
2+
__version__ = "4.1.3"
33

44
from json import loads
55
from pathlib import Path
@@ -404,15 +404,19 @@ def _validate_luks_config(self, mapped_name: str) -> None:
404404

405405
def export_crypt_sources(self) -> list[str]:
406406
"""Validates the cryptsetup configuration (if enabled).
407+
Sets CRYPTSETUP_HEADER_{name} if a header file is set.
407408
Adds the cryptsetup source and token to the exports.
408409
Sets the token to the partuuid or uuid if it exists.
409410
Sets the SOURCE when using a path.
410411
Only allows using the path if validation is disabled.
411-
sets CRYPTSETUP_HEADER_{name} if a header file is set.
412412
"""
413413
for name, parameters in self["cryptsetup"].items():
414-
_validate_luks_config(self, name)
415-
if parameters.get("path"):
414+
_validate_luks_config(self, name) # First validate the configuration
415+
if header_file := parameters.get("header_file"): # Then add the header file to the exports, if defined
416+
self["exports"]["CRYPTSETUP_HEADER_%s" % name] = header_file
417+
self.logger.debug("Set CRYPTSETUP_HEADER_%s: %s" % (name, header_file))
418+
419+
if parameters.get("path"): # If a path is set, only allow it if validation is disabled
416420
if not self["validate"]:
417421
self.logger.warning(
418422
"Using device paths is unreliable and can result in boot failures. Consider using partuuid."
@@ -424,16 +428,13 @@ def export_crypt_sources(self) -> list[str]:
424428
elif not parameters.get("partuuid") and not parameters.get("uuid") and parameters.get("path"):
425429
raise ValidationError("Device source for cryptsetup mount must be specified: %s" % name)
426430

427-
for token_type in ["partuuid", "uuid"]:
431+
for token_type in ["partuuid", "uuid"]: # Attempt to set the token from partuuid or uuid
428432
if token := parameters.get(token_type):
429433
self["exports"]["CRYPTSETUP_TOKEN_%s" % name] = f"{token_type.upper()}={token}"
430434
self.logger.debug("Set CRYPTSETUP_TOKEN_%s: %s=%s" % (name, token_type.upper(), token))
431435
break
432-
else:
436+
else: # Raise an error if no usable token/config is set
433437
raise ValidationError("A partuuid or uuid must be specified for cryptsetup mount: %s" % name)
434-
if header_file := parameters.get("header_file"):
435-
self["exports"]["CRYPTSETUP_HEADER_%s" % name] = header_file
436-
self.logger.debug("Set CRYPTSETUP_HEADER_%s: %s" % (name, header_file))
437438

438439

439440
def get_crypt_dev(self) -> str:

0 commit comments

Comments
 (0)