From 738928352e0fd62945818bc423e7a1734b42186e Mon Sep 17 00:00:00 2001 From: nandithebull Date: Wed, 25 Nov 2026 22:33:44 -0800 Subject: [PATCH] Face unlock: let polkit's sandboxed PAM helper open cameras polkit 126+ runs the password dialog's PAM stack in polkit-agent-helper@.service, whose PrivateDevices=yes leaves no cameras in /dev, so the dialog reported "no camera" while sudo and enrolling worked. Install a drop-in that allows only V4L2 devices and keeps the capability and syscall limits PrivateDevices= added. Co-Authored-By: Claude Sonnet 5.5 --- docs/face-unlock.md | 12 ++++++++++++ face/install.py | 34 ++++++++++++++++++++++++++++++++++ face/polkit-agent-helper.conf | 13 +++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 face/polkit-agent-helper.conf diff --git a/docs/face-unlock.md b/docs/face-unlock.md index 8dd1a2d..22026bc 100644 --- a/docs/face-unlock.md +++ b/docs/face-unlock.md @@ -88,6 +88,18 @@ as…", "Failure, timeout reached", "Face detection image too dark"), so if you keep `pam_howdy.so` and the dialog shows its progress the same way; Settings says which PAM services use Howdy. Faces you enrolled with Howdy are managed with `sudo howdy add`/`remove`. +## polkit's sandbox + +Since polkit 126, the password dialog's PAM stack runs in `polkit-agent-helper@.service`, which +has `PrivateDevices=yes`: its `/dev` has no cameras. The symptom is that sudo, enrolling and +`chandra-face status` find the camera, while the dialog says "no camera at …; no camera that takes +pictures is connected". `just install` adds a drop-in +(`face/polkit-agent-helper.conf`, as +`/etc/systemd/system/polkit-agent-helper@.service.d/50-chandra-face.conf`) that turns that off and +allows only V4L2 devices (`DevicePolicy=closed`, `DeviceAllow=char-video4linux rw`), keeping the +capability and syscall restrictions `PrivateDevices=` added. The rest of the unit's sandbox stays. +It applies from the next dialog, with no restart or new login. `just uninstall` removes it. + ## PAM `chandra-face pam enable SERVICE` adds this line before the service's first `auth` (or diff --git a/face/install.py b/face/install.py index eea79d4..f7d9c01 100644 --- a/face/install.py +++ b/face/install.py @@ -18,6 +18,9 @@ Installs: /pam_chandra_face.so the PAM module (`just install` builds it as you into build/; else it's built here with cc and the libpam headers) /etc/chandra/face.conf settings (kept when it exists) + /etc/systemd/system/polkit-agent-helper@.service.d/50-chandra-face.conf + lets polkit's sandboxed PAM helper open cameras (only + where polkit has that unit) /var/lib/chandra-face/ enrolled faces /usr/local/share/chandra/face/*.onnx the YuNet and SFace models (downloaded, checksummed) @@ -35,6 +38,8 @@ store = "/var/lib/chandra-face" models = "/usr/local/share/chandra/face" env_dir = "/usr/local/lib/chandra/face-env" env_python = os.path.join(env_dir, ".pixi/envs/default/bin/python3") +polkit_unit = "polkit-agent-helper@.service" +polkit_dropin = "/etc/systemd/system/%s.d/50-chandra-face.conf" % polkit_unit def find_pixi(): @@ -76,6 +81,26 @@ def make_env(): return env_python +def daemon_reload(): + """Make systemd read the unit files again; the next password dialog gets a new helper.""" + if os.path.isdir("/run/systemd/system"): + subprocess.check_call(["systemctl", "daemon-reload"]) + + +def allow_polkit_camera(): + """polkit 126+ runs PAM in a unit whose /dev has no cameras (PrivateDevices=yes): without + this drop-in the password dialog never finds one, though sudo and enrolling do.""" + if not any(os.path.exists(os.path.join(d, polkit_unit)) for d in + ("/etc/systemd/system", "/usr/local/lib/systemd/system", "/usr/lib/systemd/system", + "/lib/systemd/system")): + return # an older polkit (a setuid helper, no sandbox) or no systemd + os.makedirs(os.path.dirname(polkit_dropin), 0o755, exist_ok=True) + shutil.copyfile(os.path.join(here, "polkit-agent-helper.conf"), polkit_dropin) + os.chmod(polkit_dropin, 0o644) + daemon_reload() + print("installed", polkit_dropin) + + def pam_dir(): """Where this system's PAM modules live (next to pam_unix.so).""" cands = ["/usr/lib/security", "/lib/security", "/usr/lib64/security", "/lib64/security"] @@ -96,6 +121,14 @@ if "--remove" in sys.argv: if os.path.exists(helper): subprocess.call([sys.executable, "-I", helper, "--no-elevate", "pam", "disable"] + sorted(os.listdir("/etc/pam.d"))) + if os.path.exists(polkit_dropin): + os.remove(polkit_dropin) + print("removed", polkit_dropin) + try: + os.rmdir(os.path.dirname(polkit_dropin)) # if nothing else is in it + except OSError: + pass + daemon_reload() for p in (mod, link, helper): if os.path.lexists(p): os.remove(p) @@ -154,6 +187,7 @@ else: os.chmod(mod + ".new", 0o644) os.replace(mod + ".new", mod) print("installed", mod) +allow_polkit_camera() if not os.path.exists(conf): os.makedirs(os.path.dirname(conf), exist_ok=True) diff --git a/face/polkit-agent-helper.conf b/face/polkit-agent-helper.conf new file mode 100644 index 0000000..a763af8 --- /dev/null +++ b/face/polkit-agent-helper.conf @@ -0,0 +1,13 @@ +# Installed by Chandra's face unlock (face/install.py) as +# /etc/systemd/system/polkit-agent-helper@.service.d/50-chandra-face.conf +# +# polkit runs PAM for the password dialog (run0, pkexec) in this unit. Its PrivateDevices=yes +# gives it a /dev with no cameras, so pam_chandra_face.so could never see one there. +[Service] +PrivateDevices=no +# Of the real /dev, only the standard pseudo devices and cameras can be opened. +DevicePolicy=closed +DeviceAllow=char-video4linux rw +# What PrivateDevices=yes also did, kept. +CapabilityBoundingSet=~CAP_MKNOD CAP_SYS_RAWIO +SystemCallFilter=~@raw-io