diff --git a/bin/omarchy-drive-password b/bin/omarchy-drive-password index 8f7ba3ea8c4c..514b7635e87f 100755 --- a/bin/omarchy-drive-password +++ b/bin/omarchy-drive-password @@ -1,13 +1,17 @@ #!/bin/bash -# omarchy:summary=Set a new password for an encrypted drive +# omarchy:summary=Set a new password for an encrypted drive; for the system disk, optionally the login and root passwords too # omarchy:requires-sudo=true -# Changes a drive's LUKS key and nothing else. For the disk holding /, the new +# Changes a drive's LUKS key. For the disk holding /, the new # key must open the disk and the old one must not before the change counts. The # journal records only the disk's UUID, key slots and phase, so a change that # stops part way is finished by the next run. A platform whose boot checks prove # the disk's key slots records the owner's new one before the run finishes. +# Installation gives the login user, root and the system disk one password, so +# the owner is asked whether the login and root passwords should follow the +# disk's. The default is no; with yes they change only once the disk has taken +# the new key and its slot is recorded. # Passwords live in variables; never trace them. set +x @@ -61,6 +65,22 @@ drive_slots() { /^Key Slot [0-9]+: ENABLED/ { sub(":", "", $3); print $3 }' <<<"$dump" | paste -sd, - } +login_user() { + local user=${SUDO_USER:-$(id -un)} + [[ -n $user && $user != "root" ]] || return 1 + printf '%s' "$user" +} + + +# LUKS2 changes a key in place, so the slot number alone cannot distinguish a +# completed change from a rollback. This hashes only public keyslot metadata. +drive_slot_fingerprint() { + local metadata slot + metadata=$(sudo flock "$disk_lock" cryptsetup luksDump --dump-json-metadata "$1") || return 1 + slot=$(jq -ceS --arg slot "$2" '.keyslots[$slot] // empty' <<<"$metadata") || return 1 + sha256sum <<<"$slot" | cut -d ' ' -f1 +} + kill_slot() { local drive=$1 password=$2 slot=$3 printf '%s' "$password" | sudo flock "$disk_lock" cryptsetup luksKillSlot -q --key-file - "$drive" "$slot" @@ -94,6 +114,13 @@ change_luks_key() { return 1 } +sync_accounts() { + local user=$1 password=$2 + echo "Setting the login password for $user and root to match" + printf '%s:%s\n' "$user" "$password" | sudo chpasswd || return 1 + printf 'root:%s\n' "$password" | sudo chpasswd +} + # The entrypoint that records the system disk's key slots for the platform's # boot checks, or nothing where none does. A machine without its platform's # boot package at all (dispatch exit 3) predates it, and nothing checks its @@ -171,9 +198,10 @@ record_owner_slot() { } # Phase luks: the key change may or may not have landed. Phase record: the new -# key alone opens the recorded slot, which the boot checks still need. +# key alone opens the recorded slot, which the boot checks still need. Phase +# accounts: the login and root passwords the owner asked to follow still need it. change_system_password() { - local current=$1 new=$2 old_slot=$3 slots status=0 + local current=$1 new=$2 old_slot=$3 sync=$4 user=$5 slots fingerprint="" status=0 slots=$(drive_slots "$root_drive") if [[ ,$slots, != *",$old_slot,"* ]]; then @@ -185,8 +213,11 @@ change_system_password() { echo "The key slots of $root_drive changed while you entered the new password. Run omarchy-drive-password again." return 1 fi + if [[ $sync == "yes" ]] && sudo flock "$disk_lock" cryptsetup isLuks --type luks2 "$root_drive"; then + fingerprint=$(drive_slot_fingerprint "$root_drive" "$old_slot") || return 1 + fi mkdir -p "${REKEY_STATE%/*}" && - rekey_state_put uuid "$root_uuid" old_slot "$old_slot" slots "$slots" phase luks || return 1 + rekey_state_put uuid "$root_uuid" old_slot "$old_slot" slots "$slots" fingerprint "$fingerprint" accounts "$sync" phase luks || return 1 change_luks_key "$root_drive" "$current" "$new" "$old_slot" || status=$? if (( status == 2 )); then @@ -203,6 +234,13 @@ change_system_password() { echo "Could not record the new key slot for the boot checks. Run omarchy-drive-password again to finish." return 1 fi + if [[ $sync == "yes" ]]; then + rekey_state_put phase accounts || return 1 + if ! sync_accounts "$user" "$new"; then + echo "The login and root password updates did not finish. Run omarchy-drive-password again to finish." + return 1 + fi + fi rm -f "$REKEY_STATE" } @@ -218,30 +256,40 @@ change_pending() { return 1 } -# Settle the disk on the password it opens with now, then record its slot. +# Settle the disk on the password it opens with now, record its slot, then +# match the accounts if the owner asked for that. # Before the change was confirmed that is the old key (removing the slot the # change added, if any) or the new key in the one slot the change added # (retiring the old slot); after, only the confirmed slot. Any other key on the # disk, such as a recovery passphrase, is refused, and so is a disk that gained # more than one slot since. finish_interrupted_change() { - local phase old_slot slots slot header password opened now added extra count=0 status=0 + local phase old_slot slots slot sync user fingerprint current_fingerprint header password opened now added extra count=0 status=0 phase=$(rekey_state_get phase) - # Earlier versions named the confirmed phase "accounts". - [[ $phase != "accounts" ]] || phase=record old_slot=$(rekey_state_get old_slot) slots=$(rekey_state_get slots) slot=$(rekey_state_get slot) + sync=$(rekey_state_get accounts) + # Earlier versions recorded no answer and named the confirmed phase + # "accounts": that change finishes on the disk alone. + if [[ -z $sync ]]; then + sync=no + [[ $phase != "accounts" ]] || phase=record + fi if [[ $phase == "luks" && ! ( $old_slot =~ ^[0-9]+$ && ,$slots, == *",$old_slot,"* ) ]] || - [[ $phase == "record" && ! $slot =~ ^[0-9]+$ ]]; then + [[ $phase != "luks" && ! $slot =~ ^[0-9]+$ ]] || [[ $sync != "yes" && $sync != "no" ]]; then echo "$REKEY_STATE is unreadable. Remove it once the disk opens with only the password you want." return 1 fi + if [[ $sync == "yes" ]]; then + user=$(login_user) || { echo "Run omarchy-drive-password as the user who logs in to finish the last password change."; return 1; } + fi + echo "The last password change for $root_drive stopped part way." - if [[ $phase == "record" ]]; then + if [[ $phase != "luks" ]]; then header="New encryption password" else header="Encryption password that opens $root_drive now (the new one if the change went through)" @@ -269,6 +317,15 @@ finish_interrupted_change() { if [[ $opened == "$old_slot" ]]; then [[ -z $added ]] || kill_slot "$root_drive" "$password" "$added" || return 1 + if [[ $sync == "yes" ]]; then + fingerprint=$(rekey_state_get fingerprint) + if [[ -n $fingerprint ]]; then + current_fingerprint=$(drive_slot_fingerprint "$root_drive" "$old_slot") || return 1 + [[ $current_fingerprint != "$fingerprint" ]] || sync=no + else + sync=no + fi + fi elif [[ -n $added && $opened == "$added" ]]; then if [[ ,$now, == *",$old_slot,"* ]]; then kill_slot "$root_drive" "$password" "$old_slot" || return 1 @@ -276,8 +333,8 @@ finish_interrupted_change() { else opened="" fi - [[ -z $opened ]] || rekey_state_put slot "$opened" phase record || return 1 - elif [[ $phase == "record" && $opened != "$slot" ]]; then + [[ -z $opened ]] || rekey_state_put slot "$opened" accounts "$sync" phase record || return 1 + elif [[ $opened != "$slot" ]]; then opened="" fi @@ -286,16 +343,22 @@ finish_interrupted_change() { return 1 fi - if ! record_owner_slot "$opened"; then - echo "Could not record the key slot for the boot checks. Run omarchy-drive-password again to finish." - return 1 + if [[ $phase != "accounts" ]]; then + if ! record_owner_slot "$opened"; then + echo "Could not record the key slot for the boot checks. Run omarchy-drive-password again to finish." + return 1 + fi + fi + if [[ $sync == "yes" ]]; then + rekey_state_put phase accounts || return 1 + sync_accounts "$user" "$password" || return 1 fi rm -f "$REKEY_STATE" echo "The password change for $root_drive is finished." } change_selected_drive() { - local encrypted_drives drive current old_slot new_password confirmation status=0 system_drive=false + local encrypted_drives drive login current old_slot new_password confirmation status=0 system_drive=false sync=no encrypted_drives=$(luks_drives) if [[ -z $encrypted_drives ]]; then @@ -317,6 +380,16 @@ change_selected_drive() { if [[ -n $root_drive && $(readlink -f "$drive") == "$root_drive" ]]; then system_drive=true drive=$root_drive + # No is the default; Ctrl-C cancels the whole change. + if login=$(login_user); then + gum confirm --default=false "Also set the login password for $login and the root password to the new disk password?" || status=$? + if (( status == 0 )); then + sync=yes + elif (( status != 1 )); then + return 1 + fi + status=0 + fi fi current=$(gum input --password --header "Current encryption password") || return 1 @@ -340,7 +413,7 @@ change_selected_drive() { [[ $new_password != "$current" ]] || { echo "The new password is the current one."; return 1; } if [[ $system_drive == "true" ]]; then - change_system_password "$current" "$new_password" "$old_slot" + change_system_password "$current" "$new_password" "$old_slot" "$sync" "$login" else change_luks_key "$drive" "$current" "$new_password" "$old_slot" || status=$? if (( status == 2 )); then diff --git a/docs/file-layout.md b/docs/file-layout.md index cccf5541ea78..4e8eabd9a2d9 100644 --- a/docs/file-layout.md +++ b/docs/file-layout.md @@ -56,7 +56,7 @@ user on tty1 and runs the finalize step itself. On an encrypted install `omarchy-provision-owner` then re-keys LUKS from the staged install key to the owner's password through `install/provisioning/luks-rekey.sh`, which journals each step (phase and slot numbers, never keys) in `/var/lib/omarchy/provisioning/luks-rekey.state` so an interrupted first boot resumes. Setup finishes only once the staged key opens nothing, and removes the journal with `pending`, so a retry after the staged key is retired must use the password the disk holds. On a platform whose boot package owns the boot chain, the check before the owner form, the boot-time unlock and the record of the kept key slot go through `omarchy-lifecycle-dispatch`. See [lifecycle-dispatch.md](lifecycle-dispatch.md). -`omarchy-drive-password` reuses those journal helpers when the owner changes the password of the disk holding `/`: it changes the LUKS key and confirms the new key opens the disk and the old one no longer does. The login and root passwords are left alone. `~/.local/state/omarchy/drive-password.state` records the disk's UUID, the key slots and the phase (never a password) until the change is confirmed and its slot recorded, and the next run finishes an interrupted change with whichever of the old or new password the disk opens with. +`omarchy-drive-password` reuses those journal helpers when the owner changes the password of the disk holding `/`: it changes the LUKS key and confirms the new key opens the disk and the old one no longer does. It first asks whether the login and root passwords should follow (default no); with yes they are set only after that confirmation, and after a platform that checks key slots has recorded the new one. `~/.local/state/omarchy/drive-password.state` records the disk's UUID, the key slots, the owner's answer and the phase (never a password) until the change is confirmed, the slot is recorded and the accounts follow where asked, and the next run finishes an interrupted change with whichever of the old or new password the disk opens with. Prebuilt images are set up away from the machine they will run on, so their hardware setup waits for that machine. The builder writes a root-owned manifest, `/var/lib/omarchy/image/target` (`format=1`, `platform=`), before `omarchy-apply-system`. While it exists, `omarchy-apply-hardware` runs no hardware leaf: it queues each one in `/var/lib/omarchy/image/deferred-steps` and arms `omarchy-provision-hardware.service` (shipped from `install/provisioning/`). On the machine's first boot, before owner setup and the login screen, `bin/omarchy-provision-hardware` renames the manifest to `target.booted` and runs the queue in order, dropping each step that succeeds. Before the first step it makes the machine's own pacman keyring when the build asked for one (`/var/lib/omarchy/image/pacman-keyring`, which install finalization writes on Qualcomm and generic aarch64 instead of running `pacman-key --init`, so no two machines share a master key). A failed step stays queued for the next boot. It refreshes no package databases: the image carries its sync databases and every package its queued steps install, so the queue runs offline (the image build checks that it carries them; a step whose package is missing stays queued). Once the queue is empty it rebuilds the initramfs if a step changed its inputs (the mkinitcpio configuration, or the kernel command line in `/etc/default/limine` and `/etc/limine-entry-tool.d/`) or asked for the rebuild (`/var/lib/omarchy/image/boot-rebuild`), and disables the service; the unit file stays, so a start job already queued is skipped on the emptied queue rather than failed. A platform's own first boot may run `omarchy-provision-hardware` itself: runs are serialised, and it exits 75 when a step or the keyring failed and stays queued, and 1 when it refused to run (an untrusted manifest or queue) or the final rebuild failed, which the next run retries. Steps know they run on an image's first boot from `OMARCHY_IMAGE_DEFERRED_HARDWARE=1` (Bluetooth starts its service there, since boot already brought up its target). `install/helpers/image-target.sh` holds the contract. Root always uses these fixed paths; no environment variable turns a live system into an image build. diff --git a/docs/lifecycle-dispatch.md b/docs/lifecycle-dispatch.md index 0e8658ad03c5..75799e5c24f8 100644 --- a/docs/lifecycle-dispatch.md +++ b/docs/lifecycle-dispatch.md @@ -116,7 +116,7 @@ Failing closed holds on every platform: where `omarchy-hw-platform` can't settle ### Disk password change (`bin/omarchy-drive-password`) -- After the system disk's key changed and the new key is confirmed, `record_owner_slot` resolves `luks-slots` as the user and, when it resolves, runs `sudo omarchy-lifecycle-dispatch luks-slots owner=`, so no other platform sees an extra `sudo`. Until that succeeds the journal stays, and the next run finishes the change and records the slot. The new key can land in another slot (cryptsetup 2.8's `luksChangeKey` moves a LUKS1 key to the first free slot, and keeps a LUKS2 one in place), and the boot check would then find a slot the platform did not record. +- After the system disk's key changed and the new key is confirmed, and before any login and root passwords the owner asked to follow change, `record_owner_slot` resolves `luks-slots` as the user and, when it resolves, runs `sudo omarchy-lifecycle-dispatch luks-slots owner=`, so no other platform sees an extra `sudo`. Until that succeeds the journal stays, and the next run finishes the change and records the slot. The new key can land in another slot (cryptsetup 2.8's `luksChangeKey` moves a LUKS1 key to the first free slot, and keeps a LUKS2 one in place), and the boot check would then find a slot the platform did not record. - Before anything changes, where `luks-slots` resolves, `owner_slot_matches` runs `sudo omarchy-lifecycle-dispatch luks-slots --owner` and refuses a current password whose slot is not the owner's, so another key on the system disk, such as a recovery key an earlier Mac setup added, stays as it is and can't take the owner's place. Exit 4 (no owner slot recorded) is taken as a machine nobody recorded: the change goes on only when the current password opens the disk's one key slot, checked again before the key changes, and records the new slot as the owner's once it is confirmed; with other keys on the disk it stops, naming the slots and saying how to record them (`luks-slots owner= recovery=`) or remove the extra key. Any other failure stops the change with the boot package's reason. ## Key slots diff --git a/manual/48-security.md b/manual/48-security.md index 65a8cfa94645..769d72bd4bcf 100644 --- a/manual/48-security.md +++ b/manual/48-security.md @@ -10,7 +10,7 @@ Omarchy takes security extremely seriously. This is meant to be an operating sys ## Changing your passwords -You have two passwords on an encrypted install: the one that unlocks the drive at boot, and the one you log in and `sudo` with. Setup makes them the same. Both can be changed under _Update > Password_ in the Omarchy menu — _Drive Encryption_ for the first, _User_ for the second. Changing the drive password asks for the current one first, so have it handy. If a change is interrupted, run _Drive Encryption_ again: it asks for the password that unlocks the drive now and finishes the change. +You have two passwords on an encrypted install: the one that unlocks the drive at boot, and the one you log in and `sudo` with. Setup makes them the same. Both can be changed under _Update > Password_ in the Omarchy menu — _Drive Encryption_ for the first, _User_ for the second. For the drive Omarchy runs from, _Drive Encryption_ asks whether your login and root passwords should change to match; the answer defaults to no, and with yes they change only once the drive has accepted the new password. Changing the drive password asks for the current one first, so have it handy. If a change is interrupted, run _Drive Encryption_ again: it asks for the password that unlocks the drive now and finishes the change. ## Passing on a machine you've already used diff --git a/test/shell.d/drive-password-test.sh b/test/shell.d/drive-password-test.sh index 8cd0c7961928..f33fe49b3d10 100644 --- a/test/shell.d/drive-password-test.sh +++ b/test/shell.d/drive-password-test.sh @@ -7,8 +7,9 @@ source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" # omarchy-drive-password against fake drives. findmnt and lsblk describe a # system drive under / and a data drive, and blkid has the empty cache a user # sees until root runs blkid in that boot; cryptsetup is either a slot-table fake -# or the real binary on file-backed volumes; a chpasswd fake shows the login and -# root passwords never change. Each cryptsetup call is a crash point, so a run +# or the real binary on file-backed volumes; chpasswd records the accounts, and +# gum confirm answers TEST_CONFIRM (no by default) when asked whether they follow +# the system disk. Each cryptsetup and chpasswd call is a crash point, so a run # can be killed after every step and rerun, like a power loss. The runs repeat on an Apple fixture, # where a fake boot package records the owner's slot through the real # omarchy-lifecycle-dispatch; on the x86 fixture that is a no-op. @@ -80,6 +81,14 @@ SH cat >"$tmp/bin/gum" <<'SH' #!/bin/bash +if [[ $1 == "confirm" ]]; then + printf '%s\n' "$*" >>"$TEST_TMP/prompts" + case ${TEST_CONFIRM:-no} in + yes) exit 0 ;; + no) exit 1 ;; + *) exit 130 ;; + esac +fi [[ $1 == "input" ]] || exit 97 printf '%s\n' "$*" >>"$TEST_TMP/prompts" [[ -s $TEST_TMP/inputs ]] || exit 130 @@ -107,11 +116,14 @@ cat >"$tmp/bin/chpasswd" <<'SH' source "$TEST_TMP/crash.sh" IFS= read -r line name=${line%%:*} +crash_point "chpasswd $name" +[[ $name != "${TEST_CHPASSWD_FAIL:-}" ]] || exit 1 { grep -v "^$name " "$TEST_TMP/accounts" || true printf '%s\t%s\n' "$name" "${line#*:}" } >"$TEST_TMP/accounts.next" mv -f "$TEST_TMP/accounts.next" "$TEST_TMP/accounts" +crash_point "$name password set" SH # A LUKS1-style volume as a table of "slotpassphrase" lines next to the @@ -306,7 +318,7 @@ volume() { # / on the system drive, which also holds a recovery key; a data drive beside it. fixture() { rm -rf "$tmp/state" "$tmp/output" "$tmp/trace" "$tmp/offered" "$tmp"/dev/* "$tmp/slot-record" "$tmp/record-fail" "$tmp/owner-slot" "$tmp/owner-query-fail" "$tmp/owner-query-garbage" "$tmp/owner-unrecorded" - unset TEST_ENROLL_AT_PROMPT TEST_ENROLL_DEVICE TEST_OPEN_FAIL TEST_CHANGE_FAIL TEST_CHANGE_PARTIAL TEST_KILL_FAIL TEST_FINDMNT_FAIL TEST_TOKEN_SLOT CRASH_ORPHAN + unset TEST_ENROLL_AT_PROMPT TEST_ENROLL_DEVICE TEST_OPEN_FAIL TEST_CHPASSWD_FAIL TEST_CONFIRM TEST_CHANGE_FAIL TEST_CHANGE_PARTIAL TEST_KILL_FAIL TEST_FINDMNT_FAIL TEST_TOKEN_SLOT CRASH_ORPHAN system=$tmp/dev/system recovery=${1-$recovery_key} volume "$system" "$old_password" "$recovery" @@ -776,3 +788,138 @@ echo "$data" >"$tmp/select" attempt 0 "$data_password" "$new_password" "$new_password" || fail "apple: a data drive changes" "$(cat "$tmp/output")" [[ ! -e $tmp/slot-record && -n $(opens "$data" "$new_password") ]] || fail "apple: a data drive records no slot" pass "apple: only the system disk's slot is recorded" + +# With the owner's yes, the login and root passwords follow the system disk, +# and only once the disk has taken the new key. +sync_fixture() { + fixture + printf 'owner\tlogin-password\nroot\troot-password\n' >"$tmp/accounts" +} + +rollback_accounts() { + [[ $(account owner) == "login-password" && $(account root) == "root-password" ]] && ! grep -q 'chpasswd' "$tmp/sudo-calls" || + fail "$backend $platform: a rolled-back disk change leaves distinct account passwords unchanged" "$(cat "$tmp/accounts" "$tmp/sudo-calls")" + [[ -n $(opens "$system" "$old_password") && -z $(opens "$system" "$new_password") && ! -e $journal ]] || + fail "$backend $platform: the disk rollback finishes on the old password" "$(cat "$tmp/output")" + recorded "rollback" "$old_password" +} + +synced() { + local context=$1 password=$2 other=$old_password + [[ $password == "$old_password" ]] && other=$new_password + [[ $(account owner) == "$password" && $(account root) == "$password" ]] || + fail "$backend: $context: the login and root passwords are the disk password" "$(cat "$tmp/accounts" "$tmp/output")" + [[ -n $(opens "$system" "$password") && -z $(opens "$system" "$other") ]] || + fail "$backend: $context: only that password opens the disk" "$(cat "$tmp/trace" "$tmp/output")" + [[ ! -e $journal ]] || fail "$backend: $context: the journal is gone" "$(cat "$journal")" + recorded "$context" "$password" +} + +sync_specs=("fake x86" "fake apple") +if [[ -n ${REAL_CRYPTSETUP:-} ]]; then + sync_specs+=("luks2 x86" "luks2 apple" "luks1 x86" "luks1 apple") +fi +for run_spec in "${sync_specs[@]}"; do + use $run_spec + + sync_fixture + export TEST_CONFIRM=yes + attempt 0 "$old_password" "$new_password" "$new_password" || fail "$backend $platform: an agreed sync succeeds" "$(cat "$tmp/output")" + synced "agreed" "$new_password" + grep -Fq -- '--default=false' "$tmp/prompts" || fail "$backend $platform: the question defaults to no" "$(cat "$tmp/prompts")" + grep -Fq 'login password for owner and the root password' "$tmp/prompts" || fail "$backend $platform: the question names the login user and root" "$(cat "$tmp/prompts")" + first_account=$(grep -n 'chpasswd' "$tmp/trace" | head -1 | cut -d: -f1) + last_luks=$(grep -n 'cryptsetup' "$tmp/trace" | tail -1 | cut -d: -f1) + (( last_luks < first_account )) || fail "$backend $platform: the disk key changes and is verified before any account" "$(cat "$tmp/trace")" + no_secrets "agreed" + sync_steps=$(cat "$tmp/steps") + pass "$backend $platform: with the owner's yes, the disk key changes and verifies first, then the login and root passwords follow" + + for (( step = 1; step <= sync_steps; step++ )); do + for answer in "$new_password" "$old_password"; do + sync_fixture + export TEST_CONFIRM=yes + if attempt "$step" "$old_password" "$new_password" "$new_password"; then fail "$backend $platform: the agreed run is killed at step $step"; fi + point=$(sed -n "${step}p" "$tmp/trace") + login=$(account owner) + [[ $login == "login-password" || $login == "$new_password" && -n $(opens "$system" "$login") ]] || + fail "$backend $platform: killed after '$point': the login password changes only after the disk takes it" + if [[ ! -e $journal ]]; then + [[ $login == "login-password" && $(account root) == "root-password" ]] || + fail "$backend $platform: a change killed before its journal leaves the accounts alone" + continue + fi + [[ -n $(opens "$system" "$answer") ]] || continue + if grep -qx 'phase=\(accounts\|record\)' "$journal" && [[ $answer == "$old_password" ]]; then + if attempt 0 "$answer"; then fail "$backend $platform: after '$point' a confirmed change refuses the old password"; fi + answer=$new_password + fi + export TEST_CONFIRM=no + attempt 0 "$answer" || fail "$backend $platform: the rerun after '$point' finishes" "$(cat "$tmp/output")" + if [[ $answer == "$old_password" ]]; then + rollback_accounts + else + synced "agreed, rerun with $answer after '$point'" "$answer" + fi + done + done + pass "$backend $platform: an interrupted opt-in follows the new disk password or rolls back without changing the accounts" +done + +use fake x86 +fixture +export TEST_CONFIRM=yes TEST_CHPASSWD_FAIL=root +if attempt 0 "$old_password" "$new_password" "$new_password"; then fail "a failed root password change fails the command"; fi +grep -qx 'phase=accounts' "$journal" && [[ $(account root) == "$old_password" ]] || fail "a failed root password change keeps the journal" "$(cat "$journal")" +[[ $(account owner) == "$new_password" ]] || fail "the login password changed before the root update failed" +grep -Fq 'The login and root password updates did not finish.' "$tmp/output" || fail "a partial account change reports unfinished updates" "$(cat "$tmp/output")" +unset TEST_CHPASSWD_FAIL +if attempt 0 "$old_password"; then fail "a confirmed change refuses the old password"; fi +attempt 0 "$new_password" || fail "the rerun sets the root password" "$(cat "$tmp/output")" +synced "rerun after a failed root password change" "$new_password" +pass "a failed account change is finished by the next run" + +fixture +export TEST_CONFIRM=abort +if attempt 0 "$old_password" "$new_password" "$new_password"; then fail "Ctrl-C at the question cancels the change"; fi +[[ ! -s $tmp/sudo-calls && ! -e $journal && -n $(opens "$system" "$old_password") ]] || fail "a cancelled question changes nothing" +untouched_accounts "cancelled question" +pass "Ctrl-C at the question cancels the whole change" + +fixture +echo "$data" >"$tmp/select" +export TEST_CONFIRM=yes +attempt 0 "$data_password" "$new_password" "$new_password" || fail "a data drive changes" "$(cat "$tmp/output")" +! grep -q '^confirm' "$tmp/prompts" || fail "a data drive asks nothing about the accounts" "$(cat "$tmp/prompts")" +untouched_accounts "data drive with yes" +pass "a data drive never asks about the login password" + +fixture +export TEST_CONFIRM=yes +SUDO_USER=root +attempt 0 "$old_password" "$new_password" "$new_password" || fail "without a login user the system disk still changes" "$(cat "$tmp/output")" +SUDO_USER=owner +! grep -q '^confirm' "$tmp/prompts" || fail "without a login user the accounts are not offered" "$(cat "$tmp/prompts")" +consistent "no login user" "$new_password" +pass "without a login user the system disk changes alone" + +use fake apple +fixture +export TEST_CONFIRM=yes +touch "$tmp/record-fail" +if attempt 0 "$old_password" "$new_password" "$new_password"; then fail "apple: an agreed change whose slot record fails fails the command"; fi +grep -qx 'phase=record' "$journal" || fail "apple: a failed record keeps the record phase" "$(cat "$journal")" +untouched_accounts "agreed change before its slot is recorded" +rm "$tmp/record-fail" +attempt 0 "$new_password" || fail "apple: the rerun records the slot and matches the accounts" "$(cat "$tmp/output")" +synced "agreed change after a failed record" "$new_password" +pass "apple: the boot checks' slot is recorded before the login and root passwords change" + +use fake x86 +fixture +mkdir -p "${journal%/*}" +printf 'uuid=uuid-system\nold_slot=0\nslots=0,1\naccounts=maybe\nphase=luks\n' >"$journal" +if attempt 0 "$old_password"; then fail "a journal with an unknown answer refuses to finish"; fi +said "is unreadable" +[[ -e $journal ]] && untouched_accounts "unknown answer" || fail "an unknown answer changes nothing" +pass "a journal whose answer is neither yes nor no is refused rather than trusted"