From 8fd70fd49a15114155d5bc1f507cc76893e62783 Mon Sep 17 00:00:00 2001 From: Markus Hilger Date: Tue, 3 Nov 2026 17:27:51 +0100 Subject: [PATCH] Leave the source network profiles out of captured images Captured images kept the NetworkManager connection profiles and ifcfg files of the source host. A diskless boot kept them too, and confignet only rewrites the profiles named like the interfaces it configures, so every other interface came up with the source host's settings, such as its static addresses. Install to disk already removes them, and capture already masks netplan files for the same reason. Drop them from the image, except ifcfg-lo. --- imgutil/imgutil | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/imgutil/imgutil b/imgutil/imgutil index 175d75c6..d117e42e 100644 --- a/imgutil/imgutil +++ b/imgutil/imgutil @@ -160,11 +160,17 @@ CAPTURE_EMPTY_DIRS = ( # Directories where daemons expect the subdirectories to exist, only the # files are dropped CAPTURE_DIRS_ONLY = ('/var/log', '/var/cache/apt') -# Individual files, may be globs +# Individual files, may be globs. The network profiles of the source would +# keep its addresses on interfaces confignet does not configure, deployment +# writes the node's own (as with the netplan files masked in capture_fs) CAPTURE_DROP_FILES = ( '/var/lib/systemd/random-seed', '/var/lib/rsyslog/imjournal.state', '/var/lib/NetworkManager/*.lease', '/var/lib/dhclient/*.lease', - '/root/.*_history', '/root/.lesshst', '/root/.viminfo') + '/root/.*_history', '/root/.lesshst', '/root/.viminfo', + '/etc/NetworkManager/system-connections/*', + '/etc/sysconfig/network-scripts/ifcfg-*') +# Matches of the globs above to keep +CAPTURE_KEEP_FILES = ('/etc/sysconfig/network-scripts/ifcfg-lo',) def get_capture_excludes(mdir): prefix = mdir.rstrip('/') + '/' @@ -210,7 +216,10 @@ def get_capture_excludes(mdir): top = capin_path(dropglob) if top is None: continue + keep = [capin_path(x) for x in CAPTURE_KEEP_FILES] for dropfile in glob.glob(top): + if dropfile in keep: + continue if (os.path.islink(dropfile) or not os.path.isdir(dropfile)) and droppable(dropfile): excludes.append(dropfile) return excludes