From 5a55f3bb279119d0e72ca0964fdf88df2cf93f3e Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Tue, 12 Apr 2016 05:00:04 +0000 Subject: [PATCH] Move openssh-server to its own module. Move the key onto the systemid device. --- server/build_image.py | 1 - server/modules/openssh.py | 43 +++++++++++++++++++++++++++++++++++++++ systemid/image.py | 9 ++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100755 server/modules/openssh.py diff --git a/server/build_image.py b/server/build_image.py index 7639703..89e8b91 100755 --- a/server/build_image.py +++ b/server/build_image.py @@ -60,7 +60,6 @@ class ImageBuilder(object): 'iputils-ping', 'linux-firmware', 'linux-firmware-nonfree', - 'openssh-server', 'ubuntu-minimal', 'ubuntu-standard', 'user-setup', diff --git a/server/modules/openssh.py b/server/modules/openssh.py new file mode 100755 index 0000000..2643cd9 --- /dev/null +++ b/server/modules/openssh.py @@ -0,0 +1,43 @@ +#!/usr/bin/python3 + +import argparse +import glob +import os +import subprocess + + +parser = argparse.ArgumentParser(description='iconograph openssh') +parser.add_argument( + '--chroot-path', + dest='chroot_path', + action='store', + required=True) +FLAGS = parser.parse_args() + + +def Exec(*args, **kwargs): + print('+', args) + subprocess.check_call(args, **kwargs) + + +def ExecChroot(*args, **kwargs): + Exec('chroot', FLAGS.chroot_path, *args, **kwargs) + + +def main(): + ExecChroot( + 'apt-get', + 'install', + '--assume-yes', + 'openssh-server') + + for path in glob.glob(os.path.join(FLAGS.chroot_path, 'etc', 'ssh', 'ssh_host_*')): + os.unlink(path) + + os.symlink( + '/systemid/ssh_host_ed25519_key', + os.path.join(FLAGS.chroot_path, 'etc', 'ssh', 'ssh_host_ed25519_key')) + + +if __name__ == '__main__': + main() diff --git a/systemid/image.py b/systemid/image.py index e331ee2..5360523 100755 --- a/systemid/image.py +++ b/systemid/image.py @@ -120,6 +120,14 @@ SYSTEMID=%(system_id)s 'system_id': new_id, }) + def _GenerateSSHKey(self, root): + self._Exec( + 'ssh-keygen', + '-f', os.path.join(root, 'ssh_host_ed25519_key'), + '-N', '', + '-t', 'ed25519', + ) + def _Image(self): self._PartitionAndMkFS() root = self._Mount() @@ -135,6 +143,7 @@ New ID: \033[91m%s\033[00m ============== """ % new_id) + self._GenerateSSHKey(root) def Image(self): self._umount = []