Page MenuHomeFreeBSD

Fix format of /etc/machine-id and generate from rc.d/hostid_save
ClosedPublic

Authored by tijl on Feb 27 2023, 6:06 PM.
Tags
Referenced Files
F103106541: D38811.id.diff
Thu, Nov 21, 2:09 AM
F103103267: D38811.diff
Thu, Nov 21, 1:01 AM
F103087352: D38811.diff
Wed, Nov 20, 7:09 PM
Unknown Object (File)
Tue, Oct 29, 1:00 PM
Unknown Object (File)
Sun, Oct 27, 9:26 AM
Unknown Object (File)
Sun, Oct 27, 9:25 AM
Unknown Object (File)
Sun, Oct 27, 9:25 AM
Unknown Object (File)
Sun, Oct 27, 9:15 AM

Details

Summary

/etc/machine-id as currently generated by rc.d/machine_id contains hyphens which is incorrect according to the Linux documentation. As a consequence programs like dbus ignore the file. It would be best if this could be fixed before the release of 13.2.

rc.d/hostid_save provides similar functionality.

This patch is a proposal to generate /etc/machine-id from rc.d/hostid_save so it contains the same uuid but with hyphens removed. They are removed using a shell function because other utilities may not be available yet when rc.d/hostid_save runs.

The logic in rc.d/hostid_save has to be changed a bit to eliminate an early 'exit' call.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

tijl requested review of this revision.Feb 27 2023, 6:06 PM
This revision is now accepted and ready to land.Feb 27 2023, 6:26 PM
bapt requested changes to this revision.Feb 27 2023, 7:32 PM

no hostid is not generating the same uuid, machine-id is based on uuidgen -r which generate version 4 UUID (RFC422), but you are right, about the hyphen.

This revision now requires changes to proceed.Feb 27 2023, 7:32 PM
In D38811#883365, @bapt wrote:

no hostid is not generating the same uuid, machine-id is based on uuidgen -r which generate version 4 UUID (RFC422), but you are right, about the hyphen.

Yes, I meant to say the same uuid as hostid. I don't think there's a need for these to be different.

In D38811#883424, @tijl wrote:
In D38811#883365, @bapt wrote:

no hostid is not generating the same uuid, machine-id is based on uuidgen -r which generate version 4 UUID (RFC422), but you are right, about the hyphen.

Yes, I meant to say the same uuid as hostid. I don't think there's a need for these to be different.

I would simply fix the creator to remove the hyphens before writing them to the machine-id file. Then we'll still have UUID v4.
The point of the whole thing is to have the compliant interface that modern software expects.

etc/Makefile
61

that would make machine-id inaccessible for readonly root partitions.

I would simply fix the creator to remove the hyphens before writing them to the machine-id file. Then we'll still have UUID v4.
The point of the whole thing is to have the compliant interface that modern software expects.

Systemd only generates v4 as a last resort, so software cannot assume it is v4. It can't even assume it follows RFC 4122 because dbus-uuidgen and old versions of systemd just produce a random number.

I think one UUID per machine is easier to manage and generating /etc/machine-id from rc.d/hostid_save removes some redundancy. If v4 is preferred then rc.d/hostid can be patched to run "uuidgen -r" or "uuidgen ${uuidgen_flags}" with uuidgen_flags set to -r by default. I could include that in this patch but I think it is a separate issue.

etc/Makefile
61

Yes, I suggested putting the file in /var in the original review. Now I think it's acceptable if it's in /etc because it is only written once like /etc/hostid is. Ideally both files would be generated during OS install and by tools like etcupdate but that's beyond the scope of this patch. /var may not be available because rc.d/hostid_save runs before filesystems are mounted because it seems it may be needed for that. I see references to /etc/hostid in ZFS and NFS code, but I can't tell if it is actually needed for mounting.

In D38811#883667, @tijl wrote:

I would simply fix the creator to remove the hyphens before writing them to the machine-id file. Then we'll still have UUID v4.
The point of the whole thing is to have the compliant interface that modern software expects.

Systemd only generates v4 as a last resort, so software cannot assume it is v4. It can't even assume it follows RFC 4122 because dbus-uuidgen and old versions of systemd just produce a random number.

I think one UUID per machine is easier to manage and generating /etc/machine-id from rc.d/hostid_save removes some redundancy. If v4 is preferred then rc.d/hostid can be patched to run "uuidgen -r" or "uuidgen ${uuidgen_flags}" with uuidgen_flags set to -r by default. I could include that in this patch but I think it is a separate issue.

This is not a last resort, this is the default if no previous machine-id do exist. some program may expect RFC 4122 at some point (some already talk about it iirc) that is why we directly went to it for new. imho this ship has sailed.

As for merging ostid and machind-id, if done, then imho it should be done in a separate effort, let's just add the compact version support to uuidgen and be done for 13.2 imho.

In D38811#883669, @bapt wrote:
In D38811#883667, @tijl wrote:

I would simply fix the creator to remove the hyphens before writing them to the machine-id file. Then we'll still have UUID v4.
The point of the whole thing is to have the compliant interface that modern software expects.

Systemd only generates v4 as a last resort, so software cannot assume it is v4. It can't even assume it follows RFC 4122 because dbus-uuidgen and old versions of systemd just produce a random number.

I think one UUID per machine is easier to manage and generating /etc/machine-id from rc.d/hostid_save removes some redundancy. If v4 is preferred then rc.d/hostid can be patched to run "uuidgen -r" or "uuidgen ${uuidgen_flags}" with uuidgen_flags set to -r by default. I could include that in this patch but I think it is a separate issue.

This is not a last resort, this is the default if no previous machine-id do exist. some program may expect RFC 4122 at some point (some already talk about it iirc) that is why we directly went to it for new. imho this ship has sailed.

I haven't looked at the systemd code but the man page for /etc/machine-id says it's last resort: "...and finally a randomly generated UUID." Systemd looks in many locations for a UUID and these can be of any version described in RFC 4122 or not comply with that RFC at all such as /var/lib/dbus/machine-id.

This revision was not accepted when it landed; it landed in state Needs Revision.Mar 9 2023, 9:38 AM
This revision was automatically updated to reflect the committed changes.