sector-f-linux

Sector F Linux
git clone https://git.sectorflabs.com/sector-f-linux.git
Log | Files | Refs | README | LICENSE

commit 64112aa7fea60507f2934484e9b840d1e65d4766
parent 0fff7219315048f53c044d770475e8a34a2a356e
Author: Divan Visagie <me@divanv.com>
Date:   Sat, 28 Nov 2026 00:38:35 +0100

polkit: let the greeter set the time zone during the first run (ADR-0019)

What: the polkit rule that lets the greeter administer accounts on a fresh machine now also lets it
call timedated's SetTimezone (org.freedesktop.timedate1.set-timezone). Nothing else is added: not
the NTP setting, not the host name (those come with their own steps).

Why it is shaped this way: the account rule only holds while no human account can log in (none
exists, or all are still locked). Every other change the setup makes has to be made inside that same
window, so the check became one function, noHumanCanLogIn(), that the account action and the new one
share, and any doubt (a failing spawn, say) still closes it. Only the user "greetd" is covered.

Tested, not assumed: greeter/tests/first-run-rules.js runs the rules file against a stand-in for
polkit and checks eight cases (fresh machine: account and zone allowed; an account that can log in:
refused; an account still locked: allowed; a failing check: refused; another user: refused; the host
name and NTP actions: refused). It runs in `make test` when node is installed. A stub of mine had the
wrong argument position for busctl at first, which showed as a failing "locked" case; fixed in the
stub, not the rule.

The greeter side that uses this follows in the next commit.

Diffstat:
Mgreeter/Makefile | 3++-
Agreeter/tests/first-run-rules.js | 52++++++++++++++++++++++++++++++++++++++++++++++++++++
Mlinux/system/usr/share/polkit-1/rules.d/50-patina-first-user.rules | 29++++++++++++++++++++---------
3 files changed, 74 insertions(+), 10 deletions(-)

diff --git a/greeter/Makefile b/greeter/Makefile @@ -23,8 +23,9 @@ run-setup: ## Run the first-run setup on the mock, in a window build: ## Build a release binary cargo build --release -test: ## Run the tests +test: ## Run the tests (and the first-run polkit rules against a stand-in for polkit, if node is there) cargo test + @if command -v node >/dev/null 2>&1; then node tests/first-run-rules.js; else echo "node is not installed: the polkit rules were not tested"; fi check: test ## Run the tests and clippy, as before a commit cargo clippy --all-targets -- -D warnings diff --git a/greeter/tests/first-run-rules.js b/greeter/tests/first-run-rules.js @@ -0,0 +1,52 @@ +// Runs the polkit rules for the first run (linux/system/usr/share/polkit-1/rules.d/50-patina-first-user.rules) +// against a stand-in for polkit, to check who may do what and when. Usage: node tests/first-run-rules.js +const fs = require("fs"); +const path = require("path"); +const file = path.join(__dirname, "../../linux/system/usr/share/polkit-1/rules.d/50-patina-first-user.rules"); +const source = fs.readFileSync(file, "utf8"); + +// `passwd` is the output of getent; `locked` says, per uid, what busctl would print for Locked. +function decide({ user, action, passwd, locked = {}, spawnFails = false }) { + let rule; + const polkit = { + Result: { YES: "YES", NO: "NO" }, + addRule(f) { rule = f; }, + spawn(argv) { + if (spawnFails) throw new Error("spawn failed"); + if (argv[0].endsWith("getent")) return passwd; + if (argv[0].endsWith("busctl")) { + const uid = argv[4].split("User").pop(); + return locked[uid] ? "b true\n" : "b false\n"; + } + throw new Error("unexpected " + argv.join(" ")); + }, + }; + new Function("polkit", source)(polkit); + return rule({ id: action }, { user }); +} + +const NONE = "root:x:0:0::/root:/bin/bash\ngreetd:x:972:972::/var/lib/greetd:/sbin/nologin\nnobody:x:65534:65534::/:/sbin/nologin\n"; +const ALICE = NONE + "alice:x:1000:1000:Alice:/var/home/alice:/bin/bash\n"; +const ADMIN = "org.freedesktop.accounts.user-administration"; +const ZONE = "org.freedesktop.timedate1.set-timezone"; + +const cases = [ + ["greetd may administer accounts on a fresh machine", { user: "greetd", action: ADMIN, passwd: NONE }, "YES"], + ["greetd may set the time zone on a fresh machine", { user: "greetd", action: ZONE, passwd: NONE }, "YES"], + ["not once an account can log in", { user: "greetd", action: ZONE, passwd: ALICE, locked: { 1000: false } }, undefined], + ["still while the only account is locked (no password yet)", { user: "greetd", action: ZONE, passwd: ALICE, locked: { 1000: true } }, "YES"], + ["a failing check closes the window", { user: "greetd", action: ZONE, passwd: NONE, spawnFails: true }, undefined], + ["nobody else gets it, even on a fresh machine", { user: "divan", action: ZONE, passwd: NONE }, undefined], + ["greetd gets nothing else (the host name)", { user: "greetd", action: "org.freedesktop.hostname1.set-static-hostname", passwd: NONE }, undefined], + ["nor the clock's NTP setting", { user: "greetd", action: "org.freedesktop.timedate1.set-ntp", passwd: NONE }, undefined], +]; + +let failed = 0; +for (const [name, input, want] of cases) { + const got = decide(input); + const ok = got === want; + if (!ok) failed++; + console.log((ok ? "ok " : "FAIL ") + name + (ok ? "" : ` (wanted ${want}, got ${got})`)); +} +if (failed) { console.log(failed + " failed"); process.exit(1); } +console.log("the first-run rules do what they should"); diff --git a/linux/system/usr/share/polkit-1/rules.d/50-patina-first-user.rules b/linux/system/usr/share/polkit-1/rules.d/50-patina-first-user.rules @@ -1,12 +1,12 @@ -// The greeter may administer accounts, which is what makes the first one, only while no human account -// can log in: none exists (uid 1000 up, with a shell), or the ones that do are all still locked. That -// is what keeps the window open for the password and for taking the account back out if that fails, -// and closes it the moment a password is set. ADR-0012's alternative to a helper of our own. +// The greeter may change a few things on a machine fresh from the install: administer accounts, which +// is what makes the first one (ADR-0012), and set the time zone (ADR-0019, the setup's clock step). +// Only while no human account can log in: none exists (uid 1000 up, with a shell), or the ones that +// do are all still locked. That is what keeps the window open for the password and for taking the +// account back out if that fails, and closes it the moment a password is set. ADR-0012's alternative +// to a helper of our own. // // Any doubt closes it: if a check fails, the account counts as able to log in. -polkit.addRule(function(action, subject) { - if (subject.user !== "greetd") return; - if (action.id !== "org.freedesktop.accounts.user-administration") return; +function noHumanCanLogIn() { try { var humans = polkit.spawn(["/usr/bin/getent", "passwd"]).split("\n") .map(function(line) { return line.split(":"); }) @@ -20,8 +20,19 @@ polkit.addRule(function(action, subject) { "org.freedesktop.Accounts.User", "Locked"]); return locked.indexOf("true") === -1; }); - if (canLogIn.length === 0) return polkit.Result.YES; + return canLogIn.length === 0; } catch (e) { - return; + return false; } +} + +var firstRunActions = [ + "org.freedesktop.accounts.user-administration", + "org.freedesktop.timedate1.set-timezone" +]; + +polkit.addRule(function(action, subject) { + if (subject.user !== "greetd") return; + if (firstRunActions.indexOf(action.id) === -1) return; + if (noHumanCanLogIn()) return polkit.Result.YES; });