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

+13 -3
View File
@@ -38,7 +38,7 @@
#define CHANDRA_FACE_HELPER "/usr/local/lib/chandra/chandra-face"
#endif
#ifndef CHANDRA_FACE_PYTHON
#define CHANDRA_FACE_PYTHON "/usr/bin/python3"
#define CHANDRA_FACE_PYTHON "/usr/local/lib/chandra/face-env/.pixi/envs/default/bin/python3"
#endif
struct opts {
@@ -111,6 +111,12 @@ static void forward(pam_handle_t *pamh, const struct opts *o, char *line) {
}
}
/* Only root can change it: root's, not writable by others, nor by a group other than root's
* (pixi environments keep conda's 0775 modes, group root). */
static int root_only(const struct stat *st) {
return st->st_uid == 0 && !(st->st_mode & 002) && (!(st->st_mode & 020) || st->st_gid == 0);
}
static long now_ms(void) {
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
@@ -125,12 +131,16 @@ PAM_EXTERN int pam_sm_authenticate(pam_handle_t *pamh, int flags, int argc, cons
if (pam_get_user(pamh, &user, NULL) != PAM_SUCCESS || !user || !*user) return PAM_USER_UNKNOWN;
if (is_remote(pamh)) return PAM_AUTHINFO_UNAVAIL;
if (lid_closed()) return PAM_AUTHINFO_UNAVAIL;
/* The helper must be root's: it runs as root with the user's face data. */
/* The helper and its Python must be root's: they run as root with the user's face data. */
struct stat st;
if (stat(o.helper, &st) != 0 || st.st_uid != 0 || (st.st_mode & 022)) {
if (stat(o.helper, &st) != 0 || !root_only(&st)) {
if (o.debug) pam_syslog(pamh, LOG_WARNING, "helper %s missing or not root's", o.helper);
return PAM_AUTHINFO_UNAVAIL;
}
if (stat(o.python, &st) != 0 || !root_only(&st)) {
if (o.debug) pam_syslog(pamh, LOG_WARNING, "python %s missing or not root's", o.python);
return PAM_AUTHINFO_UNAVAIL;
}
int pfd[2];
if (pipe2(pfd, O_CLOEXEC) != 0) return PAM_AUTHINFO_UNAVAIL;
/* Our caller may ignore SIGCHLD (then waitpid can't see the helper exit); restore it. */