Files
chandra/docs/lock.md
T
nandi c790f96e58
CI / test (push) Waiting to run
Lock: add session lock from power button and chandra-ctl lock
- Lock the session from the power button or `chandra-ctl lock`
- Unlock with a face or the password; the password always works
- Add compositor lock module with tests, and a polkit unlock policy (org.chandra.unlock)
- Document the lock flow in docs/lock.md and link it from the README
- Add generated interface bindings for the compositor and widget components
2026-11-29 03:24:46 -08:00

75 lines
4.1 KiB
Markdown

# Locking the screen
Chandra can lock the session: the desktop is hidden and nothing but the unlock prompt gets
input until a **face** (or, as the fallback, your **password**) lets you back in. It reuses the
password dialog ([auth-dialog.md](auth-dialog.md)) and face unlock ([face-unlock.md](face-unlock.md)),
so there is no second lock UI to configure.
## Turn it on
Locking on screen-off is **off by default** so a half-set-up machine can't lock you out. Turn it
on by setting `CHANDRA_LOCK=1` in the session environment or toggling it at runtime via
`chandra-ctl lock on-blank on`; then pressing the **power button** (or `chandra-ctl screen off`) to
blank the screen also locks it, and waking the screen asks for your face or password.
`chandra-ctl lock` locks immediately, regardless of the setting (handy to bind to a key or a
panel button).
```sh
chandra-ctl lock # lock now
chandra-ctl lock status # locked | unlocked
chandra-ctl lock on-blank on # arm lock-on-blank at runtime (on | off | status)
```
**Before you enable it, make sure you can get back in:** enroll a face
(`chandra-face enroll`, or Settings > Session > Face unlock) and/or confirm your login password
works, and that face unlock is in the `polkit-1` PAM stack (`chandra-face pam enable polkit-1`,
which `just install --pam` does). If neither the camera nor the password can authenticate, the
session stays locked and only an SSH login can recover it.
## How it works
```
power off / chandra-ctl lock
│
▼
compositor: locked ──"unlock"──► chandra-polkit-agent
• hides windows/panel │ CheckAuthorization(unix-process, org.chandra.unlock)
• swallows input ▼
• dark lock backdrop polkit ──► this agent's dialog: face (PAM), then password
• draws the unlock dialog │
▲ │
└────────── "unlocked" ◄──────┘ (success) "unlock-failed" ◄── (cancel / fail)
```
- **Locking** is in [`compositor/host/lock.mbt`](../compositor/host/lock.mbt). The power button
([`compositor/host/compositor.mbt`](../compositor/host/compositor.mbt), `handle_input_inner`,
key `116`) and `chandra-ctl screen` route through `set_manual_screen_off` in
[`compositor/host/power.mbt`](../compositor/host/power.mbt); `lock_on_blank` (from `CHANDRA_LOCK`
or `chandra-ctl lock on-blank`) decides whether blanking also locks. Blanked again while unlock
is in flight, the compositor sends `cancel-unlock` so polkit and the camera stop immediately.
While locked, `build_scene` hides windows, popups, desktop widgets, and the panel behind a dark
`"Screen locked"` backdrop, and `handle_input_inner` swallows input (re-raising unlock only on
a key or button press when no dialog is up).
- **Unlocking** runs in the polkit agent
([`compositor/polkit/agent_loop.mbt`](../compositor/polkit/agent_loop.mbt),
[`agent.mbt`](../compositor/polkit/agent.mbt)): once registered with polkit, on an `unlock`
message it passes a `unix-process` subject (`pid`, `start-time`, `uid` from `/proc`) to
`CheckAuthorization` for **`org.chandra.unlock`** with `AllowUserInteraction` (and cancels via
`CancelCheckAuthorization` on `cancel-unlock`). polkit then drives the agent's own dialog, and
because the `polkit-1` PAM stack carries `pam_chandra_face.so` the camera is tried first, with
the password as the fallback. The action is `auth_self` (never `_keep`), so it prompts every
time and nothing is cached.
- The policy file is
[`compositor/polkit/org.chandra.unlock.policy`](../compositor/polkit/org.chandra.unlock.policy),
installed to `/usr/share/polkit-1/actions/` by `session/install.py`.
## Limits (today)
- Lock-on-idle isn't wired yet — only the power button, `chandra-ctl screen off`, and
`chandra-ctl lock` lock. (The idle timeout still blanks the screen without locking.)
- The idle lock backdrop is a minimal padlock card ("Screen locked") rather than a custom clock or
wallpaper clock widget.
- Cancelling the unlock prompt keeps you locked (the desktop stays hidden); the next key press or
screen tap raises the prompt again.