feat(firstboot): force root + operator password on first boot (console gate) #139
3 changed files with 208 additions and 0 deletions
3
build.sh
3
build.sh
|
|
@ -1452,6 +1452,8 @@ EOF
|
|||
"${MOUNT_POINT}/usr/local/etc/rc.d/clawdie_live_wifi"
|
||||
install -m 0755 "${LIVE_SESSION_DIR}/clawdie-live-seed" \
|
||||
"${MOUNT_POINT}/usr/local/etc/rc.d/clawdie_live_seed"
|
||||
install -m 0755 "${LIVE_SESSION_DIR}/clawdie-firstboot-rootpw" \
|
||||
"${MOUNT_POINT}/usr/local/etc/rc.d/clawdie_firstboot_rootpw"
|
||||
install -m 0755 "${LIVE_SESSION_DIR}/clawdie-live-resolver" \
|
||||
"${MOUNT_POINT}/usr/local/etc/rc.d/clawdie_live_resolver"
|
||||
install -m 0755 "${LIVE_SESSION_DIR}/clawdie-live-audio" \
|
||||
|
|
@ -1878,6 +1880,7 @@ EOF
|
|||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_gpu_nvidia_branch=""'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_wifi_enable="YES"'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_seed_enable="YES"'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_firstboot_rootpw_enable="YES"'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_resolver_enable="YES"'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_audio_enable="YES"'
|
||||
set_config_line "${MOUNT_POINT}/etc/rc.conf" 'clawdie_live_power_enable="YES"'
|
||||
|
|
|
|||
141
live/operator-session/clawdie-firstboot-rootpw
Normal file
141
live/operator-session/clawdie-firstboot-rootpw
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#!/bin/sh
|
||||
# Clawdie first-boot password gate.
|
||||
#
|
||||
# Forces the operator to set a root + operator (clawdie) password on the FIRST
|
||||
# boot, on the text console, BEFORE the GUI (sddm) and BEFORE the colibri daemon
|
||||
# autospawns an agent. Running before the daemon means the security decision is
|
||||
# always made before any agent can act — no cross-component interlock needed.
|
||||
#
|
||||
# Design:
|
||||
# - Idempotent via a persistent success marker (/var is persistent on this
|
||||
# image: varmfs="NO"). Marker present -> silent exit.
|
||||
# - A countdown to ENGAGE (read -t). If the operator does not engage, boot
|
||||
# continues with passwords UNSET and the gate re-prompts next boot (never
|
||||
# bricks an unattended/headless boot). Once set, never prompts again.
|
||||
# - Passwords are read with echo off (stty) and applied via `pw usermod -h 0`,
|
||||
# which reads the new password from STDIN — never in argv/ps, never near the
|
||||
# agent/LLM.
|
||||
# - On success, writes /var/db/colibri/.secured so the colibri daemon can
|
||||
# reflect security state to mother (label the node "unsecured" while absent).
|
||||
# The daemon-side consumption of this marker is a separate (colibri) change.
|
||||
#
|
||||
# Functions below are sourced and unit-tested on a non-FreeBSD host with
|
||||
# CLAWDIE_ROOTPW_TEST=1 (which skips the rc.subr handoff). The interactive
|
||||
# countdown lives only in _start and is not exercised by the logic test.
|
||||
|
||||
# PROVIDE: clawdie_firstboot_rootpw
|
||||
# REQUIRE: clawdie_live_gpu FILESYSTEMS
|
||||
# BEFORE: sddm colibri_daemon
|
||||
# KEYWORD: nojail
|
||||
|
||||
if [ -r /etc/rc.subr ]; then
|
||||
. /etc/rc.subr
|
||||
fi
|
||||
|
||||
name="clawdie_firstboot_rootpw"
|
||||
rcvar="${name}_enable"
|
||||
start_cmd="${name}_start"
|
||||
stop_cmd=":"
|
||||
|
||||
: "${clawdie_firstboot_rootpw_enable:=YES}"
|
||||
|
||||
# Overridable for tests.
|
||||
SECURED_MARKER="${SECURED_MARKER:-/var/db/colibri/.secured}"
|
||||
PW_BIN="${PW_BIN:-/usr/sbin/pw}"
|
||||
ROOTPW_CONSOLE="${ROOTPW_CONSOLE:-/dev/console}"
|
||||
ROOTPW_COUNTDOWN="${ROOTPW_COUNTDOWN:-15}"
|
||||
ROOTPW_MIN_LEN="${ROOTPW_MIN_LEN:-8}"
|
||||
|
||||
# --- pure logic (unit-tested) -----------------------------------------------
|
||||
|
||||
# Already secured? (marker present)
|
||||
_rootpw_secured() {
|
||||
[ -e "${SECURED_MARKER}" ]
|
||||
}
|
||||
|
||||
# Validate a password pair. Echoes a reason and returns 1 on failure.
|
||||
_rootpw_valid() {
|
||||
_p1="$1"; _p2="$2"
|
||||
if [ -z "${_p1}" ]; then echo "empty password"; return 1; fi
|
||||
if [ "${_p1}" != "${_p2}" ]; then echo "passwords do not match"; return 1; fi
|
||||
if [ "${#_p1}" -lt "${ROOTPW_MIN_LEN}" ]; then
|
||||
echo "too short (minimum ${ROOTPW_MIN_LEN} characters)"; return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# Apply a password to a user. Reads the password from STDIN (pw usermod -h 0).
|
||||
_rootpw_apply() {
|
||||
"${PW_BIN}" usermod "$1" -h 0
|
||||
}
|
||||
|
||||
# Record success so the daemon sees a secured node and the gate stops prompting.
|
||||
_rootpw_mark_secured() {
|
||||
mkdir -p "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
# mirror the daemon's ownership intent; best-effort (no-op under test).
|
||||
chown colibri:colibri "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
chmod 0750 "$(dirname "${SECURED_MARKER}")" 2>/dev/null || true
|
||||
: > "${SECURED_MARKER}"
|
||||
chmod 0644 "${SECURED_MARKER}" 2>/dev/null || true
|
||||
}
|
||||
|
||||
# --- interactive (console only; not unit-tested) ----------------------------
|
||||
|
||||
# Prompt for one account, echo off, loop until a valid pair is applied.
|
||||
_rootpw_prompt_and_set() {
|
||||
_user="$1"; _label="$2"
|
||||
while :; do
|
||||
stty -echo 2>/dev/null
|
||||
printf ' %s password: ' "${_label}"; IFS= read -r _p1; printf '\n'
|
||||
printf ' confirm %s: ' "${_label}"; IFS= read -r _p2; printf '\n'
|
||||
stty echo 2>/dev/null
|
||||
if _why="$(_rootpw_valid "${_p1}" "${_p2}")"; then
|
||||
printf '%s\n' "${_p1}" | _rootpw_apply "${_user}"
|
||||
_p1=; _p2=; _why=
|
||||
printf ' -> %s password set.\n\n' "${_label}"
|
||||
return 0
|
||||
fi
|
||||
_p1=; _p2=
|
||||
printf ' ! %s — try again.\n' "${_why}"
|
||||
done
|
||||
}
|
||||
|
||||
clawdie_firstboot_rootpw_start() {
|
||||
_rootpw_secured && return 0
|
||||
|
||||
# Talk to the operator on the system console.
|
||||
exec < "${ROOTPW_CONSOLE}" > "${ROOTPW_CONSOLE}" 2>&1
|
||||
|
||||
# vt(4)/framebuffer may not have flushed right after the GPU rc script;
|
||||
# settle and clear (terminfo-free) so the prompt is actually visible.
|
||||
sleep 1
|
||||
printf '\033[H\033[2J'
|
||||
|
||||
printf '================ FIRST BOOT — SECURE THIS NODE ================\n\n'
|
||||
printf ' This stick boots with NO root password. Set one now.\n'
|
||||
printf ' WRITE BOTH PASSWORDS ON PAPER — there is no recovery.\n\n'
|
||||
printf ' Press ENTER within %ss to set passwords' "${ROOTPW_COUNTDOWN}"
|
||||
printf ' (otherwise skipped) ... '
|
||||
|
||||
if IFS= read -r -t "${ROOTPW_COUNTDOWN}" _ans; then
|
||||
printf '\n\n'
|
||||
_rootpw_prompt_and_set root "ROOT (admin)"
|
||||
_rootpw_prompt_and_set clawdie "OPERATOR (clawdie)"
|
||||
_rootpw_mark_secured
|
||||
printf ' Node secured. Continuing boot...\n'
|
||||
sleep 2
|
||||
else
|
||||
printf '\n\n [skipped] passwords NOT set — this node remains OPEN.\n'
|
||||
printf ' You will be prompted again on the next boot.\n'
|
||||
sleep 3
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# On FreeBSD, hand off to rc.subr. Under test, skip so functions can be sourced.
|
||||
if [ -n "${CLAWDIE_ROOTPW_TEST:-}" ]; then
|
||||
:
|
||||
elif command -v run_rc_command >/dev/null 2>&1; then
|
||||
load_rc_config "${name}"
|
||||
run_rc_command "$1"
|
||||
fi
|
||||
64
tests/firstboot-rootpw-test.sh
Executable file
64
tests/firstboot-rootpw-test.sh
Executable file
|
|
@ -0,0 +1,64 @@
|
|||
#!/bin/sh
|
||||
# Logic test for the first-boot password gate (clawdie-firstboot-rootpw).
|
||||
#
|
||||
# Exercises the testable security logic on any POSIX host: marker skip,
|
||||
# password validation, the secured-marker write, and — critically — that the
|
||||
# password is applied to `pw usermod <user> -h 0` via STDIN (never argv).
|
||||
# The interactive countdown (_start) needs a real console and is verified by
|
||||
# booting on osa, not here.
|
||||
set -u
|
||||
|
||||
SCRIPT_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
GATE="${SCRIPT_DIR}/../live/operator-session/clawdie-firstboot-rootpw"
|
||||
[ -r "${GATE}" ] || { echo "FATAL: gate not found at ${GATE}" >&2; exit 2; }
|
||||
|
||||
WORK=$(mktemp -d "${TMPDIR:-/tmp}/firstboot-rootpw.XXXXXX") || exit 2
|
||||
trap 'rm -rf "${WORK}"' EXIT INT TERM
|
||||
|
||||
# Fake `pw`: records argv and the password read from stdin, so we can prove the
|
||||
# secret arrives on stdin and never on the command line.
|
||||
FAKEPW="${WORK}/fake-pw"
|
||||
cat >"${FAKEPW}" <<EOF
|
||||
#!/bin/sh
|
||||
printf '%s\n' "ARGV: \$*" >> "${WORK}/pw.calls"
|
||||
IFS= read -r _stdin_pw
|
||||
printf '%s\n' "STDIN: \${_stdin_pw}" >> "${WORK}/pw.calls"
|
||||
EOF
|
||||
chmod +x "${FAKEPW}"
|
||||
|
||||
export CLAWDIE_ROOTPW_TEST=1
|
||||
export SECURED_MARKER="${WORK}/secured"
|
||||
export PW_BIN="${FAKEPW}"
|
||||
export ROOTPW_MIN_LEN=8
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
. "${GATE}"
|
||||
|
||||
PASS=0; FAIL=0
|
||||
ok() { PASS=$((PASS+1)); printf ' ok %s\n' "$1"; }
|
||||
bad() { FAIL=$((FAIL+1)); printf ' FAIL %s\n' "$1"; }
|
||||
chk() { [ "$1" -eq 0 ] && ok "$2" || bad "$2"; }
|
||||
|
||||
echo "== marker / idempotency =="
|
||||
_rootpw_secured; chk "$([ $? -ne 0 ] && echo 0 || echo 1)" "not secured when marker absent"
|
||||
_rootpw_mark_secured
|
||||
[ -f "${SECURED_MARKER}" ]; chk $? "mark_secured creates the marker"
|
||||
_rootpw_secured; chk $? "secured when marker present"
|
||||
|
||||
echo "== password validation =="
|
||||
_rootpw_valid "goodpassword" "goodpassword" >/dev/null; chk $? "accepts matching >=8 char password"
|
||||
{ ! _rootpw_valid "" "" >/dev/null; }; chk $? "rejects empty"
|
||||
{ ! _rootpw_valid "abc" "abc" >/dev/null; }; chk $? "rejects too short"
|
||||
{ ! _rootpw_valid "password1" "password2" >/dev/null; }; chk $? "rejects mismatch"
|
||||
|
||||
echo "== apply via stdin (secret never in argv) =="
|
||||
: > "${WORK}/pw.calls"
|
||||
printf '%s\n' "s3cret-on-stdin" | _rootpw_apply root
|
||||
grep -q 'ARGV: usermod root -h 0' "${WORK}/pw.calls"; chk $? "pw called: usermod root -h 0"
|
||||
grep -q 'STDIN: s3cret-on-stdin' "${WORK}/pw.calls"; chk $? "password delivered on STDIN"
|
||||
{ ! grep -q 'ARGV:.*s3cret-on-stdin' "${WORK}/pw.calls"; }; chk $? "password NEVER appears in argv"
|
||||
|
||||
echo
|
||||
echo "RESULT: ${PASS} passed, ${FAIL} failed"
|
||||
[ "${FAIL}" -eq 0 ] || exit 1
|
||||
exit 0
|
||||
Loading…
Add table
Reference in a new issue