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):...@@ -17,6 +17,9 @@ if not re.fullmatch(r'snowglobe-computer-request-[0-9a-f]{32}', unit):
17 raise ValueError('Invalid computer task.')17 raise ValueError('Invalid computer task.')
18lease = '/run/snowglobe-computer-request'18lease = '/run/snowglobe-computer-request'
19if prepare or stop:19if 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)
20 with os.fdopen(os.open(lease, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600), 'r+') as current:23 with os.fdopen(os.open(lease, os.O_CREAT | os.O_RDWR | os.O_NOFOLLOW, 0o600), 'r+') as current:
21 fcntl.flock(current, fcntl.LOCK_EX)24 fcntl.flock(current, fcntl.LOCK_EX)
22 if prepare or current.read() == unit:25 if prepare or current.read() == unit:
tools/computer-test.py+11
...@@ -5,6 +5,7 @@ import base64...@@ -5,6 +5,7 @@ import base64
5import asyncio5import asyncio
6import time6import time
7import json7import json
8import io
8import tempfile9import tempfile
9import threading10import threading
10import unittest11import unittest
...@@ -419,6 +420,16 @@ class GuestCancellation(unittest.TestCase):...@@ -419,6 +420,16 @@ class GuestCancellation(unittest.TestCase):
419 self.assertNotIn('[ComputerProcess]::Stop', fallback.call_args.args[1])420 self.assertNotIn('[ComputerProcess]::Stop', fallback.call_args.args[1])
420 self.assertNotIn('$t.Stop(0)', fallback.call_args.args[1])421 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
422 def test_linux_stops_the_exact_request_unit_with_a_fresh_cleanup_budget(self):433 def test_linux_stops_the_exact_request_unit_with_a_fresh_cleanup_budget(self):
423 units = []434 units = []
424 def execute(name, executable, arguments, data=None, **kwargs):435 def execute(name, executable, arguments, data=None, **kwargs):
tools/vms.py+13-6
...@@ -7,6 +7,7 @@ import os...@@ -7,6 +7,7 @@ import os
7from pathlib import Path7from pathlib import Path
8import re8import re
9import secrets9import secrets
10import shlex
10import shutil11import shutil
11import signal12import signal
12import stat13import stat
...@@ -695,7 +696,9 @@ def linux_seed(directory, username, os_name, serial="ttyS0"):...@@ -695,7 +696,9 @@ def linux_seed(directory, username, os_name, serial="ttyS0"):
695 fedora = "fedora" in os_name.lower()696 fedora = "fedora" in os_name.lower()
696 nixos = "nixos" in os_name.lower()697 nixos = "nixos" in os_name.lower()
697 account_tool = "/run/current-system/sw/bin/" if nixos else ""698 account_tool = "/run/current-system/sw/bin/" if nixos else ""
698 rename = f'''set -eu699 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
699old=$({account_tool}getent passwd 1000 | cut -d: -f1)702old=$({account_tool}getent passwd 1000 | cut -d: -f1)
700test -n "$old"703test -n "$old"
701if [ "$old" != {username} ]; then704if [ "$old" != {username} ]; then
...@@ -708,10 +711,13 @@ if [ "$old" != {username} ]; then...@@ -708,10 +711,13 @@ if [ "$old" != {username} ]; then
708 if [ "$({account_tool}getent group 1000 | cut -d: -f1)" = "$old" ]; then {account_tool}groupmod -n {username} "$old"; fi711 if [ "$({account_tool}getent group 1000 | cut -d: -f1)" = "$old" ]; then {account_tool}groupmod -n {username} "$old"; fi
709fi712fi
710'''713'''
711 gdm_config = "/etc/gdm/custom.conf" if fedora or nixos else "/etc/gdm3/custom.conf"714 if fedora:
712 files = [715 personalize += "printf '%s' " + shlex.quote(gdm_content) + " > " + shlex.quote(gdm_config) + "\n"
713 {"path": gdm_config, "content": f"[daemon]\nAutomaticLoginEnable=true\nAutomaticLogin={username}\n"},716 personalize += '''for service in accounts-daemon.service display-manager.service; do
714 ]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}]
715 if not nixos:721 if not nixos:
716 files.insert(0, {"path": "/etc/ssh/sshd_config.d/00-snowglobe.conf", "permissions": "0600", "content": "PasswordAuthentication yes\nPermitRootLogin yes\n"})722 files.insert(0, {"path": "/etc/ssh/sshd_config.d/00-snowglobe.conf", "permissions": "0600", "content": "PasswordAuthentication yes\nPermitRootLogin yes\n"})
717 else:723 else:
...@@ -729,7 +735,8 @@ fi...@@ -729,7 +735,8 @@ fi
729 computer_setup = [["/run/current-system/sw/bin/bash", "-lc", "nix-env --profile /var/lib/snowglobe/computer -if /var/lib/snowglobe/computer.nix"]]735 computer_setup = [["/run/current-system/sw/bin/bash", "-lc", "nix-env --profile /var/lib/snowglobe/computer -if /var/lib/snowglobe/computer.nix"]]
730 config = {736 config = {
731 "users": [], "disable_root": False, "ssh_pwauth": True, "ssh_deletekeys": True,737 "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]],
733 "chpasswd": {"expire": False, "users": [{"name": user, "password": hashed, "type": "hash"} for user in [username, "root"]]},740 "chpasswd": {"expire": False, "users": [{"name": user, "password": hashed, "type": "hash"} for user in [username, "root"]]},
734 "write_files": files,741 "write_files": files,
735 "runcmd": [["systemctl", "enable", "--now", "sshd" if fedora or nixos else "ssh"], ["systemctl", "enable", "--now", f"serial-getty@{serial}.service"]] + computer_setup,742 "runcmd": [["systemctl", "enable", "--now", "sshd" if fedora or nixos else "ssh"], ["systemctl", "enable", "--now", f"serial-getty@{serial}.service"]] + computer_setup,