Files
chandra/docs/auth-dialog.md
T
Claude 0feea23a06
CI / test (push) Failing after 18s
Password dialog: Chandra is its own polkit agent, drawn in the shell layer
run0, pkexec and other polkit prompts used whatever third-party agent was
installed: a plain toolkit window saying "start transient unit
'run-p15802-i1990.service'". The compositor now registers as the session's
polkit authentication agent and asks in its own dialog:

- a centered card over a dimmed screen, above all windows and client menus,
  themed (dark/light follow the Dark mode switch), keyboard-first: Enter,
  Esc, Tab order, Alt+R show/hide, Alt+D details, Ctrl+U clear
- for run0 it shows the command it will run ("gparted /dev/sda", as root)
  from run0's command line (pid from polkit's details or the unit name),
  pkexec's command from its details, polkit's message otherwise; Details
  lists the requester, target user, unit and action id
- account picker when several admins can answer (group members expanded)
- the PAM conversation through polkit-agent-helper-1: polkit 126's socket
  first, else the setuid helper on a socket pair (new sys spawn-socket on the
  native, Rust and MoonBit hosts); password, echo-on prompts, info (fingerprint)
  and errors (faillock) shown as they come; wrong password shakes and retries;
  spinner while PAM checks; Caps Lock warning
- typing through the clients' xkb keymap (groups, Shift, AltGr, Caps Lock),
  US layout when there is none
- no client has keyboard focus or input while it is up; the password is
  wiped after sending and never logged

Settings > Session > "Chandra password dialog" (state.edn :auth-agent
:system when off) switches back to the third-party agent, which
chandra-session now finds and the compositor starts (also when polkit
refuses our agent). Tests: polkit_test (keymaps, helper protocol, run0
parsing, dialog states, the socket-pair route) and auth_test (mock polkit
Authority on a private dbus-daemon, mock helper; CHANDRA_AUTH_SHOTS writes
a PNG per state). Docs: docs/auth-dialog.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
2026-11-26 00:17:04 +00:00

4.2 KiB

The password dialog (polkit agent)

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.

  • 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.
  • 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. While PAM checks, the field is locked and a spinner shows.
  • 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.

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.

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).