Skip to content

resolve question marks in /etc/hostname to characters hashed from machine ID#36647

Merged
yuwata merged 4 commits intosystemd:mainfrom
poettering:hostname-hashmark
Mar 11, 2025
Merged

resolve question marks in /etc/hostname to characters hashed from machine ID#36647
yuwata merged 4 commits intosystemd:mainfrom
poettering:hostname-hashmark

Conversation

@poettering
Copy link
Copy Markdown
Member

so i have a bunch of particle os instances around, that i frequently factory reset. and it's confusing, since they all have the same name. Let's do something about this, and extend the hostname setup logic a bit to deal better with "cattle" rather than "pet" deployments. Specifically: if a hostname in /etc/hostname contains a bunch of question marks we'll replace it with hex chars hashed from the machine id.

This allows us to do something like this:

hostnamectl set-hostname --static 'funky-????-????-???'

and we'll end up with a hostname like funky-baf4-b653-e230

@poettering
Copy link
Copy Markdown
Member Author

i guess we could increase the entropy a bit by not using a 16 character alphabet, but a 32 character alphabet for the characters we insert, i.e. 0-9a-v, i.e. would encode 5bit per question mark to replace, instead of just 4. would mean for 128bit entropy we'd need 26 chars instead of 32 chars. i.e. we'd be much shorter than a uuid for the same amount of entropy...

poettering added a commit to poettering/particleos that referenced this pull request Mar 7, 2025
This depends on systemd/systemd#36647

This gives every instance of ParticleOS a slightly different hostname
(well, within the bounds of 2^32), which is quite useful when operating
with a number of them.
poettering added a commit to poettering/particleos that referenced this pull request Mar 7, 2025
This depends on systemd/systemd#36647

This gives every instance of ParticleOS a slightly different hostname
(well, within the bounds of 2^32), which is quite useful when operating
with a number of them.
@poettering poettering force-pushed the hostname-hashmark branch 3 times, most recently from 9ae0560 to 1f325c5 Compare March 7, 2025 21:30
Copy link
Copy Markdown
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. But several minor requests.

@yuwata yuwata added reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks and removed please-review PR is ready for (re-)review by a maintainer labels Mar 9, 2025
@github-actions github-actions bot added please-review PR is ready for (re-)review by a maintainer and removed reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Mar 11, 2025
Copy link
Copy Markdown
Member

@yuwata yuwata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One suggestion.

@yuwata yuwata added good-to-merge/with-minor-suggestions and removed please-review PR is ready for (re-)review by a maintainer labels Mar 11, 2025
…stname-setup.c

In one of the next commits we'd like to introduce a concept of
optionally hashing the hostname from the machine ID. For that we we need
to optionally back gethostname_full() by code involving sd-id128, hence
let's move it from src/basic/ to src/shared/, since only there we are
allowed to use our public APIs.
@poettering poettering added good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed and removed good-to-merge/with-minor-suggestions labels Mar 11, 2025
@yuwata
Copy link
Copy Markdown
Member

yuwata commented Mar 11, 2025

All mkosi failures are unrelated, and hopefully half of them will be fixed by #36691.

@yuwata yuwata merged commit ced634a into systemd:main Mar 11, 2025
39 of 47 checks passed
@github-actions github-actions bot removed the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Mar 11, 2025
* public information to be broadcast on the network, while the hostname certainly is. */

for (char *n = name; *n; n++) {
if (*n != '?')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strchr?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-> #36707.

yuwata added a commit to yuwata/systemd that referenced this pull request Mar 11, 2025
daandemeyer pushed a commit to systemd/particleos that referenced this pull request Mar 12, 2025
This depends on systemd/systemd#36647

This gives every instance of ParticleOS a slightly different hostname
(well, within the bounds of 2^32), which is quite useful when operating
with a number of them.
ddstreet pushed a commit to ddstreet/particleos that referenced this pull request Mar 14, 2025
This depends on systemd/systemd#36647

This gives every instance of ParticleOS a slightly different hostname
(well, within the bounds of 2^32), which is quite useful when operating
with a number of them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants