network: honor --root= for picked up credentials

network-generator writes generated command line configuration below
the alternate root passed with --root=, but network.* credentials
were copied to fixed host /run paths.

Build the credential target directories with arg_root before passing
them to pick_up_credentials(). This keeps normal boot behavior
unchanged while making credential output land in the requested root.
This commit is contained in:
Totoro
2026-09-04 14:22:25 +09:00
committed by Yu Watanabe
parent 4a25049a9e
commit f4a7117af2
4 changed files with 36 additions and 12 deletions
@@ -4,12 +4,15 @@
set -eux
set -o pipefail
ROOT="$(mktemp -d /var/tmp/test-network-generator-root.XXXXXX)"
at_exit() {
rm -f /run/credstore/network.conf.50-testme
rm -f /run/credstore/network.network.50-testme
rm -f /run/systemd/networkd.conf.d/50-testme.conf
rm -f /run/systemd/network/50-testme.network
rm -f /run/systemd/system/systemd-network-generator.service.d/50-testme.conf
rm -rf "${ROOT:?}"
}
trap at_exit EXIT
@@ -35,3 +38,10 @@ systemctl restart systemd-network-generator
diff /run/credstore/network.conf.50-testme /run/systemd/networkd.conf.d/50-testme.conf
diff /run/credstore/network.network.50-testme /run/systemd/network/50-testme.network
CREDENTIALS_DIRECTORY=/run/credstore /usr/lib/systemd/systemd-network-generator --root="$ROOT"
diff /run/credstore/network.conf.50-testme \
"$ROOT/run/systemd/networkd.conf.d/50-testme.conf"
diff /run/credstore/network.network.50-testme \
"$ROOT/run/systemd/network/50-testme.network"