From 2a73f2a1bdd1c1ea6b7fd3d27ba8c2e335fa14bb Mon Sep 17 00:00:00 2001 From: Nataliia Solomko Date: Fri, 3 Jul 2026 14:18:32 +0300 Subject: T8344: Preserve symlinks when copying config to/from TPM encrypted volume shutil.copytree() defaults to symlinks=False, so it recurses into symlinked directories and recreates them as real directories instead of preserving the symlink. cloud-init creates /opt/vyatta/etc/config/cloud/instance as a symlink to instances/i-. Enabling/disabling config encryption copied this tree with copytree() and silently turned that symlink into a real directory, causing cloud-init to fail on later runs with: IsADirectoryError: [Errno 21] Is a directory: '.../cloud/instance' Pass symlinks=True to preserve symlinks during the copy. --- src/helpers/vyos-config-encrypt.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/helpers/vyos-config-encrypt.py b/src/helpers/vyos-config-encrypt.py index e035040e1..876a835ec 100755 --- a/src/helpers/vyos-config-encrypt.py +++ b/src/helpers/vyos-config-encrypt.py @@ -122,7 +122,9 @@ def encrypt_config(key, recovery_key=None, is_tpm=True): cmd(f'mount /dev/mapper/vyos_config {d}') # Move mount_path to encrypted volume - shutil.copytree(mount_path, d, copy_function=shutil.move, dirs_exist_ok=True) + shutil.copytree( + mount_path, d, symlinks=True, copy_function=shutil.move, dirs_exist_ok=True + ) cmd(f'chgrp -R vyattacfg {d}') cmd(f'umount {d}') @@ -207,7 +209,9 @@ def decrypt_config(key): cmd(f'mount /dev/mapper/vyos_config {d}') # Move encrypted volume to /opt/vyatta/etc/config - shutil.copytree(d, mount_path, copy_function=shutil.move, dirs_exist_ok=True) + shutil.copytree( + d, mount_path, symlinks=True, copy_function=shutil.move, dirs_exist_ok=True + ) cmd(f'chgrp -R vyattacfg {mount_path}') cmd(f'umount {d}') -- cgit v1.2.3