-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Have a real fixed HostID on Linux #603
Conversation
On Linux, most golang programs do not run as root (or at least, they should not), by default, the kernels uses strict permissions, so most userland programs cannot read `/sys/class/dmi/id/product_uuid`. However, programs such as Consul are relying on it to get fixed IDs, instead they have a different ID on each boot. We propose to use `/etc/machine-id` as fallback https://www.freedesktop.org/software/systemd/man/machine-id.html In order to fix this, this patch does the following: - if `/sys/class/dmi/id/product_uuid` can be read, use it for HostID - else if `/etc/machine-id` exists and has 32 chars, use it and add '-' to have the same format as product_uuid - finally, if notthing works, use the `kernel.random.boot_id` This will greatly increase the number of programs having correct behaviour when those rely on having a fixed HostID. This will fix the following issues: - shirou#350 - hashicorp/consul#4741
@Lomanic yes, but this case is already properly handled with error management below. What I mean is, this case (file not being readable is not the exception: some weird kernel config or unusual arch), but the rule (I mean, only programs running as root can use it, which in 2018 should be the exception, not the rule) |
98c39f5
to
890eb80
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 👍
@Lomanic Thank you for the review |
LGTM |
Wow, Great! Your are thinking backward compatibility so much! |
@shirou Thank you! Do you think you might release a new version, so I can fix the bug in Consul by updating this library? Kind Regards |
Releases are once per month, following calver like Ubuntu, see Tag semantics |
Bump `shirou/gopsutil` to include shirou/gopsutil#603 This will allow to have consistent node-id even when machine is reinstalled when using `"disable_host_node_id": false` It will fix hashicorp#4914 and allow having the same node-id even when reinstalling a node from scratch. However, it is only compatible with a single OS (installing to Windows will change the node-id, but it seems acceptable).
+1 |
…4926) Bump `shirou/gopsutil` to include shirou/gopsutil#603 This will allow to have consistent node-id even when machine is reinstalled when using `"disable_host_node_id": false` It will fix #4914 and allow having the same node-id even when reinstalling a node from scratch. However, it is only compatible with a single OS (installing to Windows will change the node-id, but it seems acceptable).
On Linux, most golang programs do not run as root (or at least, they should not),
by default, the kernels uses strict permissions, so most userland programs cannot
read
/sys/class/dmi/id/product_uuid
. However, programs such as Consul are relyingon it to get fixed IDs, instead they have a different ID on each boot.
We propose to use
/etc/machine-id
as fallback https://www.freedesktop.org/software/systemd/man/machine-id.htmlIn order to fix this, this patch does the following:
/sys/class/dmi/id/product_uuid
can be read, use it for HostID/etc/machine-id
exists and has 32 chars, use it and add '-' to have the same format as product_uuidkernel.random.boot_id
This will greatly increase the number of programs having correct behaviour when
those rely on having a fixed HostID.
This will fix the following issues: