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

+9 -6
View File
@@ -14,10 +14,13 @@ any other service you add it to.
just install-face # PAM module, chandra-face, settings, face models (asks for root once)
```
You need Python 3 with OpenCV 4.5.4 or later (`python3-opencv` on Debian/Ubuntu/Fedora,
`python-opencv` on Arch), a C compiler and the PAM headers (`libpam0g-dev` / `pam-devel`). The
models (OpenCV's YuNet face detector and SFace recognizer, 37 MB) are downloaded from the
opencv_zoo repository and checked against their SHA-256 sums.
Nothing from the distro is needed beyond a C compiler and the PAM headers (`libpam0g-dev` /
`pam-devel`) and [pixi](https://pixi.sh): Python, OpenCV and numpy come from a pixi environment
(`face/pixi.toml` + `face/pixi.lock`) that install-face makes in `/usr/local/lib/chandra/face-env`,
owned by root. It is deliberately not the checkout's `.pixi`: the PAM module runs that Python as
root, so it must not be anywhere a user can write. The models (OpenCV's YuNet face detector and
SFace recognizer, 37 MB) are downloaded from the opencv_zoo repository and checked against their
SHA-256 sums. The environment takes about 450 MB.
The Settings rows are part of the session, not of `install-face`: after updating Chandra, run
`just install` (or `just install-dev`) and log in again so the compositor, its host and the
@@ -79,7 +82,7 @@ by hand instead, put that line at the top of the auth section; module options:
| --- | --- |
| `timeout=N` | the helper gets N + 6 seconds in all before it is killed (default 4; the camera's own timeout is in face.conf) |
| `config=PATH` | another settings file (default `/etc/chandra/face.conf`) |
| `helper=PATH`, `python=PATH` | another chandra-face / Python (default `/usr/local/lib/chandra/chandra-face`, `/usr/bin/python3`) |
| `helper=PATH`, `python=PATH` | another chandra-face / Python (default `/usr/local/lib/chandra/chandra-face` and the face-env's python3; both must be root's) |
| `quiet` | don't send the "looking" / "not recognized" messages |
| `debug` | the helper's stderr goes to the application's stderr; skipped helpers are logged |
@@ -114,7 +117,7 @@ models = /usr/local/share/chandra/face
to the application's conversation as `PAM_TEXT_INFO` or `PAM_ERROR_MSG`, and maps its exit status
to `PAM_SUCCESS` (0), `PAM_AUTH_ERR` (1) or `PAM_AUTHINFO_UNAVAIL` (anything else). The helper
must be root's and not writable by others, or it is not run.
- `face/chandra-face` (Python): finds faces with YuNet, turns the largest one into a 128-number
- `face/chandra-face` (Python, on the face-env's interpreter): finds faces with YuNet, turns the largest one into a 128-number
SFace embedding, and compares it with the stored ones (cosine similarity). It also enrolls,
lists, removes, edits PAM files, reports status and downloads the models. Root commands run by
another user re-run themselves through run0 (or pkexec when systemd isn't PID 1).