Password dialog rebuilt: a separate polkit agent, one state machine, explicit errors
CI / test (push) Canceled after 21m14s
CI / test (push) Canceled after 21m14s
The first version ran polkit registration, polkit-agent-helper-1, the PAM conversation and the drawing inside the compositor's frame loop, with overlapping state in two layers. A helper that quit before asking was taken for a wrong password and restarted in a loop that wiped the field (typing seemed dead), a refused registration quietly started a third-party agent, and the dialog and the Face unlock window each grabbed the keyboard. Now: - chandra-polkit-agent (compositor/authagent, /usr/local/lib/chandra) does polkit and PAM. Each request runs one state machine (polkit/machine.mbt: starting, asking, checking, failed, done). A check that quits or can't start is Failed with the reason and waits for Try again; only a wrong password starts the next check by itself. It logs each step to stderr (the session log), never the typed text. - The compositor starts it on a socket pair and only draws what it says (host/auth.mbt, auth_draw.mbt; line protocol in polkit/wire.mbt). One input owner (grab_input): the dialog, else the Face unlock window. - No silent fallback: if the agent can't run, polkit refuses it, polkit doesn't answer in 10 s, or it dies, a notice on screen says why (a crash after it ran restarts it, up to 3 times, and says so). The third-party agent runs only when the Settings switch is off. - chandra-ctl auth-demo [password|face|face-ok|die|slow|users] shows the real dialog with a pretend check (password "demo"), no root needed; chandra-ctl auth-status says whether the agent is registered. - just install builds and installs the agent (just auth-agent). Tests: polkit_test (link, machine, view, helper Gone) and auth_test end to end through handle_input: the agent loop in-process against a mock polkit on a private dbus-daemon plus a mock helper, and the real agent program spawned by the compositor (demo, and registered with the mock polkit). Typing on a real xkb keymap, wrong password, cancel, withdrawal, helper quitting early or missing, polkit refusing, agent not starting or crashing, demo modes, Face unlock Apply. 170/170 host and 20/20 polkit tests pass. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
This commit is contained in:
22 files changed
+3462
-1806
No files matched your search
+106
-43
@@ -2,60 +2,123 @@
|
||||
|
||||
When run0, pkexec, a disk mount or any other polkit-checked action needs an administrator's
|
||||
password, Chandra asks in its own dialog: a card in the middle of a dimmed screen, drawn by the
|
||||
compositor in the shell layer, above every window and client menu.
|
||||
compositor above every window and client menu.
|
||||
|
||||
## Try it
|
||||
|
||||
```sh
|
||||
chandra-ctl auth-demo # the dialog with a pretend check: the password is "demo"
|
||||
chandra-ctl auth-demo face # looks for a face, gives up, then asks for the password
|
||||
chandra-ctl auth-demo die # the check quits before asking (a broken polkit setup); Try again
|
||||
chandra-ctl auth-status # is the agent running and registered with polkit, or why not
|
||||
run0 true # the real thing: your password, through polkit and PAM
|
||||
```
|
||||
|
||||
Demo modes: `password` (default), `face`, `face-ok`, `die`, `slow`, `users`. A demo needs no
|
||||
root and runs nothing; it uses the same agent program, link, state machine and drawing as a real
|
||||
request, only the password check is pretend.
|
||||
|
||||
If something goes wrong, the session log says what happened step by step:
|
||||
|
||||
```sh
|
||||
grep -E 'chandra-polkit-agent|password dialog' ~/.local/state/chandra/session.log
|
||||
```
|
||||
|
||||
## What it shows
|
||||
|
||||
- **What it says.** For run0 the dialog shows the command that will run (`gparted /dev/sda`) and as
|
||||
whom, instead of polkit's "start transient unit 'run-p15802-i1990.service'": the unit name
|
||||
carries run0's pid, and run0's command line says what it runs. pkexec's command comes from
|
||||
polkit's details. Everything else shows polkit's own message. Details (Alt+D) lists who asked
|
||||
(process and its parent), the target user, the unit and the polkit action id.
|
||||
whom, instead of polkit's "start transient unit 'run-p15802-i1990.service'". pkexec's command
|
||||
comes from polkit's details. Everything else shows polkit's own message. Details (Alt+D) lists
|
||||
who asked, the target user, the unit and the polkit action id.
|
||||
- **Who answers.** The account polkit wants: you when you are an administrator, else one of the
|
||||
admins (members of `wheel`/`sudo` are expanded). With several, Tab to the account row and use
|
||||
← →.
|
||||
- **Keyboard.** The field has the focus. Enter authenticates, Esc cancels, Tab / Shift+Tab move
|
||||
between the account, Show, Details, Cancel and Authenticate, Space or Enter activates them.
|
||||
Alt+R shows or hides the password, Ctrl+U clears it. Typing goes through the same xkb keymap
|
||||
apps get (groups, Shift, AltGr, Caps Lock), so the password is typed on your layout. Caps Lock
|
||||
on shows a warning.
|
||||
- **PAM.** The dialog follows whatever PAM asks through polkit's helper: password prompts, visible
|
||||
prompts (a one-time code), information (a fingerprint reader asking for a finger) and errors
|
||||
(faillock's "account is locked"). A wrong password shakes the card, says so, and starts again.
|
||||
Face unlock (pam_chandra_face.so, or Howdy's pam_howdy.so) gets its own row: "Looking for your
|
||||
face…" while the camera looks (the password can be typed meanwhile), then "Face recognized" or
|
||||
why not, before the password prompt; see [face-unlock.md](face-unlock.md).
|
||||
While PAM checks, the field is locked and a spinner shows.
|
||||
Alt+R shows or hides the password, Ctrl+U clears it. Typing goes through the xkb keymap apps
|
||||
get (groups, Shift, AltGr, Caps Lock), so the password is typed on your layout. Caps Lock on
|
||||
shows a warning.
|
||||
- **PAM.** Password prompts, visible prompts (a one-time code), information (a fingerprint reader)
|
||||
and errors (faillock's "account is locked") are shown as PAM says them. A wrong password shakes
|
||||
the card, says so, and PAM asks again. Face unlock gets its own row ("Looking for your face…",
|
||||
then "Face recognized" or why not); the password can be typed meanwhile and goes in when PAM
|
||||
asks for it. See [face-unlock.md](face-unlock.md).
|
||||
- **When the check fails without a verdict** (polkit's helper can't be reached, quits before
|
||||
asking, or quits while checking), the dialog says exactly that and waits: the main button
|
||||
becomes **Try again**. Nothing is retried behind your back.
|
||||
- **Safety.** While the dialog is up no client has keyboard focus, input goes to the dialog only,
|
||||
and client popups are hidden, so nothing can draw over it or read the keys. The password is kept
|
||||
as characters wiped after sending, the buffer sent to the helper is zeroed, and nothing of it is
|
||||
logged.
|
||||
and client popups are hidden. The password is kept as characters wiped after sending, the
|
||||
buffers it passes through are zeroed, and nothing of it is logged.
|
||||
|
||||
## How it works
|
||||
|
||||
- `compositor/polkit/agent.mbt`: connects to the system bus with the compositor's own D-Bus code
|
||||
and calls `RegisterAuthenticationAgent` on `org.freedesktop.PolicyKit1.Authority` for the login
|
||||
session (`XDG_SESSION_ID`, else logind's session of the compositor's pid). It serves
|
||||
`org.freedesktop.PolicyKit1.AuthenticationAgent` at `/org/chandra/PolicyKit1/AuthenticationAgent`:
|
||||
`BeginAuthentication` calls queue up and are answered when the dialog is done (an empty reply
|
||||
after success, `org.freedesktop.PolicyKit1.Error.Cancelled` when dismissed);
|
||||
`CancelAuthentication` closes the dialog.
|
||||
- `compositor/polkit/helper.mbt`: the PAM conversation through `polkit-agent-helper-1`. With polkit
|
||||
126+ it connects to `/run/polkit/agent-helper.socket` (socket activation) and sends the user name
|
||||
and cookie; otherwise it runs the setuid helper (`/usr/lib/polkit-1/...` or
|
||||
`/usr/libexec/...`) on a socket pair (`sys.spawn-socket`, implemented by all three hosts) and
|
||||
sends the cookie. On success the helper tells polkitd itself.
|
||||
- `compositor/polkit/describe.mbt`, `keymap.mbt`, `dialog.mbt`: words for a request, the xkb
|
||||
keymap parser, the dialog's states. `compositor/host/auth.mbt`: drawing and input.
|
||||
- Only the login session (`--drm`) registers. The setting is state.edn `:auth-agent :system` when
|
||||
off. If polkit refuses (another agent already has the session) or there is no system bus, the
|
||||
compositor starts the third-party agent `chandra-session` found (`CHANDRA_POLKIT_FALLBACK`).
|
||||
Turning the switch off live unregisters and starts that agent; turning it back on while that
|
||||
agent runs takes effect at the next login (polkit allows one agent per session).
|
||||
- Debug: `CHANDRA_POLKIT_HELPER=socket:/path` or `=/path/to/helper` picks the helper.
|
||||
Two parts, one process each:
|
||||
|
||||
- **`chandra-polkit-agent`** (`compositor/authagent`, installed in `/usr/local/lib/chandra/`)
|
||||
does everything polkit and PAM: it registers on the system bus as this login session's
|
||||
authentication agent (`RegisterAuthenticationAgent` for `XDG_SESSION_ID`), serves
|
||||
`BeginAuthentication` / `CancelAuthentication` at `/org/chandra/PolicyKit1/AuthenticationAgent`,
|
||||
runs polkit's `polkit-agent-helper-1` (polkit 126's `/run/polkit/agent-helper.socket`, else the
|
||||
setuid program), and keeps each request in **one state machine**
|
||||
(`compositor/polkit/machine.mbt`):
|
||||
|
||||
```
|
||||
Starting --PAM asks--> Asking --answer--> Checking --SUCCESS--> Done
|
||||
^ |
|
||||
+---- new check <----+ FAILURE (wrong password: counted, card shakes)
|
||||
Starting/Checking --check quits, can't start, ends without asking--> Failed --Try again--> Starting
|
||||
any --cancel--> Done
|
||||
```
|
||||
|
||||
It logs every step to stderr, which is the session log (never what was typed).
|
||||
- **The compositor** (`compositor/host/auth.mbt`, `auth_draw.mbt`) starts the agent on a socket
|
||||
pair (its stdin/stdout), draws the dialog from the state the agent sends, owns the keyboard
|
||||
and the pointer while it is up (`grab_input`: the dialog, else the Face unlock window, never
|
||||
both), and sends back the answer, the account picked, Try again, or Cancel. The link is a
|
||||
line protocol (`compositor/polkit/wire.mbt`); only the compositor holds the other end, so no
|
||||
other program can open the dialog or read what is typed into it.
|
||||
|
||||
### When it can't work, you are told
|
||||
|
||||
There is no silent fallback. A notice at the top of the screen (click to dismiss) and the session
|
||||
log say what happened:
|
||||
|
||||
- the agent program isn't installed or can't be run;
|
||||
- polkit refused the agent (say, another agent already has the session) or there is no system
|
||||
bus;
|
||||
- polkit hasn't answered within 10 seconds;
|
||||
- the agent stopped after it was running: it is started again (up to three times) and the notice
|
||||
says so.
|
||||
|
||||
Settings > Session > **Chandra password dialog** off is the only way another polkit agent runs
|
||||
(the first one `chandra-session` finds, passed as `CHANDRA_POLKIT_FALLBACK`); it is saved as
|
||||
state.edn `:auth-agent :system`. Turning it back on while that agent runs takes effect at the next
|
||||
login (polkit allows one agent per session), and the notice says so. `CHANDRA_POLKIT_AGENT=none`
|
||||
starts no agent; `=PATH` starts that agent instead. `CHANDRA_POLKIT_AGENT_BIN` points at another
|
||||
build of chandra-polkit-agent, and `CHANDRA_POLKIT_HELPER=socket:/path` or `=/path/to/helper`
|
||||
picks polkit's helper (both for debugging).
|
||||
|
||||
### Why it was rebuilt (2026-11-26)
|
||||
|
||||
The first version ran polkit, the helper, PAM and the drawing inside the compositor's frame loop,
|
||||
with overlapping state in two layers. A helper that quit before asking was taken for a wrong
|
||||
password and restarted in a tight loop that wiped the field, so typing seemed to do nothing; a
|
||||
refused registration quietly started another agent; the dialog and the Face unlock window each
|
||||
grabbed the keyboard. The split above gives one state machine, one input owner, and an explicit
|
||||
error for every failure.
|
||||
|
||||
## Tests
|
||||
|
||||
`compositor/polkit/polkit_test.mbt` (keymaps, helper lines, run0 parsing, descriptions, dialog
|
||||
states) and `compositor/host/auth_test.mbt`, which runs the agent against a mock polkit Authority
|
||||
on a private `dbus-daemon` and a mock helper on a socket. `CHANDRA_AUTH_SHOTS=/some/dir` writes a
|
||||
PNG of each dialog state. Not covered by tests: the real polkitd and PAM (registration for a real
|
||||
logind session, the real helper's socket and setuid paths).
|
||||
- `compositor/polkit/polkit_test.mbt`: keymaps, helper lines (and `Gone` when the helper quits),
|
||||
run0 parsing, descriptions, the link encoding, the state machine (wrong password, early quit,
|
||||
no retry until asked, face unlock, account picker) and the view (keys, Try again).
|
||||
- `compositor/host/auth_test.mbt`, end to end through `handle_input`: the agent loop in-process
|
||||
against a mock polkit Authority on a private `dbus-daemon` and a mock helper socket, and the
|
||||
**real agent program** spawned by the compositor (demo, and registered with the mock polkit
|
||||
through its own process). Covers typing on a real xkbcommon keymap, wrong password, cancel,
|
||||
polkit withdrawing a request, the helper quitting early, the helper missing, polkit refusing the
|
||||
agent, the agent not starting or crashing (notices), the demo modes, and Face unlock's Apply.
|
||||
`CHANDRA_AUTH_SHOTS=/some/dir` writes a PNG of each state. Build the agent first
|
||||
(`just auth-agent`), or the real-program test is skipped.
|
||||
- Not covered: a real polkitd and PAM (a real logind session, the real helper's socket and setuid
|
||||
paths). `run0 true` in the session is that test.
|
||||
+4
-3
@@ -82,11 +82,12 @@ the password in the terminal, as usual.
|
||||
|
||||
Started from a terminal, run0 asks there. Started from the launcher or a keyboard shortcut there is
|
||||
no terminal, so run0 and pkexec need a **polkit authentication agent** in the session. Chandra is
|
||||
its own: the compositor registers with polkit and asks in a dialog it draws itself, showing the
|
||||
command run0 will run (see [auth-dialog.md](auth-dialog.md)). Turn off Settings → Session →
|
||||
its own: the compositor starts chandra-polkit-agent and asks in a dialog it draws itself, showing
|
||||
the command run0 will run (see [auth-dialog.md](auth-dialog.md); `chandra-ctl auth-demo` shows it
|
||||
without root). If it can't start, a notice on screen says why. Turn off Settings → Session →
|
||||
"Chandra password dialog" to use a third-party agent instead; `chandra-session` finds the first one
|
||||
installed (polkit-gnome, mate-polkit, polkit-kde, hyprpolkitagent, xfce-polkit or lxpolkit) and
|
||||
the compositor starts it then, or whenever polkit won't take Chandra's agent. Set
|
||||
the compositor starts it then (only then). Set
|
||||
`CHANDRA_POLKIT_AGENT=/path/to/agent` to always use that agent, or `CHANDRA_POLKIT_AGENT=none` if
|
||||
a systemd user unit already starts one. Its output goes to the session log.
|
||||
|
||||
|
||||
Reference in new issue
Block a user