Skip to content

Commit c303aa6

Browse files
committed
tpm: T7726: Copy encrypted volume when adding system images
1 parent 140d397 commit c303aa6

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

src/op_mode/image_installer.py

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from os import readlink
2727
from os import getpid
2828
from os import getppid
29+
from os import sync
2930
from json import loads
3031
from json import dumps
3132
from typing import Union
@@ -1086,30 +1087,60 @@ def add_image(image_path: str, vrf: str = None, username: str = '',
10861087
# find target directory
10871088
root_dir: str = disk.find_persistence()
10881089

1090+
cmdline_options = []
1091+
10891092
# a config dir. It is the deepest one, so the comand will
10901093
# create all the rest in a single step
10911094
target_config_dir: str = f'{root_dir}/boot/{image_name}/rw{DIR_CONFIG}/'
10921095
# copy config
10931096
if no_prompt or migrate_config():
1094-
print('Copying configuration directory')
1095-
# copytree preserves perms but not ownership:
1096-
Path(target_config_dir).mkdir(parents=True)
1097-
chown(target_config_dir, group='vyattacfg')
1098-
chmod_2775(target_config_dir)
1099-
copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True,
1100-
copy_function=copy_preserve_owner, dirs_exist_ok=True)
1101-
1102-
# Record information from which image we upgraded to the new one.
1103-
# This can be used for a future automatic rollback into the old image.
1104-
tmp = {'previous_image' : image.get_running_image()}
1105-
write_file(f'{target_config_dir}/first_boot', dumps(tmp))
1106-
1097+
if Path('/dev/mapper/vyos_config').exists():
1098+
print('Copying encrypted configuration volume')
1099+
1100+
# Record information from which image we upgraded to the new one.
1101+
# This can be used for a future automatic rollback into the old image.
1102+
#
1103+
# For encrypted config, we need to copy, sync filesystems and remove from current image
1104+
tmp = {'previous_image' : image.get_running_image()}
1105+
write_file('/opt/vyatta/etc/config/first_boot', dumps(tmp))
1106+
sync()
1107+
1108+
# Copy encrypteed volumes
1109+
current_name = image.get_running_image()
1110+
current_config_path = f'{root_dir}/luks/{current_name}'
1111+
target_config_path = f'{root_dir}/luks/{image_name}'
1112+
copy(current_config_path, target_config_path)
1113+
1114+
# Now remove from current image
1115+
Path('/opt/vyatta/etc/config/first_boot').unlink()
1116+
1117+
cmdline_options = get_cli_kernel_options(
1118+
f'/opt/vyatta/etc/config/config.boot')
1119+
else:
1120+
print('Copying configuration directory')
1121+
# copytree preserves perms but not ownership:
1122+
Path(target_config_dir).mkdir(parents=True)
1123+
chown(target_config_dir, group='vyattacfg')
1124+
chmod_2775(target_config_dir)
1125+
copytree(f'{DIR_CONFIG}/', target_config_dir, symlinks=True,
1126+
copy_function=copy_preserve_owner, dirs_exist_ok=True)
1127+
1128+
# Record information from which image we upgraded to the new one.
1129+
# This can be used for a future automatic rollback into the old image.
1130+
tmp = {'previous_image' : image.get_running_image()}
1131+
write_file(f'{target_config_dir}/first_boot', dumps(tmp))
1132+
1133+
cmdline_options = get_cli_kernel_options(
1134+
f'{target_config_dir}/config.boot')
11071135
else:
11081136
Path(target_config_dir).mkdir(parents=True)
11091137
chown(target_config_dir, group='vyattacfg')
11101138
chmod_2775(target_config_dir)
11111139
Path(f'{target_config_dir}/.vyatta_config').touch()
11121140

1141+
cmdline_options = get_cli_kernel_options(
1142+
f'{target_config_dir}/config.boot')
1143+
11131144
target_ssh_dir: str = f'{root_dir}/boot/{image_name}/rw/etc/ssh/'
11141145
if no_prompt or copy_ssh_host_keys():
11151146
print('Copying SSH host keys')

0 commit comments

Comments
 (0)