Sign in to sudo and polkit with a security key or fingerprint

Ports configure security-key and configure fingerprint from CoreDesktop's
9dc5eb1: touch a FIDO2 key or a finger instead of typing your password for
sudo and polkit, falling back to the password. Each shows only when the
hardware is there. The fingerprint skips to the password with the lid shut.

lib/pam.sh is CoreDesktop's, but also takes Ubuntu's "@include
common-auth" as the start of a stack's auth part, which is how sudo's and
polkit's begin. Only those two stacks change, not common-auth, which
pam-auth-update owns and every sign-in includes. libpam-fprintd's
pam-auth-update profile is off by default, so installing it changes no
sign-in by itself. The login and lock screens keep asking for the
password, unlike on GNOME.

Smoketest: 70-sign-in, on copies of Ubuntu's sudo and polkit stacks.
TEST.md: with a real key and reader.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-28 19:03:41 -07:00
co-authored by Claude Opus 5.5
parent 2952034654
commit 7185d6cb3e
8 changed files with 411 additions and 3 deletions
+1
View File
@@ -37,6 +37,7 @@ Each run writes its logs to `smoketest/results/<time>/`, one per scenario, and p
| `50-sandbox` *(all)* | Node.js and srt download and install. A stand-in agent can't read `~/.ssh` or Federated Connector's settings, or write outside its project, reaches allowed sites only, and won't start in your home folder. A new bash finds the sandboxed command first. |
| `55-hermes-homeserver` | Hermes' gateway reaches only a Matrix server you've allowed: a server in Hermes' settings is to do until `configure hermes` allows it, a wildcard or escape codes never count, and `configure agents` carries over the server an old drop-in allowed. `edit_json` fills an empty file from its default. |
| `60-packages` *(all)* | davfs2 installs with `mount.davfs` setuid, and `davfs2_ready` fixes one installed without. sshfs' `fusermount3` and smbclient are where `configure storage` expects them, and so is GTK's CUPS print backend. mise installs from its apt repository and a new bash has it. |
| `70-sign-in` | `configure security-key` and `configure fingerprint` on copies of Ubuntu's sudo and polkit stacks, which start with `@include common-auth`: the line goes just before it, polkit gets its own copy and the vendor's is left alone, adding twice adds once, and stopping puts sudo back as it was. A FIDO2 key is found by its HID descriptor, a reader by its vendor (unless a driver claims it, like a touchpad) or its name. |
## What still needs Pop!_OS
+96
View File
@@ -0,0 +1,96 @@
# shellcheck shell=bash
# Scenarios set what the runner and items read
# shellcheck disable=SC2034
DESCRIPTION="Security key and fingerprint: PAM lines for sudo and polkit, and finding the hardware"
TIER=quick
scenario() {
local sudo_before polkit_before
# Everything here is in $HOME, so nothing needs root
sudo() { "$@"; }
# Copies of Ubuntu's sudo and polkit stacks, which start with @include
export PAM_DIR="$HOME/pam.d" PAM_VENDOR_DIR="$HOME/lib-pam.d"
mkdir -p "$PAM_DIR" "$PAM_VENDOR_DIR"
cat > "$PAM_DIR/sudo" << 'EOF'
#%PAM-1.0
# Set up user limits from /etc/security/limits.conf.
session required pam_limits.so
session required pam_env.so readenv=1 user_readenv=0
session required pam_env.so readenv=1 envfile=/etc/default/locale user_readenv=0
@include common-auth
@include common-account
@include common-session-noninteractive
EOF
cat > "$PAM_VENDOR_DIR/polkit-1" << 'EOF'
#%PAM-1.0
@include common-auth
@include common-account
@include common-password
session required pam_env.so readenv=1 user_readenv=0
@include common-session-noninteractive
EOF
sudo_before="$(cat "$PAM_DIR/sudo")"
polkit_before="$(cat "$PAM_VENDOR_DIR/polkit-1")"
step "Security key"
export U2F_MAPPINGS="$HOME/u2f_mappings" HIDRAW="$HOME/hidraw"
source "$CONNECTOR/configure.d/70-security-key.sh"
check_not "not shown without a key" is_installed
mkdir -p "$HIDRAW/hidraw0/device" "$HIDRAW/hidraw1/device"
printf '\x05\x01\x09\x06' > "$HIDRAW/hidraw0/device/report_descriptor"
check_not "a keyboard isn't a key" key_plugged_in
printf '\x06\xd0\xf1\x09\x01' > "$HIDRAW/hidraw1/device/report_descriptor"
check "a FIDO2 key is" key_plugged_in
check "shown with one plugged in" is_installed
check "use_keys" use_keys
check "sudo takes the key" pam_has sudo pam_u2f.so
check_eq "just before common-auth" "@include common-auth" \
"$(grep -A1 pam_u2f.so "$PAM_DIR/sudo" | tail -n 1)"
check "polkit gets its own copy, which takes the key" pam_has polkit-1 pam_u2f.so
check_eq "the vendor's copy is left alone" "$polkit_before" "$(cat "$PAM_VENDOR_DIR/polkit-1")"
check_not "not done without a registered key" is_configured
echo "$USER:credential" > "$U2F_MAPPINGS"
check "done with one" is_configured
use_keys
check_eq "use_keys again adds nothing" 1 "$(grep -c pam_u2f.so "$PAM_DIR/sudo")"
stop_using_keys > /dev/null
check_eq "stop_using_keys puts sudo back as it was" "$sudo_before" "$(cat "$PAM_DIR/sudo")"
check_not "and polkit" pam_has polkit-1 pam_u2f.so
check_not "and forgets your keys" key_registered
step "Fingerprint"
export USB_DEVICES="$HOME/usb" LID_CLOSED="$HOME/lid-closed"
source "$CONNECTOR/configure.d/71-fingerprint.sh"
mkdir -p "$USB_DEVICES/1-1" "$USB_DEVICES/1-2/1-2:1.0" "$HOME/drivers/usbhid"
echo "USB Keyboard" > "$USB_DEVICES/1-1/product"
# A Synaptics touchpad: the vendor makes readers too, but a driver claims it
echo 06cb > "$USB_DEVICES/1-2/idVendor"
ln -s "$HOME/drivers/usbhid" "$USB_DEVICES/1-2/1-2:1.0/driver"
check_not "not shown without a reader" is_installed
mkdir -p "$USB_DEVICES/1-3"
echo 27c6 > "$USB_DEVICES/1-3/idVendor"
check "a Goodix reader, which no driver claims, is found" reader_present
rm -rf "$USB_DEVICES/1-3"
mkdir -p "$USB_DEVICES/1-4"
echo "ELAN:ARM-M4" > "$USB_DEVICES/1-4/product"
check "and an Elan one, by its name" reader_present
check "use_fingerprint" use_fingerprint
check "the lid check is installed" test -x "$LID_CLOSED"
check_eq "it skips the reader when the lid check succeeds" \
"auth [success=1 default=ignore] pam_exec.so quiet $LID_CLOSED" \
"$(grep -B1 pam_fprintd.so "$PAM_DIR/sudo" | head -n 1)"
check "polkit takes it" pam_has polkit-1 pam_fprintd.so
stop_using_fingerprint > /dev/null
check_eq "stop_using_fingerprint puts sudo back as it was" "$sudo_before" "$(cat "$PAM_DIR/sudo")"
check_not "and polkit" grep -q "pam_fprintd\|lid-closed" "$PAM_DIR/polkit-1"
rm -rf "$PAM_DIR" "$PAM_VENDOR_DIR" "$HIDRAW" "$USB_DEVICES" "$HOME/drivers" "$U2F_MAPPINGS" "$LID_CLOSED"
unset PAM_DIR PAM_VENDOR_DIR U2F_MAPPINGS HIDRAW USB_DEVICES LID_CLOSED
unset -f sudo
}