Face unlock window: live camera preview, Snap, thumbnails, one password on Apply
CI / test (push) Failing after 12m30s

Settings > Session "Add or remove faces…" (and "Remove…" on a face) opens a
compositor-drawn Face unlock window instead of running root steps one by one:

- chandra-face camera runs as the user (no password): it streams a small live
  picture with the face box and a cropped thumbnail per snap; the snaps'
  embeddings stay in that process, nothing is written to disk.
- Click a snap to drop it; mark saved faces Remove/Keep.
- Apply saves the snaps as one face and removes the marked ones in one root
  `chandra-face apply` (JSON on stdin, validated) through run0/pkexec: one
  password prompt.
- New raster host function image-pixels (host-wasm, wasmhost, native) for the
  window's pictures.

Tests: camera session and apply in face/test_face.py; the window end to end
against a fake tool in compositor/host/face_test.mbt. Docs explain why the
change itself still needs root.

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 02:36:29 +00:00
1 parent 0a9787ae36
commit 9f7489cfea
74 files changed
+2617 -89

No files matched your search

+50 -17
View File
@@ -31,18 +31,34 @@ The Settings rows are part of the session: after `just install`, log in again so
compositor, its host and the Settings module are the new ones. (`just reload` alone isn't enough: an older host doesn't serve
the `face-unlock` capability.) Then in **Settings > Session > Face unlock**:
- **Add a face…** asks for your password (in the password dialog), then looks through the
camera for about ten seconds and keeps five views of your face. Add another face for glasses,
a different light, or a second camera position.
- **Add or remove faces…** opens the Face unlock window (below). **Remove…** on a face opens it
with that face marked.
- **Use my face for passwords** puts the face first in the PAM services `polkit-1` (the password
dialog) and `sudo`, after the password. Turning it off takes it out again.
- **Remove** (click twice) forgets one face.
dialog) and `sudo`, after the password. Turning it off takes it out again (one password).
Everything Settings does runs `chandra-face` through run0 (or pkexec), so each change asks for
an administrator's password first. From a terminal:
### The Face unlock window
![The Face unlock window: live picture, two snaps, a saved face](screenshots/face-window.png)
- The camera starts at once, with no password: a live picture with a box round the face it sees.
- **Snap** (or Space) keeps the picture in view and shows it below; snap a few: straight on,
turned a little, with and without glasses. Click a snap to drop it. A snap that can't be used
says why ("No face in view", "More than one face in view", "Come closer to the camera").
- **Remove** / **Keep** on a saved face marks it for removal, or not.
- **Apply** (or Enter) saves the snaps as one new face and removes the marked ones, in one step:
the password dialog asks once, above the window. **Cancel** (Esc) changes nothing.
Why root at all: the face data is root's (`/var/lib/chandra-face`, 0600) and PAM trusts it to let
you into sudo and polkit without a password. If you could write it as yourself, so could any
program running as you, and it could quietly add a face (or a photo) of its choosing and then use
sudo. So only the change needs root, and only once: the camera and the pictures stay on your side,
and only the face data of the snaps you kept crosses to the root step. (Removing a face only
takes access away, so it could be allowed without a password; it isn't yet, to keep one rule.)
From a terminal (each root command asks for the password itself):
```sh
chandra-face enroll --label "Desk" # add a face
chandra-face enroll --label "Desk" # add a face (looks for ten seconds, keeps five views)
chandra-face list
chandra-face test # look now and print the similarity scores
chandra-face remove 2
@@ -130,18 +146,31 @@ models = /usr/local/share/chandra/face
the session-settings module reaches it through the `face-unlock` capability
(`wit/capabilities.wit`). The password dialog (`compositor/polkit/dialog.mbt`, `face_message`)
turns the module's messages into the face row.
- The Face unlock window (`compositor/host/face_window.mbt`, drawn by the compositor like the
password dialog) talks to `chandra-face camera`, run as you on a socket: it sends
`frame W H BX BY BW BH LEN` + RGB bytes (320 px wide, about 12 a second) and `snap ID 96 96 LEN`
+ RGB (the face, cropped), and reads `snap`, `drop ID`, `apply REMOVE-IDS`, `quit`. The snaps'
embeddings stay in that process; on `apply` it closes the camera and runs
`chandra-face apply` through run0/pkexec with `{"add": [{"label", "vectors"}], "remove": [ids]}`
on its stdin, which checks the data (sizes, finite numbers, the same length as the faces
already saved) and writes the store once. The window's pictures are host images
(`raster.image-pixels`), reused and dropped when it closes.
## Privacy and security
- **Nothing leaves the machine.** Camera frames are only held in memory by the root helper for the
few seconds it looks; they are never written to disk or sent anywhere. The only network access
is the one-time model download.
- **Nothing leaves the machine.** Camera frames are only held in memory, by the root helper for the
few seconds it looks, and by the Face unlock window (its camera process and its images) while
it is open; they are never written to disk or sent anywhere. The only network access is the
one-time model download.
- **What is stored**: per user, `/var/lib/chandra-face/USER/faces.json` (root, mode 0600) holds the
embeddings (feature vectors, not pictures) and `faces.list` (0644) only the labels and dates
that Settings shows. The helper refuses a store, config or model that is a symlink, not root's,
or writable by group or others.
- **Changing faces needs an administrator**: enrolling runs as root after polkit's password
check, so a program running as you can't quietly add someone else's face to your account.
- **Changing faces needs an administrator**: saving runs as root after polkit's password check,
so a program running as you can't quietly add someone else's face to your account. The face
data the window hands over comes from your own camera process: the password is the check, as
it is for anything else that root runs for you. With face unlock already on for polkit-1, the
face itself can answer that password dialog (the window closes the camera first so it can).
- **2D face recognition can be fooled.** A good photo or video of you held up to a normal (RGB)
webcam may be accepted: there is no liveness or depth check. An infrared camera (most "Windows
Hello" laptops have one) is much harder to fool with a photo or a screen; set `device` to it
@@ -156,7 +185,8 @@ models = /usr/local/share/chandra/face
`just test-face` runs `face/test_face.py` with a fake camera (a folder of PGM frames) and a
fake recognizer, so it needs no camera, OpenCV or models: enrollment, recognition, the reasons
for failing, permission checks on the store, PAM file editing (including Debian's
`@include common-auth`). `just test-face --pam` (as root, with `pamtester`) also builds the PAM
`@include common-auth`), and the window's camera session (live pictures, snaps, drops, one apply
that adds and removes, bad apply data refused). `just test-face --pam` (as root, with `pamtester`) also builds the PAM
module and runs it through a throwaway PAM service: a match succeeds, a stranger falls through,
remote and unenrolled users are skipped quietly, a hanging helper is killed, a writable helper is
not run. With `CHANDRA_FACE_MODELS=DIR` the OpenCV backend is checked on frames without a face.
@@ -164,8 +194,11 @@ not run. With `CHANDRA_FACE_MODELS=DIR` the OpenCV backend is checked on frames
On the compositor side, `compositor/polkit/polkit_test.mbt` covers the message parsing and the
dialog's face states, `compositor/host/auth_test.mbt` drives the dialog through a mock helper
(`CHANDRA_AUTH_SHOTS=dir` saves `14-face-scanning.png` and `15-face-failed.png`), and
`compositor/host/face_test.mbt` drives Settings > Session against a fake chandra-face.
`compositor/host/face_test.mbt` drives Settings > Session and the Face unlock window (Remove…
opens it with the face marked, Space snaps, Enter applies once, Esc cancels) against a fake
chandra-face (`CHANDRA_AUTH_SHOTS=dir` saves `17-face-window.png`).
Not verified here: a real camera (frames came from image files; with OpenCV's real models, a
rotated and rescaled photo of the enrolled face scored 0.92 and a different person -0.18), and
run0/pkexec elevation from Settings on a real systemd session.
rotated and rescaled photo of the enrolled face scored 0.92 and a different person -0.18; the
window's screenshot is the real pipeline on a photo), and run0/pkexec elevation (with the apply
data on stdin) on a real systemd session.