authoravatarclover caruso<git@paperclover.net>2026-11-16 21:52:29-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 00:44:02-08:00
log62fb5e2102b3da5f14e1c90a004b32f1f69089a6
tree3be71e27e2cb138a8c9ea20294664d90928657d0
parenta746c1188b774c0869822dd0dad345d919cbc037
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Refresh Fedora identity before accepting desktop operations

Configure autologin and refresh active identity services once per clone so GDM can load the personalized account. Probe systemd access before a Linux worker claims its request while guest permissions are still initializing. Assisted-by: gpt-6.1-sol

3 files changed, 27 insertions(+), 6 deletions(-)

guest/computer-linux.py+3
......@@ -17,6 +17,9 @@ if not re.fullmatch(r'snowglobe-computer-request-[0-9a-f]{32}', unit):
1717 raise ValueError('Invalid computer task.')
1818lease = '/run/snowglobe-computer-request'
1919if prepare or stop:
20 if prepare:
21 subprocess.run(['systemctl', 'show', 'systemd-user-sessions.service', '-p', 'ActiveState', '--value'],
22 check=True, capture_output=True, timeout=3)
2023 with os.fdopen(os.open(lease, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600), 'r+') as current:
2124 fcntl.flock(current, fcntl.LOCK_EX)
2225 if prepare or current.read() == unit:
tools/computer-test.py+11
......@@ -5,6 +5,7 @@ import base64
55import asyncio
66import time
77import json
8import io
89import tempfile
910import threading
1011import unittest
......@@ -419,6 +420,16 @@ class GuestCancellation(unittest.TestCase):
419420 self.assertNotIn('[ComputerProcess]::Stop', fallback.call_args.args[1])
420421 self.assertNotIn('$t.Stop(0)', fallback.call_args.args[1])
421422
423 def test_linux_prepare_does_not_claim_a_request_before_systemd_is_accessible(self):
424 source = (Path(__file__).resolve().parent.parent / 'guest/computer-linux.py').read_text()
425 request = io.StringIO(json.dumps({'_prepare':'snowglobe-computer-request-' + 'a' * 32}))
426 denied = computer.subprocess.CalledProcessError(1, 'systemctl', stderr=b'Access denied')
427 with patch.object(computer.sys, 'stdin', request), patch.object(computer.subprocess, 'run', side_effect=denied), \
428 patch.object(computer.os, 'open') as claim:
429 with self.assertRaises(computer.subprocess.CalledProcessError):
430 exec(compile(source, '<guest computer>', 'exec'), {'__name__':'__main__'})
431 claim.assert_not_called()
432
422433 def test_linux_stops_the_exact_request_unit_with_a_fresh_cleanup_budget(self):
423434 units = []
424435 def execute(name, executable, arguments, data=None, **kwargs):
tools/vms.py+13-6
......@@ -7,6 +7,7 @@ import os
77from pathlib import Path
88import re
99import secrets
10import shlex
1011import shutil
1112import signal
1213import stat
......@@ -695,7 +696,9 @@ def linux_seed(directory, username, os_name, serial="ttyS0"):
695696 fedora = "fedora" in os_name.lower()
696697 nixos = "nixos" in os_name.lower()
697698 account_tool = "/run/current-system/sw/bin/" if nixos else ""
698 rename = f'''set -eu
699 gdm_config = "/etc/gdm/custom.conf" if fedora or nixos else "/etc/gdm3/custom.conf"
700 gdm_content = f"[daemon]\nAutomaticLoginEnable=true\nAutomaticLogin={username}\n"
701 personalize = f'''set -eu
699702old=$({account_tool}getent passwd 1000 | cut -d: -f1)
700703test -n "$old"
701704if [ "$old" != {username} ]; then
......@@ -708,10 +711,13 @@ if [ "$old" != {username} ]; then
708711 if [ "$({account_tool}getent group 1000 | cut -d: -f1)" = "$old" ]; then {account_tool}groupmod -n {username} "$old"; fi
709712fi
710713'''
711 gdm_config = "/etc/gdm/custom.conf" if fedora or nixos else "/etc/gdm3/custom.conf"
712 files = [
713 {"path": gdm_config, "content": f"[daemon]\nAutomaticLoginEnable=true\nAutomaticLogin={username}\n"},
714 ]
714 if fedora:
715 personalize += "printf '%s' " + shlex.quote(gdm_content) + " > " + shlex.quote(gdm_config) + "\n"
716 personalize += '''for service in accounts-daemon.service display-manager.service; do
717 if systemctl is-active --quiet "$service"; then systemctl restart "$service"; fi
718done
719'''
720 files = [] if fedora else [{"path": gdm_config, "content": gdm_content}]
715721 if not nixos:
716722 files.insert(0, {"path": "/etc/ssh/sshd_config.d/00-snowglobe.conf", "permissions": "0600", "content": "PasswordAuthentication yes\nPermitRootLogin yes\n"})
717723 else:
......@@ -729,7 +735,8 @@ fi
729735 computer_setup = [["/run/current-system/sw/bin/bash", "-lc", "nix-env --profile /var/lib/snowglobe/computer -if /var/lib/snowglobe/computer.nix"]]
730736 config = {
731737 "users": [], "disable_root": False, "ssh_pwauth": True, "ssh_deletekeys": True,
732 "bootcmd": ([["rm", "-f", gdm_config]] if nixos else []) + [["sh", "-c", rename]],
738 "bootcmd": ([["rm", "-f", gdm_config]] if nixos else []) + [
739 (["cloud-init-per", "instance", "snowglobe-desktop"] if fedora else []) + ["sh", "-c", personalize]],
733740 "chpasswd": {"expire": False, "users": [{"name": user, "password": hashed, "type": "hash"} for user in [username, "root"]]},
734741 "write_files": files,
735742 "runcmd": [["systemctl", "enable", "--now", "sshd" if fedora or nixos else "ssh"], ["systemctl", "enable", "--now", f"serial-getty@{serial}.service"]] + computer_setup,