Skip to content
Open
Show file tree
Hide file tree
Changes from 8 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
2 changes: 2 additions & 0 deletions bin/omarchy-apply-lock
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ fi

if grep -qE '^[[:space:]]*-[[:space:]]*#[0-9]+:' <<< "$fingerprint_status"; then
echo "Configuring lock screen fingerprint authentication..."
# No lid gate: skipping pam_fprintd on this stack is unlock success. Lid
# handling for fingerprint belongs in the lock service, not PAM.
as_root install -Dm755 -o root -g root "$resume_hook_src" "$resume_hook_dst"
as_root install -Dm644 -o root -g root "$stop_timeout_src" "$stop_timeout_dst"
as_root systemctl daemon-reload
Expand Down
18 changes: 18 additions & 0 deletions bin/omarchy-hw-laptop-open
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

# omarchy:summary=Returns true when the laptop lid is open
# omarchy:hidden=true

# Inverse of omarchy-hw-laptop-closed. The fingerprint PAM gate uses this so the
# common path (lid open) exits 0 and pam_exec does not LOG_ERR on every
# sudo/polkit auth (#10254). Callers that want "is closed?" keep using
# omarchy-hw-laptop-closed.

for state in /proc/acpi/button/lid/*/state; do
[[ -r $state ]] || continue
[[ $(<"$state") == *"closed"* ]] && exit 1
[[ $(<"$state") == *"open"* ]] && exit 0
done

# No lid switch (desktop): treat as open so fingerprint stays available.
exit 0
Comment on lines +17 to +18

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Closed lids report open

omarchy-hw-laptop-open treats every laptop without an ACPI lid file as open. The existing omarchy-hw-laptop-closed also checks input lid switches through logind, including on supported Apple Silicon MacBooks.

After setup or migration switches PAM to this helper, those laptops stop skipping fingerprint authentication when closed. Sudo and polkit can wait for an unreachable reader instead of going straight to the password prompt. Preserve the existing helper’s non-ACPI check when reversing its result.

Knowledge Base Used: Hardware, devices, and power

8 changes: 4 additions & 4 deletions bin/omarchy-remove-security-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ fi

remove_pam_config() {
# Remove from sudo (both the fingerprint module and its clamshell gate)
if grep -Eq 'pam_fprintd\.so|omarchy-hw-laptop-closed' /etc/pam.d/sudo; then
if grep -Eq 'pam_fprintd\.so|omarchy-hw-laptop-(open|closed)' /etc/pam.d/sudo; then
echo "Removing fingerprint authentication from sudo..."
sudo sed -i -e '/pam_fprintd\.so/d' -e '/omarchy-hw-laptop-closed/d' /etc/pam.d/sudo
sudo sed -i -e '/pam_fprintd\.so/d' -e '/omarchy-hw-laptop-closed/d' -e '/omarchy-hw-laptop-open/d' /etc/pam.d/sudo
fi

# Remove from polkit (both the fingerprint module and its clamshell gate)
if [[ -f /etc/pam.d/polkit-1 ]] && grep -Eq 'pam_fprintd\.so|omarchy-hw-laptop-closed' /etc/pam.d/polkit-1; then
if [[ -f /etc/pam.d/polkit-1 ]] && grep -Eq 'pam_fprintd\.so|omarchy-hw-laptop-(open|closed)' /etc/pam.d/polkit-1; then
echo "Removing fingerprint authentication from polkit..."
sudo sed -i -e '/pam_fprintd\.so/d' -e '/omarchy-hw-laptop-closed/d' /etc/pam.d/polkit-1
sudo sed -i -e '/pam_fprintd\.so/d' -e '/omarchy-hw-laptop-closed/d' -e '/omarchy-hw-laptop-open/d' /etc/pam.d/polkit-1
fi
}

Expand Down
60 changes: 47 additions & 13 deletions bin/omarchy-setup-security-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,30 @@ set -e

setup_pam_config() {
# A clamshell gate runs before pam_fprintd in every stack: when the lid is
# shut the reader is unreachable, so it skips fingerprint (success=1) and PAM
# drops straight to the password prompt instead of blocking on the reader
# until it times out. Lid open → fingerprint, then password as the fallback.
# shut the reader is unreachable, so fingerprint is skipped and PAM drops
# straight to the password prompt instead of blocking on the reader until it
# times out. Lid open → fingerprint, then password as the fallback.
#
# pam_exec needs a literal absolute path (no env expansion). Point at the
# fixed /usr/bin path the omarchy package always provides, so the gate keeps
# working across package installs and dev-link — the latter overlays
# $OMARCHY_PATH trees but leaves /usr/bin untouched.
local fprintd_gate="auth [success=1 default=ignore] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-closed"
#
# Use omarchy-hw-laptop-open (exit 0 when open) so the common path does not
# make pam_exec LOG_ERR on every sudo/polkit auth (#10254). success=ignore
# continues to pam_fprintd; default=1 skips it when the lid is closed.
local fprintd_gate="auth [success=ignore default=1] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-open"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 PAM helper may be missing If setup runs from a dev-linked checkout while the installed package predates this helper, dev-link does not put omarchy-hw-laptop-open at /usr/bin. Setup still replaces the sudo and polkit gates with that absolute path. pam_exec then fails and default=1 skips fingerprint authentication even when the lid is open. The migration can make the same replacement.


# Configure sudo
if ! grep -q pam_fprintd.so /etc/pam.d/sudo; then
echo "Configuring sudo for fingerprint authentication..."
sudo sed -i '1i auth sufficient pam_fprintd.so' /etc/pam.d/sudo
fi
if ! grep -q 'omarchy-hw-laptop-closed' /etc/pam.d/sudo; then
# Drop any prior polarity of the gate, then insert the silent lid-open form
# immediately before pam_fprintd so default=1 skips exactly that module.
sudo sed -i -e '/omarchy-hw-laptop-closed/d' -e '/omarchy-hw-laptop-open/d' /etc/pam.d/sudo
if ! grep -q 'omarchy-hw-laptop-open' /etc/pam.d/sudo; then
echo "Adding clamshell gate to sudo..."
# Insert immediately before pam_fprintd so success=1 skips exactly it.
sudo sed -i "/pam_fprintd\.so/i $fprintd_gate" /etc/pam.d/sudo
fi

Expand All @@ -35,7 +41,8 @@ setup_pam_config() {
echo "Configuring polkit for fingerprint authentication..."
sudo sed -i '1i auth sufficient pam_fprintd.so' /etc/pam.d/polkit-1
fi
if ! grep -q 'omarchy-hw-laptop-closed' /etc/pam.d/polkit-1; then
sudo sed -i -e '/omarchy-hw-laptop-closed/d' -e '/omarchy-hw-laptop-open/d' /etc/pam.d/polkit-1
if ! grep -q 'omarchy-hw-laptop-open' /etc/pam.d/polkit-1; then
echo "Adding clamshell gate to polkit..."
sudo sed -i "/pam_fprintd\.so/i $fprintd_gate" /etc/pam.d/polkit-1
fi
Expand Down Expand Up @@ -64,13 +71,40 @@ if ! omarchy-hw-fingerprint; then
exit 1
fi

# libfprint-git tracks upstream ahead of the Arch release, so a new reader only
# needs a pin bump in omarchy-pkgs. It conflicts with stock libfprint, and
# --noconfirm answers that prompt with N; --ask 4 accepts the replacement in
# one transaction, so a failed install leaves the existing driver in place.
if omarchy-pkg-missing libfprint-git fprintd usbutils; then
# Prefer libfprint-git (tracks upstream ahead of Arch). Stock libfprint is
# still replaced so a new reader only needs a pin bump in omarchy-pkgs. A
# community fork that already provides libfprint / libfprint-2 must be left
# alone — pacman -Qq is provides-aware, while omarchy-pkg-missing libfprint-git
# is not, and --ask 4 would otherwise silently evict the working driver
# (see #11899). After any package change, restart fprintd so enroll/verify
# talk to the on-disk library instead of a stale in-memory .so.
libfprint_pkgs=()
while IFS= read -r pkg; do
[[ -n $pkg ]] && libfprint_pkgs+=("$pkg")
done < <(pacman -Qq libfprint libfprint-2 libfprint-git 2>/dev/null | sort -u)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Working fork can be replaced If a working libfprint fork is installed under its own package name and provides libfprint, pacman -Qq does not find it by the provided name. Setup then treats the driver as missing and requests libfprint-git; --ask 4 can remove the working fork. The fork test misses this because its -Qq stub resolves providers.


need_packages=()
if ((${#libfprint_pkgs[@]} == 0)) ||
{ ((${#libfprint_pkgs[@]} == 1)) && [[ ${libfprint_pkgs[0]} == libfprint ]]; }; then
# Missing entirely, or only Arch stock — install / replace with libfprint-git.
need_packages+=(libfprint-git)
fi
if omarchy-pkg-missing fprintd; then
need_packages+=(fprintd)
fi
if omarchy-pkg-missing usbutils; then
need_packages+=(usbutils)
fi

if ((${#need_packages[@]} > 0)); then
echo "Installing required packages..."
sudo pacman -S --needed --noconfirm --ask 4 -- libfprint-git fprintd usbutils
# Conflicts with stock libfprint: --noconfirm would answer N; --ask 4 accepts
# the replacement in one transaction so a failed install leaves the existing
# driver in place.
sudo pacman -S --needed --noconfirm --ask 4 "${need_packages[@]}"
# D-Bus activation keeps a running fprintd mapped to the library that was
# just replaced; without a restart, enroll can "succeed" against the old .so.
sudo systemctl try-restart fprintd.service 2>/dev/null || true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Restart failure is hidden If a package transaction replaces libfprint while fprintd is active and try-restart fails, this line hides the error and continues to enrollment against the stale in-memory library. Surfacing that failure would avoid an apparently valid enrollment using the old driver. The new test stub always succeeds, so it does not cover this path.

fi

# Enroll first fingerprint
Expand Down
12 changes: 12 additions & 0 deletions migrations/1789261001.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
echo "Drop the lid gate from lock-screen fingerprint PAM"

# An earlier revision of this migration (and setup/apply-lock) inserted
# omarchy-hw-laptop-open with [success=ignore default=1] before pam_fprintd.
# On the lock PamContext that skip is PAM success and unlocks with the lid
# closed. Remove the gate; lid policy stays in the lock service (#10393).

pam=/etc/pam.d/omarchy-lock-fingerprint

if [[ -f $pam ]] && grep -q 'omarchy-hw-laptop-open' "$pam"; then
sudo sed -i '/omarchy-hw-laptop-open/d' "$pam"
fi
28 changes: 28 additions & 0 deletions migrations/1789400300.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
echo "Silence the fingerprint clamshell PAM gate on the common lid-open path"

# The previous gate ran omarchy-hw-laptop-closed with [success=1 default=ignore].
# Lid open (the usual case) exited 1, and pam_exec logged that at LOG_ERR on
# every sudo/polkit auth (#10254). Flip to omarchy-hw-laptop-open with
# [success=ignore default=1] so control flow stays the same but the common
# path exits 0.
#
# Lock is a separate PamContext whose only auth module is pam_fprintd.
# Skipping it (default=1) would unlock with the lid shut. Leave that stack
# alone; lid-closed skip on the lock screen belongs in the lock service.

gate='auth [success=ignore default=1] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-open'

for pam in /etc/pam.d/sudo /etc/pam.d/polkit-1; do
[[ -f $pam ]] || continue
grep -q 'pam_fprintd\.so' "$pam" || continue

# Already on the silent polarity.
if grep -q 'omarchy-hw-laptop-open' "$pam"; then
continue
fi

sudo sed -i -e '/omarchy-hw-laptop-closed/d' -e '/omarchy-hw-laptop-open/d' "$pam"
if ! grep -q 'omarchy-hw-laptop-open' "$pam"; then
sudo sed -i "/pam_fprintd\.so/i $gate" "$pam"
fi
done
56 changes: 56 additions & 0 deletions test/shell.d/fingerprint-clamshell-silent-gate-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#!/bin/bash

set -euo pipefail

# The fingerprint clamshell gate must exit 0 on the common lid-open path so
# pam_exec does not fill the journal with LOG_ERR on every sudo/polkit auth.

source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh"

helper="$ROOT/bin/omarchy-hw-laptop-open"
[[ -x $helper ]] || fail "omarchy-hw-laptop-open is executable"

# Match the closed helper's ACPI path convention.
grep -q '/proc/acpi/button/lid' "$helper" ||
fail "omarchy-hw-laptop-open reads the ACPI lid state"

grep -q 'exit 1' "$helper" ||
fail "omarchy-hw-laptop-open exits 1 when the lid is closed"

grep -q 'exit 0' "$helper" ||
fail "omarchy-hw-laptop-open exits 0 when the lid is open"
Comment on lines +14 to +21

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tests check strings, not behavior

These checks search for exit statements without running the lid helper, so they can pass when lid detection is broken. AGENTS.md says “Don't restate the implementation” and “No test for a migration,” but this file also checks migration source. The same pattern appears in lock-fingerprint-clamshell-gate-test.sh.

Run the helper against open and closed lid states, check the files setup writes, and remove the migration-source checks. These repository requirements must be satisfied before merging.

File Used: AGENTS.md (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


pass "omarchy-hw-laptop-open is the silent lid-open helper"

setup="$ROOT/bin/omarchy-setup-security-fingerprint"
grep -q 'omarchy-hw-laptop-open' "$setup" ||
fail "fingerprint setup installs the lid-open PAM gate"

grep -q '\[success=ignore default=1\]' "$setup" ||
fail "fingerprint setup uses success=ignore default=1 for the lid-open gate"

! grep -q 'omarchy-hw-laptop-closed' <<<"$(grep fprintd_gate= "$setup")" ||
fail "fingerprint setup gate line must not call omarchy-hw-laptop-closed"

pass "fingerprint setup installs the silent lid-open PAM gate"

remove="$ROOT/bin/omarchy-remove-security-fingerprint"
grep -q 'omarchy-hw-laptop-open' "$remove" ||
fail "fingerprint remove strips the lid-open PAM gate"

pass "fingerprint remove strips both gate polarities"

migration="$ROOT/migrations/1789400300.sh"
[[ -f $migration ]] || fail "a migration rewrites existing PAM gates to the silent polarity"
grep -q 'omarchy-hw-laptop-open' "$migration" ||
fail "migration installs the lid-open PAM gate"
grep -q 'omarchy-hw-laptop-closed' "$migration" ||
fail "migration removes the lid-closed PAM gate"
grep -q '/etc/pam.d/sudo' "$migration" ||
fail "migration rewrites sudo"
grep -q '/etc/pam.d/polkit-1' "$migration" ||
fail "migration rewrites polkit"
! grep -q 'omarchy-lock-fingerprint' "$migration" ||
fail "migration must not gate the lock PAM stack (skipping pam_fprintd unlocks)"

pass "migration flips sudo/polkit fingerprint PAM gates to the silent polarity"
84 changes: 69 additions & 15 deletions test/shell.d/fingerprint-package-test.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/bin/bash
#
# The fingerprint setup installs libfprint-git in place of stock libfprint. The
# two conflict, so the swap has to happen inside one --ask 4 transaction, and a
# rerun with everything installed must not touch pacman at all. The real
# The fingerprint setup installs libfprint-git when no libfprint provider is
# present, or when only Arch stock libfprint is. A community fork that already
# provides libfprint must not be replaced, and a package transaction must
# restart fprintd so enroll does not talk to a stale .so. The real
# omarchy-pkg-missing runs; pacman and the privileged calls are stubbed.

set -euo pipefail
Expand All @@ -22,23 +23,52 @@ STUB
cat > "$scratch/bin/sudo" <<'STUB'
#!/bin/bash
case "$1" in
pacman | fprintd-enroll) exec "$@" ;;
pacman | fprintd-enroll | systemctl) exec "$@" ;;
sed) printf 'pam %s\n' "$*" >> "$CALL_LOG" ;;
tee) printf 'pam %s\n' "$*" >> "$CALL_LOG"; cat >/dev/null ;;
*) echo "Unexpected privileged call: $*" >> "$CALL_LOG"; exit 99 ;;
esac
STUB
# INSTALLED lists the installed package names, one per line.
# INSTALLED lists installed package names, one per line.
# PROVIDES maps query=provider for pacman -Qq provides resolution (forks).
cat > "$scratch/bin/pacman" <<'STUB'
#!/bin/bash
resolve() {
local query=$1
if grep -qx "$query" <<< "${INSTALLED:-}"; then
printf '%s\n' "$query"
return 0
fi
local line provider target
while IFS= read -r line; do
[[ -z $line ]] && continue
target=${line%%=*}
provider=${line#*=}
if [[ $target == "$query" ]] && grep -qx "$provider" <<< "${INSTALLED:-}"; then
printf '%s\n' "$provider"
return 0
fi
done <<< "${PROVIDES:-}"
return 1
}

case "$1" in
-Qq)
shift
[[ ${1:-} == -- ]] && shift
found=0
for query in "$@"; do
if out=$(resolve "$query"); then
printf '%s\n' "$out"
found=1
fi
done
(( found ))
;;
-Q)
if [[ $2 == "--" ]]; then
shift 2
else
shift
fi
grep -qx -- "$1" <<< "${INSTALLED:-}"
shift
[[ ${1:-} == -- ]] && shift
resolve "${1:-}" >/dev/null
;;
-S)
printf 'pacman %s\n' "$*" >> "$CALL_LOG"
Expand All @@ -47,6 +77,10 @@ case "$1" in
*) printf 'pacman %s\n' "$*" >> "$CALL_LOG"; exit 99 ;;
esac
STUB
cat > "$scratch/bin/systemctl" <<'STUB'
#!/bin/bash
printf 'systemctl %s\n' "$*" >> "$CALL_LOG"
STUB
cat > "$scratch/bin/fprintd-enroll" <<'STUB'
#!/bin/bash
# Stop before verification/PAM; no host authentication files may be changed.
Expand Down Expand Up @@ -84,27 +118,47 @@ run_setup() {
fi
}

assert_installs() {
grep -qx 'pacman -S --needed --noconfirm --ask 4 -- libfprint-git fprintd usbutils' "$CALL_LOG" || fail "$1"
assert_full_install() {
grep -qx 'pacman -S --needed --noconfirm --ask 4 libfprint-git fprintd usbutils' "$CALL_LOG" || fail "$1"
(( $(grep -c '^pacman ' "$CALL_LOG") == 1 )) || fail "$1: one pacman transaction"
grep -qx 'systemctl try-restart fprintd.service' "$CALL_LOG" || fail "$1: restarts fprintd after install"
}

run_setup
assert_installs "a fresh machine installs libfprint-git, fprintd and usbutils"
assert_full_install "a fresh machine installs libfprint-git, fprintd and usbutils"
grep -qx enroll "$CALL_LOG" || fail "installation is followed by enrollment"
pass "a fresh machine installs libfprint-git and reaches enrollment"

INSTALLED=$'libfprint\nfprintd\nusbutils' run_setup
assert_installs "installed stock libfprint is replaced in the same transaction"
grep -qx 'pacman -S --needed --noconfirm --ask 4 libfprint-git' "$CALL_LOG" ||
fail "installed stock libfprint is replaced with libfprint-git only"
(( $(grep -c '^pacman ' "$CALL_LOG") == 1 )) || fail "stock replacement: one pacman transaction"
grep -qx 'systemctl try-restart fprintd.service' "$CALL_LOG" ||
fail "stock replacement restarts fprintd"
pass "installed stock libfprint is replaced without a removal step"

INSTALLED=$'libfprint-git\nfprintd\nusbutils' run_setup
if grep -q '^pacman' "$CALL_LOG"; then
fail "a rerun with everything installed does not touch pacman"
fi
if grep -q '^systemctl' "$CALL_LOG"; then
fail "a no-op package path does not restart fprintd"
fi
grep -qx enroll "$CALL_LOG" || fail "a rerun with everything installed reaches enrollment"
pass "a rerun with everything installed goes straight to enrollment"

INSTALLED=$'libfprint-goodix53x5\nfprintd\nusbutils' \
PROVIDES=$'libfprint=libfprint-goodix53x5\nlibfprint-2=libfprint-goodix53x5' \
run_setup
if grep -q '^pacman' "$CALL_LOG"; then
fail "a working libfprint fork is not replaced with libfprint-git"
fi
if grep -q '^systemctl' "$CALL_LOG"; then
fail "keeping a fork does not restart fprintd"
fi
grep -qx enroll "$CALL_LOG" || fail "a forked libfprint still reaches enrollment"
pass "a working libfprint fork is left alone"

INSTALL_STATUS=1 run_setup
if grep -qx enroll "$CALL_LOG"; then
fail "a failed package transaction prevents enrollment"
Expand Down
Loading