Debian: passwordless updates, offline updates, and install ISO builder

Ports the update behaviour of the Fedora clients to Debian, and adds the
Debian equivalent of putting ks.cfg on the installation medium.

Updates
-------
Debian's shipped polkit policy only lets a sudo-group user trigger
upgrade-system and trigger-offline-update without a password. The actions
pkcon refresh and pkcon update actually use (system-sources-refresh and
system-update) are auth_admin, so a desktop user was prompted - a
behavioural difference from Fedora. update_local_repo.py now installs
/etc/polkit-1/rules.d/60-vdi-no-password-updates.rules granting exactly
those two plus package-install to group sudo. package-remove,
package-reinstall and package-install-untrusted stay auth_admin.

The offline update itself ports unchanged: Debian 13 PackageKit 1.3.1
supports offline-get-prepared and offline-trigger, and
packagekit-offline-update.service is wired into system-update.target.
Scheduling moves from an @reboot cron line to vdi-offline-update.timer
(6h, Persistent), with /root/auto_update.sh delegating to the same script
so there is one implementation instead of two.

Both are installed by update_local_repo.py, not only by the preseed, so
already-provisioned machines pick them up on their next 10-minute cron run.

install ISO
-----------
debian/make-iso.sh bakes preseed.cfg into a Debian netinst ISO and adds
auto=true priority=critical preseed/file=/cdrom/preseed.cfg to every boot
menu entry, then verifies its own output.

Measured, not assumed
---------------------
* subject.local == true never matches in this environment: pkcheck returns
  2 with the clause and 0 without it, same sudo-group user. It was in the
  first version of the rule and is removed; the reasoning is in the source.
* pkcon exits 5 for "no packages to update", which is the normal answer on
  a patched box and was being logged as a download failure. Fixed.
* offline-get-prepared exits 4 when nothing is prepared, so the Fedora
  "if ... offline-trigger" guard is load-bearing - triggering anyway can
  leave a dangling /system-update symlink that breaks the next boot.
* Extracting a netinst and rebuilding with "xorriso -as mkisofs" grows it
  792MB -> 988MB because Debian shares identical file extents; replaying
  the original session with -map keeps dedup and the boot record.
* A hardcoded menu list misses isolinux/gtk.cfg, where the BIOS *default*
  entry lives, so the machine still prompted. Menus are discovered now.

Tests: 90 passed, 0 failed, 2 skipped. T17 asserts the polkit decision in
both directions (authorised with the rule, prompted without it), because a
check that cannot fail proves nothing.
This commit is contained in:
Mistercoolertyper committed 2026-11-04 10:16:23 +01:00
1 parent 4f1a4530aa
commit 15d65183dc
6 files changed
+1335 -2

No files matched your search

+183
View File
@@ -491,6 +491,183 @@ def _repo_file(name):
return "./" + name
# ---------------------------------------------------------------------------
# Debian: no-password updates and the offline update
# ---------------------------------------------------------------------------
# Lets members of the "sudo" group refresh and install updates from a graphical
# session without being asked for a password, which is how the Fedora clients
# behave. Debian's own /usr/share/polkit-1/rules.d/org.freedesktop.packagekit.rules
# only covers "upgrade-system" and "trigger-offline-update" - not the update and
# install actions - and 50-default.rules makes "unix-group:sudo" the admin
# identity, so an admin is prompted for authorisation. This rule supplies the
# missing cases.
#
# Scoped to the desktop-session actions only:
# * system-sources-refresh is the action `pkcon refresh` uses;
# * system-update is the action `pkcon update` uses;
# * package-install covers installing from a local cache.
# Deliberately NOT covered: package-install-untrusted, package-remove,
# package-reinstall. Those stay at auth_admin, so a normal user still cannot
# remove packages or install an untrusted one without a password.
#
# NOTE on subject.local: an earlier version of this rule also required
# `subject.local == true`, intending to limit it to seats physically in front of
# the machine. That clause was removed after measurement: with it the rule does
# not match and the user is still prompted (pkcheck rc=2), and without it the
# rule authorises (pkcheck rc=0), both with the same sudo-group user. The
# consequence of dropping it is that a sudo-group user on a remote session can
# also update without a password - which is the same trust level that group
# already carries through sudo.
POLKIT_RULE_PATH = "/etc/polkit-1/rules.d/60-vdi-no-password-updates.rules"
POLKIT_RULE = """// Installed by VDI-Linux update_local_repo.py. Do not edit; it is rewritten.
//
// Allow members of the "sudo" group to refresh the package cache and install
// updates from a graphical session without a password prompt. This matches the
// behaviour of the Fedora clients. Everything else PackageKit can do still
// requires authorisation.
polkit.addRule(function(action, subject) {
if ((action.id == "org.freedesktop.packagekit.system-sources-refresh" ||
action.id == "org.freedesktop.packagekit.system-update" ||
action.id == "org.freedesktop.packagekit.package-install") &&
subject.isInGroup("sudo")) {
return polkit.Result.YES;
}
});
"""
# Prepares an offline update: download now, install at the next boot, so the
# desktop is never sitting on a half-applied transaction while someone is using
# it. Same intent as the Fedora auto_update.sh, but it records a timestamp so
# the caller can throttle it and it does not depend on an ambient DISPLAY.
OFFLINE_UPDATE_SCRIPT = "/usr/local/sbin/vdi-offline-update"
OFFLINE_UPDATE_CONTENT = """#!/bin/bash
# Prepare a PackageKit offline update. Installed by VDI-Linux; do not edit.
#
# Runs as root from cron, so PackageKit authorises it without a password. The
# update is downloaded now and applied by packagekit-offline-update.service on
# the next boot, which is what keeps updates off the desktop's critical path.
set -u
STAMP=/var/lib/vdi-offline-update.last
MIN_INTERVAL=21600 # six hours between attempts
now=$(date +%s)
if [ -r "$STAMP" ]; then
last=$(cat "$STAMP" 2>/dev/null || echo 0)
case "$last" in ''|*[!0-9]*) last=0 ;; esac
if [ $((now - last)) -lt "$MIN_INTERVAL" ]; then
echo "vdi-offline-update: last attempt $(( (now - last) / 60 )) min ago, skipping"
exit 0
fi
fi
echo "$now" > "$STAMP"
# Hold off sleep and idle for the duration of the download.
RUN=(pkcon)
if command -v systemd-inhibit >/dev/null 2>&1; then
RUN=(systemd-inhibit --what=sleep:idle \\
--who="VDI offline update" --why="Downloading system updates" \\
--mode=block pkcon)
fi
"${RUN[@]}" refresh force || echo "vdi-offline-update: refresh failed"
# pkcon's exit codes (PK_EXIT_ENUM): 0 success, 1 failed, 2 cancelled,
# 3 not found, 4 already installed, 5 no packages to update. Exit 5 is the
# normal "already up to date" answer, not an error, so it must not be reported
# as a download failure - measured on trixie, `update --only-download` returns 5
# on a fully patched box.
"${RUN[@]}" update --only-download
rc=$?
case "$rc" in
0) : ;;
5) echo "vdi-offline-update: no updates available" ;;
*) echo "vdi-offline-update: download failed (pkcon exit $rc)" ;;
esac
# offline-get-prepared exits non-zero when nothing is prepared, so this guard is
# what stops us arming /system-update with no payload (a dangling system-update
# symlink fails the next boot).
if pkcon offline-get-prepared >/dev/null 2>&1; then
if pkcon offline-trigger; then
echo "vdi-offline-update: offline update armed for the next boot"
else
echo "vdi-offline-update: offline-trigger failed"
fi
else
echo "vdi-offline-update: nothing to prepare"
fi
"""
# systemd timer units: the same three things auto_update.sh does, on a timer.
# Using units rather than crontab entries means systemd owns the scheduling,
# logs go to the journal, and a failed run is visible in `systemctl status`.
OFFLINE_UPDATE_SERVICE = """[Unit]
Description=Prepare a PackageKit offline update
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/vdi-offline-update
Nice=10
IOSchedulingClass=idle
"""
OFFLINE_UPDATE_TIMER = """[Unit]
Description=Prepare a PackageKit offline update periodically
[Timer]
OnBootSec=15min
OnUnitActiveSec=6h
RandomizedDelaySec=15min
Persistent=true
[Install]
WantedBy=timers.target
"""
def install_debian_update_policy():
"""Install the polkit rule and the offline-update script/timer on Debian.
Both are idempotent: each file is only rewritten when its content differs,
so a 10-minute cron run does not touch the disk or restart anything.
"""
if PACKAGE_FAMILY != "debian":
return
for path, content, mode in (
(POLKIT_RULE_PATH, POLKIT_RULE, 0o644),
(OFFLINE_UPDATE_SCRIPT, OFFLINE_UPDATE_CONTENT, 0o755),
("/etc/systemd/system/vdi-offline-update.service", OFFLINE_UPDATE_SERVICE, 0o644),
("/etc/systemd/system/vdi-offline-update.timer", OFFLINE_UPDATE_TIMER, 0o644),
):
try:
os.makedirs(os.path.dirname(path), exist_ok=True)
current = None
if os.path.exists(path):
with open(path, encoding="utf-8") as handle:
current = handle.read()
if current == content:
continue
temporary = path + ".tmp"
with open(temporary, "w", encoding="utf-8") as handle:
handle.write(content)
os.chmod(temporary, mode)
os.replace(temporary, path)
logging.info("Installed %s", path)
except OSError as error:
logging.warning("Could not install %s: %s", path, error)
# Enable the timer. `enable --now` would start it, but in a chroot there is
# no running systemd, so tolerate failure and let it come up on first boot.
if shutil.which("systemctl"):
subprocess.run(["systemctl", "daemon-reload"], check=False,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
subprocess.run(["systemctl", "enable", "vdi-offline-update.timer"], check=False,
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
def _match_debian_asset(assets, package_name):
"""Find the release asset for ``package_name``, ignoring its version.
@@ -734,6 +911,12 @@ def main():
install_desktop_shortcuts()
# Debian needs a polkit rule before a desktop user can update without a
# password, and the offline-update timer. Both are idempotent and are done
# here, not in the preseed, so existing machines pick them up on the next
# cron run - the same way configure_kde.py back-fills older installs.
install_debian_update_policy()
is_newer, release_data = is_newer_release(REPO_OWNER, REPO_NAME)
if PACKAGE_FAMILY == "debian":