Files
connector-popos/smoketest/scenarios/70-sign-in.sh
T
davidandClaude Opus 5.5 7185d6cb3e 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>
2026-11-28 19:03:41 -07:00

97 lines
4.1 KiB
Bash

# 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
}