commit aba36e51fff91f1ca461fb1cf38c235a17dc3ed8
parent 10bae84022e200de14ea9dc941edc1a41a15f1c3
Author: Divan Visagie <me@divanv.com>
Date: Fri, 20 Nov 2026 23:51:16 +0100
ADR-0012 (proposed), a login manager of our own: greetd and a Patina greeter; the prototype
The login screen becomes the setup: greetd does the privileged work (PAM, logind sessions, the seat), a Patina greeter, in this repository and not in patina-desktop, runs as an unprivileged user in a kiosk compositor, and shows the setup when no human account exists, or the login screen when one does. A small root helper, socket-activated, makes the first account and refuses once one exists. GDM, gnome-shell and the GDM theme work go. ADR-0011's open question about a no-user session points here.
linux/prototype/ is the throwaway code that proved it on a VM installed from the published image, with greetd, gtkgreet and cage layered on: the helper (checked from the greeter user: bad input and callers outside the group refused, one account for two and for three simultaneous requests) and a scripted greeter that, with no account, had the helper make one and then logged it into the Patina session through greetd.
Recorded in the ADR: it works only with SELinux permissive; enforcing denies the greeter (xdm_t) the helper's socket and AccountsService a look at the caller, so the helper needs a policy of its own, and writing it needs auditd, which the image lacks. Also greetd's tmpfiles rule never creates /var/lib/greetd, a uid reused right after a delete raced once, and /usr/local is read-only.
Diffstat:
7 files changed, 360 insertions(+), 4 deletions(-)
diff --git a/docs/adr/0011-the-first-boot-is-the-installer.md b/docs/adr/0011-the-first-boot-is-the-installer.md
@@ -4,7 +4,9 @@ Date: 2026-11-20
## Status
-Proposed. The user's direction: a machine should be set up the way a Mac is. The system is put on a
+Proposed, and its no-user-session question is answered in
+[ADR-0012](0012-a-login-manager-of-our-own-greetd-and-a-patina-greeter.md): the setup runs in the login
+screen itself, a Patina greeter on greetd. The user's direction: a machine should be set up the way a Mac is. The system is put on a
drive and expanded, and the first boot, when no user exists, runs a setup built into Patina. Amends
[ADR-0010](0010-a-live-installer-built-from-the-image.md): the live installer stays, but its job
shrinks to choosing a drive. Nothing here has been built; "to verify" marks what has not been
@@ -68,9 +70,8 @@ restored: how ostree stores local `/etc` changes has not been looked at).
- **Does the installed system boot from the chosen drive on a real, multi-drive desktop?**
`bootc` writes the bootloader to that drive's EFI partition. Whether it also registers a
firmware boot entry, which a machine with a Windows drive or two may need, is unchecked.
-- **A no-user session for the setup.** Patina's compositor needs a setup mode, run by GDM or by a
- greeter of our own, as an unprivileged account, the way `gnome-initial-setup` runs. How, and
- whether GDM's own initial-setup support can be used, is to look at.
+- **A no-user session for the setup.** Settled in ADR-0012: the login screen is a Patina greeter on
+ greetd, with the setup as its first-run mode and a small helper that makes the first account.
- **Encryption.** It cannot be in a shared image. Creating the encrypted storage at first boot with
a key made on that machine (`systemd-repart` can, with the TPM or a passphrase), or an encrypted
home per user (`systemd-homed`), are options; neither has been tried on this stack.
diff --git a/docs/adr/0012-a-login-manager-of-our-own-greetd-and-a-patina-greeter.md b/docs/adr/0012-a-login-manager-of-our-own-greetd-and-a-patina-greeter.md
@@ -0,0 +1,136 @@
+# 0012. A login manager of our own: greetd, and a Patina greeter with the setup built in
+
+Date: 2026-11-20
+
+## Status
+
+Proposed. The user's idea: since there is no user on a fresh machine, the login screen should be
+where the setup happens, and once the account exists it becomes the ordinary login screen. This
+answers the question [ADR-0011](0011-the-first-boot-is-the-installer.md) left open, how to run
+the setup with no user. Nothing here is built beyond the prototype noted at the end; "to verify"
+marks what has not been looked at.
+
+## Context
+
+[ADR-0011](0011-the-first-boot-is-the-installer.md) wants the first boot to be the installer: with
+no user, a Patina setup assistant creates the account, and a factory reset returns to it. GDM, the
+login manager the image has now, has no such mode: with no users it shows a bare "Username" box (seen
+on 2026-11-20), and it brings GNOME Shell and a GNOME session entry with it, which the image only
+carries for GDM's sake. Its look is ours only through a patched GNOME Shell theme resource and a
+dconf setting (ADR-0009, `linux/branding/gdm-theme.py`).
+
+An experiment on a VM installed from the published image, which has no accounts, showed the
+account step is plumbing that works. AccountsService's `CreateUser` over D-Bus, as root and without
+GNOME tools, made an administrator with a home on Btrfs in `/var/home`; `SetPassword` took a hash;
+and the user template (`Session=patina`) applied to the new account, so a login started the Patina
+session. What is missing is a place to run the setup before any account exists.
+
+What is available:
+- **greetd** 0.10.3, `cage` (a kiosk Wayland compositor) and `gtkgreet` 0.8 are in Fedora 45.
+ `greetd-tuigreet` and `regreet` are not.
+- **greetd** does the privileged part: PAM, logind sessions, the seat, starting the user's session.
+ A greeter is any program that talks to it over a socket (JSON, a length prefix, the path in
+ `$GREETD_SOCK`), run as an unprivileged user.
+- **patina-desktop** has the lock screen (`lock/`: a Patina password interface over PAM, whose PAM
+ half a greeter does not need, as greetd authenticates), user pictures (`system/src/avatar.rs`,
+ ADR-0104), `patina-session`, and the login profile (ADR-0083). It has no greeter.
+
+## Decision (proposed)
+
+- **greetd is the login daemon.** We write the greeter, not the privileged code: no PAM or session
+ handling of our own.
+- **A Patina greeter app** (egui, like Files and Settings) runs as the greeter user inside a kiosk
+ compositor: `cage` to start, the Patina compositor in a kiosk mode later. It has two modes:
+ - **Login:** the users, their pictures, a password, the power menu; an `initial_session` for the
+ live disc's `liveuser`, and for a first login straight after the setup.
+ - **First run**, when there is no human account (uid 1000 or above; to verify how best to tell):
+ the setup of ADR-0011, with the account first.
+- **Both live in this repository (patina-os), not in patina-desktop:** the greeter and the helper are
+ OS code, what logs in, and not part of the desktop session. Where the greeter wants Patina's
+ interface pieces it depends on the Patina libraries or copies what the lock screen does; it
+ does not change patina-desktop.
+- **An account helper**, a small root service that only makes the first user. It is socket-activated,
+ listens on a Unix socket only the greeter user can reach, checks the name and the other fields,
+ refuses once any human account exists (and under a lock, so two requests cannot both succeed),
+ and makes the account through AccountsService as in the experiment. It is a helper and not a
+ polkit rule because a rule has to express "only while no users exist" in policy, and the helper
+ can be read in one sitting. The greeter stays unprivileged.
+- **After the account exists,** the greeter logs it straight into the session through greetd, with
+ the password it was just given, as on a Mac, and from then on shows the login mode.
+- **GDM goes.** With it, gnome-shell, the GNOME session entry, `linux/branding/gdm-theme.py` and
+ its build stage, and the dconf logo setting. The greeter is Patina's, so the Everforest skin and
+ the logo are native, not patched in.
+
+## Known gaps against GDM
+
+Accessibility (a screen reader, an on-screen keyboard for touch), multi-seat, fast user switching,
+and fingerprint login: the PAM side works through greetd, but the greeter has to show PAM's
+prompts ("place your finger") and handle a conversation with more than one step. These are
+accepted for now.
+
+## Open questions
+
+- Which kiosk compositor, and whether Patina's compositor can run as a greeter session for a
+ user with no account of their own (it uses libseat, so logind should do).
+- How the helper knows nobody is already set up, and what happens if the setup is interrupted
+ half way.
+- HiDPI and several monitors on the greeter, and the cursor.
+- Joining the tailnet, and the encryption of ADR-0011, as setup steps.
+- Whether greetd's own PAM service (`greetd`) needs more than Fedora's default for the fingerprint
+ reader and the lock screen's `patina-lock` service to agree.
+
+## Order of work
+
+1. **A prototype on the VM** (done, see above): layer greetd, `gtkgreet` and `cage`, replace GDM, and
+ drive greetd by script as the greeter user: no account, the helper makes the first, and greetd
+ starts that user's Patina session. The SELinux policy for the helper is still to do.
+2. The greeter app, in login mode.
+3. The first-run mode, on top of the helper.
+4. Remove GDM, gnome-shell, the theme stage and the dconf logo setting from the image.
+5. The gaps above, as they matter.
+
+## Prototype (2026-11-20)
+
+Done on the VM installed from the published image, with greetd, `gtkgreet` and `cage` layered on with
+`rpm-ostree install` (22 packages with their dependencies, and the layering survived the reboot).
+The code is in `linux/prototype/`.
+
+Verified:
+- **greetd hosts a greeter on this image.** With GDM disabled, greetd runs `cage` and `gtkgreet` as
+ the unprivileged `greetd` user, and its PAM services (`greetd`, `greetd-greeter`) are there.
+- **The account helper does what the decision says.** From the greeter user, a bad name and a bad
+ request are refused, a caller outside the greeter's group cannot connect, the first request makes
+ the account, and a second is refused with "already set up". Two simultaneous requests gave exactly
+ one account, and so did three after a pause: the lock works.
+- **The whole flow works.** A scripted greeter (`proto-greeter`, speaking greetd's protocol) found no
+ human account, asked the helper for one, logged it in through greetd with the password just
+ given, and greetd started its Patina session on tty1: the compositor, the hud pieces and the rest
+ ran as the new user, and the screen showed the desktop. Run with SELinux permissive (below).
+
+Not working yet, and found:
+- **SELinux blocks it when enforcing.** The greeter runs in `xdm_t` and is denied write on the
+ helper's socket, labeled `var_run_t`; AccountsService (`accountsd_t`) is denied search on a
+ directory of the helper's, probably to look at the caller. The helper needs a policy of its own: a
+ type for the process and one for its socket, allowing `xdm_t` to reach the socket, and
+ AccountsService to look at the caller. Writing it needs the full list of denials, and this image
+ cannot give one: it has no `auditd` or `ausearch`, and the kernel rate-limits the audit messages
+ it prints (158 suppressed in one run), so `auditd` has to be added before the policy can be
+ written. An earlier "no denials" check of mine used `ausearch`, which is not on the image, and
+ meant nothing; the kernel log is where the real denial was.
+- **`/var/lib/greetd` is never created.** greetd's tmpfiles rule is `Z`, which only fixes the
+ ownership of what exists, so the greeter starts with "unable to set working directory". The image
+ needs its own `d` entry.
+- **uid reuse is racy.** Deleting an account and creating another at once reused uid 1000, and the
+ password could not be set on the AccountsService object that was still going away. It did not
+ recur after a pause. It matters for a factory reset (ADR-0011), where users are removed and made again.
+- **`/usr/local` is read-only**, so the helper belongs in `/usr/libexec`, shipped in the image.
+
+## Consequences
+
+- The login screen and the setup are one thing, in Patina's own look, and a factory reset
+ (ADR-0011) reuses it.
+- The image gets smaller and simpler without GNOME Shell, and the "a GNOME session shows at the
+ chooser" loose end disappears.
+- We take on the greeter's quality: it is the first thing a user sees and where a bug locks them out.
+ greetd keeps the security-critical code out of it, but the interface and its first-run logic
+ are ours, as is a recovery path when something is wrong (a text console login stays available).
diff --git a/linux/prototype/README.md b/linux/prototype/README.md
@@ -0,0 +1,21 @@
+# Prototype: the login manager of ADR-0012
+
+Throwaway code that proved the architecture on a VM. Nothing here ships. The real greeter and helper
+will be written in this repository (not in patina-desktop), the helper as a Rust service shipped in
+the image with an SELinux policy of its own.
+
+- `patina-setupd`: the account helper. Socket-activated, one JSON request in, one reply out; makes
+ the first user through AccountsService and refuses once any human account exists, under a lock.
+- `patina-setup.socket`, `patina-setup@.service`: its units. The socket is root:greetd, mode 0660.
+- `proto-greeter`: a scripted stand-in for the greeter. With no human account it asks the helper for
+ one, then logs that account in through greetd's protocol and starts `patina-session --session`.
+
+## Trying it on the test VM
+
+The VM's `/usr` is read-only: make it writable for one boot with `bootc usroverlay`, and put the two
+scripts in `/usr/libexec` (`restorecon` them). The units go in `/etc/systemd/system`. greetd,
+`gtkgreet` and `cage` come from `rpm-ostree install`; GDM is disabled and greetd enabled. Set
+`/etc/greetd/config.toml`'s `default_session.command` to `/usr/libexec/proto-greeter`.
+
+SELinux, enforcing, blocks the greeter from the helper's socket: see the ADR's prototype section.
+`setenforce 0` shows the flow working.
diff --git a/linux/prototype/patina-setup.socket b/linux/prototype/patina-setup.socket
@@ -0,0 +1,13 @@
+[Unit]
+Description=Patina first-account helper (socket)
+
+[Socket]
+ListenStream=/run/patina-setup.sock
+SocketMode=0660
+SocketUser=root
+SocketGroup=greetd
+Accept=yes
+MaxConnections=4
+
+[Install]
+WantedBy=sockets.target
diff --git a/linux/prototype/patina-setup@.service b/linux/prototype/patina-setup@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Patina first-account helper
+
+[Service]
+ExecStart=/usr/libexec/patina-setupd
+StandardInput=socket
+StandardOutput=socket
+StandardError=journal
+NoNewPrivileges=yes
+PrivateTmp=yes
+TimeoutStartSec=30
diff --git a/linux/prototype/patina-setupd b/linux/prototype/patina-setupd
@@ -0,0 +1,86 @@
+#!/usr/bin/python3
+"""The account helper of ADR-0012, as a prototype: makes the first user, once.
+
+Socket-activated (patina-setup.socket, Accept=yes), so each connection runs this once: one JSON
+line in on stdin, one JSON line out on stdout. The socket is reachable only by root and the greeter's
+group. It refuses once any human account exists, under a lock so two requests cannot both succeed,
+and makes the account through AccountsService (D-Bus), as the experiment did.
+
+ request: {"username": "alice", "fullname": "Alice Example", "password": "..."}
+ reply: {"ok": true, "username": "alice"} or {"ok": false, "error": "..."}
+"""
+import fcntl
+import json
+import pwd
+import re
+import subprocess
+import sys
+
+LOCK = "/run/patina-setup.lock"
+BUS = ["busctl", "--system", "call", "org.freedesktop.Accounts"]
+
+
+def reply(ok, **fields):
+ sys.stdout.write(json.dumps({"ok": ok, **fields}) + "\n")
+ sys.stdout.flush()
+ sys.exit(0)
+
+
+def humans():
+ """Accounts a person could log in as: uid 1000 and up, with a shell."""
+ return [p.pw_name for p in pwd.getpwall()
+ if 1000 <= p.pw_uid < 60000 and not p.pw_shell.endswith(("nologin", "false"))]
+
+
+def log(*a):
+ print("patina-setupd:", *a, file=sys.stderr, flush=True) # goes to the journal; never the password
+
+
+def call(path, iface, method, sig, *args):
+ r = subprocess.run(BUS[:3] + [BUS[3], path, iface, method, sig, *map(str, args)],
+ capture_output=True, text=True)
+ if r.returncode:
+ log(method, "failed:", r.stderr.strip()[:200])
+ return r
+
+
+line = sys.stdin.buffer.readline(4096) # bounded: one request
+try:
+ req = json.loads(line)
+ name, full, password = req["username"], req["fullname"], req["password"]
+ assert all(isinstance(x, str) for x in (name, full, password))
+except Exception:
+ reply(False, error="bad request")
+
+if not re.fullmatch(r"[a-z][a-z0-9_-]{0,30}", name):
+ reply(False, error="the user name must be lower case letters, digits, - and _, starting with a letter")
+if not (1 <= len(full) <= 64) or re.search(r"[:\x00-\x1f\x7f]", full):
+ reply(False, error="bad full name")
+if not (1 <= len(password) <= 256) or "\n" in password:
+ reply(False, error="bad password")
+
+with open(LOCK, "w") as lock:
+ fcntl.flock(lock, fcntl.LOCK_EX) # a second request waits here, then finds the account made
+ if humans():
+ log("refused: already set up", humans())
+ reply(False, error="already set up")
+ try:
+ pwd.getpwnam(name)
+ reply(False, error="that name is taken")
+ except KeyError:
+ pass
+
+ made = call("/org/freedesktop/Accounts", "org.freedesktop.Accounts", "CreateUser", "ssi", name, full, 1)
+ if made.returncode:
+ reply(False, error="could not create the account")
+ uid = pwd.getpwnam(name).pw_uid
+ path = f"/org/freedesktop/Accounts/User{uid}"
+ crypted = subprocess.run(["openssl", "passwd", "-6", "-stdin"], input=password + "\n",
+ capture_output=True, text=True).stdout.strip()
+ ok = crypted.startswith("$6$") and not call(path, "org.freedesktop.Accounts.User", "SetPassword",
+ "ss", crypted, "").returncode
+ if not ok: # leave the machine as it was: still with no user
+ log("rolling back", name, "uid", uid)
+ call("/org/freedesktop/Accounts", "org.freedesktop.Accounts", "DeleteUser", "xb", uid, "true")
+ reply(False, error="could not set the password")
+ reply(True, username=name)
diff --git a/linux/prototype/proto-greeter b/linux/prototype/proto-greeter
@@ -0,0 +1,88 @@
+#!/usr/bin/python3
+"""A scripted stand-in for the Patina greeter (ADR-0012), to prove the architecture before any interface.
+
+greetd runs this as the greeter user. With no human account it asks the account helper
+(patina-setupd) to make the first one; then it logs that account in through greetd's protocol
+and starts the Patina session, which is what the real greeter does after its setup screen.
+Messages to and from greetd are a 4 byte native-endian length and a JSON body, over $GREETD_SOCK.
+"""
+import json
+import os
+import pwd
+import socket
+import struct
+import sys
+
+USER, FULL, PASSWORD = "erin", "Erin Prototype", "sectorf-proto"
+
+
+def log(*a):
+ print("proto-greeter:", *a, file=sys.stderr, flush=True)
+
+
+def humans():
+ return [p.pw_name for p in pwd.getpwall()
+ if 1000 <= p.pw_uid < 60000 and not p.pw_shell.endswith(("nologin", "false"))]
+
+
+def talk(sock_path, obj, framed):
+ s = socket.socket(socket.AF_UNIX)
+ s.connect(sock_path)
+ return s
+
+
+def send(s, msg):
+ body = json.dumps(msg).encode()
+ s.sendall(struct.pack("=I", len(body)) + body)
+
+
+def recvn(s, n):
+ buf = b""
+ while len(buf) < n:
+ chunk = s.recv(n - len(buf))
+ if not chunk:
+ raise EOFError("greetd closed the socket")
+ buf += chunk
+ return buf
+
+
+def recv(s):
+ (n,) = struct.unpack("=I", recvn(s, 4))
+ return json.loads(recvn(s, n))
+
+
+# 1. First run: no one can log in, so ask the helper for the first account.
+if not humans():
+ log("no human account: first-run setup")
+ h = socket.socket(socket.AF_UNIX)
+ h.settimeout(30)
+ h.connect("/run/patina-setup.sock")
+ h.sendall((json.dumps({"username": USER, "fullname": FULL, "password": PASSWORD}) + "\n").encode())
+ h.shutdown(socket.SHUT_WR)
+ answer = json.loads(h.makefile().readline())
+ log("helper says:", {k: v for k, v in answer.items() if k != "password"})
+ if not answer.get("ok"):
+ sys.exit(1)
+else:
+ log("accounts exist:", humans())
+
+# 2. Log that account in through greetd, with the password just given.
+g = socket.socket(socket.AF_UNIX)
+g.connect(os.environ["GREETD_SOCK"])
+send(g, {"type": "create_session", "username": USER})
+r = recv(g)
+while r["type"] == "auth_message":
+ log("greetd asks:", r["auth_message_type"], repr(r["auth_message"]))
+ secret = r["auth_message_type"] == "secret"
+ send(g, {"type": "post_auth_message_response", "response": PASSWORD if secret else None})
+ r = recv(g)
+if r["type"] != "success":
+ log("login refused:", r)
+ send(g, {"type": "cancel_session"})
+ sys.exit(1)
+
+# 3. Start the Patina session, and leave: greetd takes it from here.
+send(g, {"type": "start_session", "cmd": ["patina-session", "--session"], "env": []})
+r = recv(g)
+log("start_session:", r)
+sys.exit(0 if r["type"] == "success" else 1)