Bug 2179056

Summary: [leapp] Failed to read machine ID from container image: Invalid argument
Product: Red Hat Enterprise Linux 7 Reporter: Christophe Besson <cbesson>
Component: leapp-repositoryAssignee: Leapp Notifications Bot <leapp-notifications-bot>
Status: NEW --- QA Contact: upgrades-and-conversions
Severity: low Docs Contact:
Priority: low    
Version: 7.9Keywords: Reproducer, WorkAround
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Christophe Besson 2023-03-16 14:22:30 UTC
Description of problem:
If the /etc/machine-id file is not well-formed, systemd-nspawn used by leapp exits with a -1 return code, leading to the emergency shell. This is harmless as it happens very early and the system is untouched.

Version-Release number of selected component (if applicable):
leapp-upgrade-el7toel8-0.17.0-1.el7_9

How reproducible:
Always

Steps to Reproduce:
1. echo >> /etc/machine-id
2. leapp upgrade

Actual results:
[    2.462635] upgrade[691]: Failed to read machine ID from container image: Invalid argument
[    2.476214] upgrade[690]: (sd-namespace) failed with exit status 1.

Expected results:
Possibly an inhibitor.

Additional info:
* Never observed such an issue, hence very low sev. This file should not have been touched (by a human or a script).
* Probably the same for IPU 8>9.
* The KCS I linked could be enough.
* Some systemd-nspawn excerpt:

	systemd-239/src/nspawn/nspawn.c:
	2187 static int setup_machine_id(const char *directory) {
	 :
	2198 
	2199         etc_machine_id = prefix_roota(directory, "/etc/machine-id");
	2200 
	2201         r = id128_read(etc_machine_id, ID128_PLAIN, &id);
	2202         if (r < 0) {
	2203                 if (!IN_SET(r, -ENOENT, -ENOMEDIUM)) /* If the file is missing or empty, we don't mind */
	2204                         return log_error_errno(r, "Failed to read machine ID from container image: %m");

	systemd-239/src/libsystemd/sd-id128/id128-util.c:
	 82 int id128_read_fd(int fd, Id128Format f, sd_id128_t *ret) {
	 :
	102         case 33: /* plain UUID with trailing newline */
	103                 if (buffer[32] != '\n')
	104                         return -EINVAL;
	105 
	106                 _fallthrough_;
	107         case 32: /* plain UUID without trailing newline */
	108                 if (f == ID128_UUID)
	109                         return -EINVAL;
	110 
	111                 buffer[32] = 0;
	112                 break;
	113 
	114         case 37: /* RFC UUID with trailing newline */
	115                 if (buffer[36] != '\n')
	116                         return -EINVAL;
	117 
	118                 _fallthrough_;
	119         case 36: /* RFC UUID without trailing newline */
	120                 if (f == ID128_PLAIN)
	121                         return -EINVAL;