From 385a42034aa268b77e5163a8de78149c8bead8c3 Mon Sep 17 00:00:00 2001 From: Thomas Stallinger Date: Fri, 28 Aug 2026 10:36:07 +0200 Subject: [PATCH] device_fingerprint zusaetzlich lokal auf dem Geraet hinterlegen Siehe ADR-0022 (platform-docs). Beide Backends lesen den bereits waehrend des Live-Boots berechneten Fingerprint aus hardware.json und schreiben ihn nach /etc/tuxflotte/device_fingerprint - ermoeglicht beidseitige Identifikation (Geraeteliste <-> Geraet selbst), vorher nur einseitig moeglich. Co-Authored-By: Claude Opus 5 --- backends/fedora/backend.sh | 18 +++++++++++++++++- backends/fedora/kickstart.tpl | 9 +++++++++ backends/mint/backend.sh | 18 +++++++++++++++++- backends/mint/postinstall.sh | 10 ++++++++++ 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/backends/fedora/backend.sh b/backends/fedora/backend.sh index 440fe85..fa78467 100755 --- a/backends/fedora/backend.sh +++ b/backends/fedora/backend.sh @@ -11,6 +11,10 @@ KICKSTART_TEMPLATE="${BACKEND_DIR}/kickstart.tpl" RUNTIME_BLUEPRINT_FILE="/run/tuxflotte/runtime/runtime_blueprint.json" SERVER_RESPONSE_FILE="/run/tuxflotte/server/response.json" +# Von 10_hardware.sh im selben Live-Boot geschrieben (siehe dort) - Quelle +# fuer den Fingerprint, der jetzt auch auf dem installierten Geraet selbst +# hinterlegt wird (siehe backend_generate_config()/kickstart.tpl %post). +HARDWARE_FILE="/run/tuxflotte/hardware/hardware.json" RUNTIME_DIR="/run/tuxflotte/backend" CONFIG_FILE="${RUNTIME_DIR}/config" @@ -85,6 +89,17 @@ backend_generate_config() { [[ -n "${device_id}" ]] || { backend_fatal "Keine Geräte-ID in der Serverantwort gefunden."; return 1; } + # Fuer die beidseitige Identifikation (Geraeteliste <-> Geraet selbst, + # siehe kickstart.tpl %post) - aus der bereits waehrend des Live-Boots + # berechneten hardware.json, nicht aus der Serverantwort (die kennt nur + # die zugewiesene device_id, nicht den urspruenglichen Hardware-Hash). + local device_fingerprint + [[ -r "${HARDWARE_FILE}" ]] || + { backend_fatal "Hardware-Erfassung nicht gefunden: ${HARDWARE_FILE}"; return 1; } + device_fingerprint="$(jq --raw-output '.identity.device_fingerprint // empty' "${HARDWARE_FILE}")" + [[ -n "${device_fingerprint}" ]] || + { backend_fatal "Kein device_fingerprint in ${HARDWARE_FILE} gefunden."; return 1; } + disk_encryption="$(jq --raw-output '.runtime_blueprint.installation_directives.disk_encryption' "${RUNTIME_BLUEPRINT_FILE}")" partitioning="$(jq --raw-output '.runtime_blueprint.installation_directives.partitioning' "${RUNTIME_BLUEPRINT_FILE}")" secure_boot_required="$(jq --raw-output '.runtime_blueprint.installation_directives.secure_boot_required' "${RUNTIME_BLUEPRINT_FILE}")" @@ -113,7 +128,8 @@ backend_generate_config() { TUXFLOTTE_DEVICE_ID="${device_id}" \ TUXFLOTTE_PARTITIONING_COMMAND="${partitioning_command}" \ TUXFLOTTE_BLUEPRINTS_JSON="${blueprints_json}" \ - envsubst '${TUXFLOTTE_HOSTNAME} ${TUXFLOTTE_DEVICE_ID} ${TUXFLOTTE_PARTITIONING_COMMAND} ${TUXFLOTTE_BLUEPRINTS_JSON}' \ + TUXFLOTTE_DEVICE_FINGERPRINT="${device_fingerprint}" \ + envsubst '${TUXFLOTTE_HOSTNAME} ${TUXFLOTTE_DEVICE_ID} ${TUXFLOTTE_PARTITIONING_COMMAND} ${TUXFLOTTE_BLUEPRINTS_JSON} ${TUXFLOTTE_DEVICE_FINGERPRINT}' \ <"${KICKSTART_TEMPLATE}" >"${CONFIG_FILE}" chmod 0600 "${CONFIG_FILE}" diff --git a/backends/fedora/kickstart.tpl b/backends/fedora/kickstart.tpl index 9796996..65f4da7 100644 --- a/backends/fedora/kickstart.tpl +++ b/backends/fedora/kickstart.tpl @@ -45,6 +45,15 @@ localectl set-x11-keymap de install -d -m 0700 /etc/tuxflotte +# Identifikation soll in beide Richtungen moeglich sein: die Geraeteliste +# zeigt den Fingerprint bereits an (siehe geraete_liste.html), aber bislang +# gab es auf dem installierten Geraet selbst keine Datei, um ihn mit einem +# einfachen "cat" gegenzupruefen - build_device_fingerprint() (10_hardware.sh) +# berechnet ihn nur einmalig waehrend des Live-Boots und haelt ihn sonst +# nirgends fest. Absichtlich Klartext, kein Secret - reiner Hardware-Hash, +# kein chmod 0600 noetig wie bei agent.credentials. +echo "${TUXFLOTTE_DEVICE_FINGERPRINT}" > /etc/tuxflotte/device_fingerprint + cat > /etc/tuxflotte/runtime_blueprint.json <<'RUNTIME_BLUEPRINT_EOF' ${TUXFLOTTE_BLUEPRINTS_JSON} RUNTIME_BLUEPRINT_EOF diff --git a/backends/mint/backend.sh b/backends/mint/backend.sh index ad26976..89e477f 100644 --- a/backends/mint/backend.sh +++ b/backends/mint/backend.sh @@ -12,6 +12,10 @@ POSTINSTALL_SCRIPT="${BACKEND_DIR}/postinstall.sh" RUNTIME_BLUEPRINT_FILE="/run/tuxflotte/runtime/runtime_blueprint.json" SERVER_RESPONSE_FILE="/run/tuxflotte/server/response.json" +# Von 10_hardware.sh im selben Live-Boot geschrieben (siehe dort) - Quelle +# fuer den Fingerprint, der jetzt auch auf dem installierten Geraet selbst +# hinterlegt wird (siehe backend_generate_config()/postinstall.sh). +HARDWARE_FILE="/run/tuxflotte/hardware/hardware.json" RUNTIME_DIR="/run/tuxflotte/backend" CONFIG_FILE="${RUNTIME_DIR}/config" @@ -255,6 +259,17 @@ backend_generate_config() { [[ -n "${device_id}" ]] || { backend_fatal "Keine Geräte-ID in der Serverantwort gefunden."; return 1; } + # Fuer die beidseitige Identifikation (Geraeteliste <-> Geraet selbst, + # siehe postinstall.sh) - aus der bereits waehrend des Live-Boots + # berechneten hardware.json, nicht aus der Serverantwort (die kennt nur + # die zugewiesene device_id, nicht den urspruenglichen Hardware-Hash). + local device_fingerprint + [[ -r "${HARDWARE_FILE}" ]] || + { backend_fatal "Hardware-Erfassung nicht gefunden: ${HARDWARE_FILE}"; return 1; } + device_fingerprint="$(jq --raw-output '.identity.device_fingerprint // empty' "${HARDWARE_FILE}")" + [[ -n "${device_fingerprint}" ]] || + { backend_fatal "Kein device_fingerprint in ${HARDWARE_FILE} gefunden."; return 1; } + partitioning_json="$(jq --compact-output '.runtime_blueprint.installation_directives.partitioning' "${RUNTIME_BLUEPRINT_FILE}")" secure_boot_required="$(jq --raw-output '.runtime_blueprint.installation_directives.secure_boot_required' "${RUNTIME_BLUEPRINT_FILE}")" @@ -277,7 +292,8 @@ backend_generate_config() { postinstall_rendered="$( TUXFLOTTE_DEVICE_ID="${device_id}" \ TUXFLOTTE_BLUEPRINTS_JSON="${blueprints_json}" \ - envsubst '${TUXFLOTTE_DEVICE_ID} ${TUXFLOTTE_BLUEPRINTS_JSON}' \ + TUXFLOTTE_DEVICE_FINGERPRINT="${device_fingerprint}" \ + envsubst '${TUXFLOTTE_DEVICE_ID} ${TUXFLOTTE_BLUEPRINTS_JSON} ${TUXFLOTTE_DEVICE_FINGERPRINT}' \ <"${POSTINSTALL_SCRIPT}" )" diff --git a/backends/mint/postinstall.sh b/backends/mint/postinstall.sh index 2e03ced..f20f032 100644 --- a/backends/mint/postinstall.sh +++ b/backends/mint/postinstall.sh @@ -19,6 +19,16 @@ AGENT_REPO_RAW="https://git.tuxflotte.de/admin/provisioning-agent/raw/branch/mai install -d -m 0700 /etc/tuxflotte || tuxflotte_agent_fatal "Verzeichnis /etc/tuxflotte konnte nicht angelegt werden." +# Identifikation soll in beide Richtungen moeglich sein: die Geraeteliste +# zeigt den Fingerprint bereits an (siehe geraete_liste.html), aber bislang +# gab es auf dem installierten Geraet selbst keine Datei, um ihn mit einem +# einfachen "cat" gegenzupruefen - build_device_fingerprint() (10_hardware.sh) +# berechnet ihn nur einmalig waehrend des Live-Boots und haelt ihn sonst +# nirgends fest. Absichtlich Klartext, kein Secret - reiner Hardware-Hash, +# kein chmod 0600 noetig wie bei agent.credentials. +echo "${TUXFLOTTE_DEVICE_FINGERPRINT}" > /etc/tuxflotte/device_fingerprint || + tuxflotte_agent_fatal "device_fingerprint konnte nicht abgelegt werden." + cat > /etc/tuxflotte/runtime_blueprint.json <<'RUNTIME_BLUEPRINT_EOF' ${TUXFLOTTE_BLUEPRINTS_JSON} RUNTIME_BLUEPRINT_EOF