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

+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
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)