Skip to content

Make Mender node_id generation always authoritative on RPi - #41

Open
jehanazad wants to merge 2 commits into
mainfrom
claude/amazing-ride-4Q0Dk
Open

Make Mender node_id generation always authoritative on RPi#41
jehanazad wants to merge 2 commits into
mainfrom
claude/amazing-ride-4Q0Dk

Conversation

@jehanazad

Copy link
Copy Markdown
Contributor

Summary

This change modifies the Mender device identity generation to always derive the node_id from the Raspberry Pi serial number on RPi hardware, rather than only on first boot. This ensures that stale node_id values baked into golden images are automatically refreshed, while maintaining backward compatibility with cached values on non-RPi hardware.

Key Changes

  • RPi serial as authoritative source: On Raspberry Pi hardware, the node_id is now always derived from /proc/cpuinfo serial, not just on first boot
  • Cache refresh logic: The cached node_id is only updated if it differs from the current serial-derived value, preventing unnecessary writes
  • Improved fallback chain: Non-RPi hardware now falls back to cached node_id first, then MAC address as a last resort
  • Golden image cleanup: Both rootfs2image and rootfs2image.edi now remove cached node_id files during image generation to ensure each device generates its own unique ID on first boot
  • Atomic writes preserved: The existing atomic write pattern (using temporary files and mv) is maintained for cache updates

Implementation Details

  • The RPi detection logic remains unchanged (checking for "Raspberry Pi" or "BCM" in /proc/cpuinfo)
  • The node_id format stays consistent: ret prefix + last 8 hex characters of serial
  • Cache refresh only occurs when the computed node_id differs from the cached value, optimizing for the common case where they match
  • The cleanup in image generation scripts ensures golden images don't carry stale node_id values that could cause device identity collisions

https://claude.ai/code/session_014KRrakaPXvCUSgXQcjvKhs

claude added 2 commits May 31, 2026 18:13
…irst boot

The Mender device identity script caches node_id to /data/mender/node_id on
first run. If this file exists in the rootfs at image creation time it gets
baked into the data partition, causing every flashed device to share the same
identity and appear as a single device in the Mender dashboard.

Remove it during postprocessing alongside machine-id, which is already cleaned
for the same reason.

https://claude.ai/code/session_014KRrakaPXvCUSgXQcjvKhs
Devices were appearing as duplicates in the Mender dashboard because a stale
node_id (from the device used to build/test the golden image) was persisted
on the data partition. Every device flashed from that image inherited the same
identity.

Two-layer fix:
1. Identity script: on RPi hardware, always derive node_id from the hardware
   serial rather than trusting a cached value. The cache is refreshed if stale,
   so existing devices self-heal on next mender-authd invocation without manual
   intervention.
2. Postprocessing: explicitly remove node_id from the data partition during
   image creation (defence-in-depth, mirrors existing machine-id removal).

https://claude.ai/code/session_014KRrakaPXvCUSgXQcjvKhs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants