Skip to content
Closed
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
3 changes: 3 additions & 0 deletions bin/omarchy-apply-lock
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ EOF
if [[ -x /usr/bin/fprintd-list ]] &&
/usr/bin/fprintd-list "$target_user" 2>/dev/null | grep -qi finger; then
echo "Configuring lock screen fingerprint authentication..."
# Same clamshell gate as sudo/polkit / setup-security-fingerprint: lid closed
# skips pam_fprintd and this stack fails closed (password is a parallel PAM).
as_root tee /etc/pam.d/omarchy-lock-fingerprint >/dev/null <<'EOF'
#%PAM-1.0
auth [success=ignore default=1] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-open
auth required pam_fprintd.so
account include system-local-login
EOF
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
8 changes: 4 additions & 4 deletions bin/omarchy-remove-security-fingerprint
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ set -e

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
28 changes: 20 additions & 8 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"

# 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 All @@ -58,8 +65,13 @@ EOF

setup_lock_fingerprint_pam() {
echo "Configuring lock screen for fingerprint authentication..."
sudo tee /etc/pam.d/omarchy-lock-fingerprint >/dev/null <<'EOF'
# Same clamshell gate as sudo/polkit: lid closed → skip pam_fprintd (fail closed
# here — this stack has no password fallback; password runs in a parallel PAM
# service). Re-enrollment must keep rewriting the gate so it cannot be wiped.
local fprintd_gate="auth [success=ignore default=1] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-open"
sudo tee /etc/pam.d/omarchy-lock-fingerprint >/dev/null <<EOF
#%PAM-1.0
$fprintd_gate
auth required pam_fprintd.so
account include system-local-login
EOF
Expand Down
15 changes: 15 additions & 0 deletions migrations/1789261001.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
echo "Gate lock-screen fingerprint auth behind the lid state"

# Existing fingerprint setups write /etc/pam.d/omarchy-lock-fingerprint with
# pam_fprintd alone. With the lid shut the lock screen still hammers the
# unreachable reader. Insert the same pam_exec gate sudo/polkit already use.
# New setups get this from omarchy-setup-security-fingerprint / omarchy-apply-lock.

gate="auth [success=ignore default=1] pam_exec.so quiet /usr/bin/omarchy-hw-laptop-open"
pam=/etc/pam.d/omarchy-lock-fingerprint

if [[ -f $pam ]] &&
grep -q 'pam_fprintd\.so' "$pam" &&
! grep -q 'omarchy-hw-laptop-open' "$pam"; then
sudo sed -i "/pam_fprintd\.so/i $gate" "$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"

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"
57 changes: 57 additions & 0 deletions test/shell.d/lock-fingerprint-clamshell-gate-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash

set -euo pipefail

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

setup="$ROOT/bin/omarchy-setup-security-fingerprint"
apply="$ROOT/bin/omarchy-apply-lock"

grep -F 'setup_lock_fingerprint_pam' "$setup" >/dev/null ||
fail "setup-security-fingerprint still defines setup_lock_fingerprint_pam"

# Extract the lock PAM writer by grepping the function body for the gate.
grep -A20 'setup_lock_fingerprint_pam()' "$setup" | grep -Fq 'omarchy-hw-laptop-open' ||
fail "setup_lock_fingerprint_pam writes the clamshell pam_exec gate"

grep -A20 'setup_lock_fingerprint_pam()' "$setup" | grep -Fq 'pam_fprintd.so' ||
fail "setup_lock_fingerprint_pam still requires pam_fprintd"

# Gate must come before pam_fprintd in the generated lock stack.
python3 - "$setup" <<'PY' || fail "lock PAM gate is ordered before pam_fprintd in setup"
import pathlib, re, sys
text = pathlib.Path(sys.argv[1]).read_text()
m = re.search(r"setup_lock_fingerprint_pam\(\) \{(.*?)^\}", text, re.S | re.M)
body = m.group(1)
if "omarchy-hw-laptop-open" not in body:
raise SystemExit(1)
# In the heredoc / tee payload, gate line must appear before pam_fprintd.
idx_gate = body.find("omarchy-hw-laptop-open")
idx_fp = body.find("pam_fprintd.so")
if idx_gate < 0 or idx_fp < 0 or idx_gate > idx_fp:
raise SystemExit(1)
PY
pass "setup lock fingerprint PAM includes an ordered clamshell gate"

grep -Fq 'omarchy-hw-laptop-open' "$apply" ||
fail "apply-lock writes the clamshell gate into omarchy-lock-fingerprint"
# Order inside apply-lock heredoc
python3 - "$apply" <<'PY' || fail "apply-lock orders the gate before pam_fprintd"
import pathlib, sys
text = pathlib.Path(sys.argv[1]).read_text()
start = text.find("omarchy-lock-fingerprint")
chunk = text[start:start+800]
if chunk.find("omarchy-hw-laptop-open") > chunk.find("pam_fprintd.so"):
raise SystemExit(1)
if "omarchy-hw-laptop-open" not in chunk:
raise SystemExit(1)
PY
pass "apply-lock lock fingerprint PAM includes an ordered clamshell gate"

migration="$ROOT/migrations/1789261001.sh"
[[ -f $migration ]] || fail "migration repairs existing lock fingerprint PAM"
grep -Fq 'omarchy-lock-fingerprint' "$migration" ||
fail "migration targets omarchy-lock-fingerprint"
grep -Fq 'omarchy-hw-laptop-open' "$migration" ||
fail "migration inserts the laptop-closed gate"
pass "migration installs the lock fingerprint clamshell gate on existing installs"