From 736b0835686296e949690b816619d7ce20fe2959 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Fri, 17 Apr 2026 15:26:20 +0200 Subject: [PATCH] copr-be: provide ssh key in config.iso drive for libvirt This is the way to tell the instance's cloud-init what is the (currently rotated) correct ssh pub key. --- .../backend/templates/provision/libvirt-new | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/roles/copr/backend/templates/provision/libvirt-new b/roles/copr/backend/templates/provision/libvirt-new index de99ba803e..3183a92b21 100755 --- a/roles/copr/backend/templates/provision/libvirt-new +++ b/roles/copr/backend/templates/provision/libvirt-new @@ -200,6 +200,21 @@ class LibvirtSpawner: """ todo_files = copy.copy(self.config_files) + + # Make sure the machine trusts our buildsys.pub key (via cloud-init). + with open("/var/lib/resallocserver/provision/files/buildsys.pub", "r", + encoding='utf-8') as file: + public_key = file.read() + + user_data = f"""\n +#cloud-config +ssh_authorized_keys: + - {public_key} +""" + todo_files.append(ConfigFile('user-data', user_data)) + meta_data = "instance-id: {self.vm_name}\n" + todo_files.append(ConfigFile('meta-data', meta_data)) + startup_script = self.get_startup_script() if startup_script: todo_files.append(startup_script) @@ -216,9 +231,10 @@ class LibvirtSpawner: image = os.path.join(self.workdir, 'config.iso') - # The 'eimg_config' label is not important, we search for /dev/sr0 - # anyway. - if self.call(['mkisofs', '-o', image, '-V', 'eimg_config', '-r', '-J', + # The 'cidata' label is important, otherwise cloud-init can't take the + # image as NoCloud drive. Other files shouldn't be a problem for cloud + # init. + if self.call(['mkisofs', '-o', image, '-V', 'cidata', '-r', '-J', '--quiet', config_dir]) != 0: raise Exception("mkisofs failed") return image