Face unlock: let polkit's sandboxed PAM helper open cameras
CI / test (push) Canceled after 28m1s

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 <noreply@anthropic.com>
This commit is contained in:
nandiandClaude Sonnet 5.5 committed 2026-11-25 22:33:44 -08:00
1 parent 2752b81e36
commit 738928352e
3 files changed
+59

No files matched your search

+12
View File
@@ -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 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`. 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 ## PAM
`chandra-face pam enable SERVICE` adds this line before the service's first `auth` (or `chandra-face pam enable SERVICE` adds this line before the service's first `auth` (or
+34
View File
@@ -18,6 +18,9 @@ Installs:
<PAM module dir>/pam_chandra_face.so the PAM module (`just install` builds it as you into <PAM module dir>/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) build/; else it's built here with cc and the libpam headers)
/etc/chandra/face.conf settings (kept when it exists) /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 /var/lib/chandra-face/ enrolled faces
/usr/local/share/chandra/face/*.onnx the YuNet and SFace models (downloaded, checksummed) /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" models = "/usr/local/share/chandra/face"
env_dir = "/usr/local/lib/chandra/face-env" env_dir = "/usr/local/lib/chandra/face-env"
env_python = os.path.join(env_dir, ".pixi/envs/default/bin/python3") 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(): def find_pixi():
@@ -76,6 +81,26 @@ def make_env():
return env_python 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(): def pam_dir():
"""Where this system's PAM modules live (next to pam_unix.so).""" """Where this system's PAM modules live (next to pam_unix.so)."""
cands = ["/usr/lib/security", "/lib/security", "/usr/lib64/security", "/lib64/security"] 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): if os.path.exists(helper):
subprocess.call([sys.executable, "-I", helper, "--no-elevate", "pam", "disable"] subprocess.call([sys.executable, "-I", helper, "--no-elevate", "pam", "disable"]
+ sorted(os.listdir("/etc/pam.d"))) + 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): for p in (mod, link, helper):
if os.path.lexists(p): if os.path.lexists(p):
os.remove(p) os.remove(p)
@@ -154,6 +187,7 @@ else:
os.chmod(mod + ".new", 0o644) os.chmod(mod + ".new", 0o644)
os.replace(mod + ".new", mod) os.replace(mod + ".new", mod)
print("installed", mod) print("installed", mod)
allow_polkit_camera()
if not os.path.exists(conf): if not os.path.exists(conf):
os.makedirs(os.path.dirname(conf), exist_ok=True) os.makedirs(os.path.dirname(conf), exist_ok=True)
+13
View File
@@ -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