Face unlock: Python, OpenCV and numpy from a root-owned pixi environment
CI / test (push) Successful in 2m41s

- face/pixi.toml + pixi.lock (python 3.12, numpy, opencv-python-headless). `just install-face`
  passes the pixi on your PATH; install.py runs `pixi install --frozen` as root into
  /usr/local/lib/chandra/face-env (not the checkout's .pixi: the PAM module runs this Python as
  root, so it must not be user-writable), writes the helper's shebang for it and builds the PAM
  module with it as the default python. No python3-opencv needed; uninstall removes the env.
- The PAM module now also refuses a Python that isn't root's; group-writable is accepted only
  for group root (conda/pixi files are 0775 root:root), in the module and chandra-face's checks.
- Elevation re-runs on the same interpreter (sys.executable). "OpenCV is missing: run just
  install-face" instead of naming the distro package. Dropped a stray __pycache__.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
Claude committed 2026-11-26 01:34:45 +00:00
1 parent fa634956cc
commit b097116ded
10 files changed
+1105 -26

No files matched your search

+5 -5
View File
@@ -105,7 +105,7 @@ def check_trusted(path, what):
raise Fail("%s %s is a symlink" % (what, path), 2)
if st.st_uid not in (0, os.geteuid()):
raise Fail("%s %s is not owned by root" % (what, path), 2)
if st.st_mode & 0o022:
if st.st_mode & 0o002 or (st.st_mode & 0o020 and st.st_gid != 0):
raise Fail("%s %s can be written by others" % (what, path), 2)
@@ -248,7 +248,7 @@ class OpenCVRecognizer:
import cv2 # noqa
import numpy # noqa
except ImportError:
raise Fail("python3-opencv (with numpy) is not installed", 2)
raise Fail("OpenCV is missing: run just install-face", 2)
import cv2
import numpy as np
@@ -622,7 +622,7 @@ def cmd_status(cfg, user, out):
try:
import cv2 # noqa
except ImportError:
problem = "python3-opencv is not installed"
problem = "OpenCV is missing: run just install-face"
if not problem:
for m in MODELS:
if not os.path.exists(os.path.join(cfg.models, m)):
@@ -681,10 +681,10 @@ def elevate(argv, user):
args += ["--user", user]
run0 = shutil.which("run0")
if run0 and os.path.isdir("/run/systemd/system"):
os.execv(run0, [run0, "--background=", "--"] + ["/usr/bin/python3", "-I"] + args)
os.execv(run0, [run0, "--background=", "--"] + [sys.executable, "-I"] + args)
pk = shutil.which("pkexec")
if pk:
os.execv(pk, [pk, "/usr/bin/python3", "-I"] + args)
os.execv(pk, [pk, sys.executable, "-I"] + args)
raise Fail("needs root, and neither run0 nor pkexec is installed")