Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 91 additions & 18 deletions bin/omarchy-drive-password
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"
}

Expand All @@ -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)"
Expand Down Expand Up @@ -269,15 +317,24 @@ 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
fi
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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/file-layout.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<omarchy-hw-platform value>`), 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.

Expand Down
2 changes: 1 addition & 1 deletion docs/lifecycle-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<slot>`, 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=<slot>`, 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=<slot> recovery=<slot>`) or remove the extra key. Any other failure stops the change with the boot package's reason.

## Key slots
Expand Down
2 changes: 1 addition & 1 deletion manual/48-security.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading