Skip to content

Commit 1df209a

Browse files
authored
Merge pull request #1321 from Dstack-TEE/fix/guest-preset-policy
fix(os): drop foreign systemd presets so dstack's policy is terminal
2 parents d9de891 + 63d78fc commit 1df209a

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

‎os/mkosi/mkosi.postinst‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,9 @@ rm -f "$B"/etc/ssh/ssh_host_*_key "$B"/etc/ssh/ssh_host_*_key.pub
1919
# Build outputs are merged after package installation, so refresh the final
2020
# rootfs cache after manually staged NVIDIA and container-runtime libraries.
2121
ldconfig -r "$B"
22+
23+
# systemd applies the first matching rule across all preset files sorted by
24+
# name, so a distro preset such as Debian's 90-systemd.preset would shadow the
25+
# `disable *` in 99-dstack-default.preset. Keep dstack's policy the only one.
26+
find "$B"/usr/lib/systemd/system-preset "$B"/etc/systemd/system-preset \
27+
-maxdepth 1 -name '*.preset' ! -name '*dstack*' -print -delete 2>/dev/null || true

‎os/mkosi/mkosi.skeleton/usr/lib/systemd/system-preset/80-dstack.preset‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# SPDX-License-Identifier: Apache-2.0
22
enable systemd-networkd.service
3+
# The only unit WantedBy=network-online.target, which dstack-prepare waits on.
4+
enable systemd-networkd-wait-online.service
35
enable systemd-resolved.service
46
enable chrony.service
57
enable docker.service

‎os/mkosi/tests/acceptance.sh‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ test ! -e "$D/../common/rootfs/wg-checker.service"
124124
# only meaningful with a terminal disable. Without it, every package pulled in
125125
# by Packages= would start at boot with no diff to 80-dstack.preset.
126126
grep -q '^disable \*$' "$D/mkosi.skeleton/usr/lib/systemd/system-preset/99-dstack-default.preset"
127+
# ...and it is only terminal if no foreign preset sorts before it.
128+
grep -q "! -name '\*dstack\*'" "$D/mkosi.postinst" || {
129+
echo 'mkosi.postinst must drop foreign preset files' >&2; exit 1; }
130+
grep -qx 'enable systemd-networkd-wait-online.service' \
131+
"$D/mkosi.skeleton/usr/lib/systemd/system-preset/80-dstack.preset"
127132
# The TEE simulator serves synthetic quotes; its preset must not ship in prod.
128133
if grep -rq 'dstack-tee-simulator' "$D/mkosi.skeleton/"; then
129134
echo 'simulator preset must live in the dev profile skeleton' >&2

0 commit comments

Comments
 (0)