From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id EAA7A15808C for ; Sat, 2 Apr 2022 23:50:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EAEE6E08C8; Sat, 2 Apr 2022 23:50:49 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 3F223E086A for ; Sat, 2 Apr 2022 23:50:48 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 2BD20340F14 for ; Sat, 2 Apr 2022 23:50:47 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7D4BF35A for ; Sat, 2 Apr 2022 23:50:45 +0000 (UTC) From: "Matt Turner" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Matt Turner" Message-ID: <1648943416.5be6069bcbd5a7fa3f114f28366597bc5ddbb891.mattst88@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/stagebase.py X-VCS-Directories: catalyst/base/ X-VCS-Committer: mattst88 X-VCS-Committer-Name: Matt Turner X-VCS-Revision: 5be6069bcbd5a7fa3f114f28366597bc5ddbb891 X-VCS-Branch: master Date: Sat, 2 Apr 2022 23:50:45 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: ff4cd329-46fb-4602-b358-050a8bf4db5a X-Archives-Hash: 92a6496ae702ef1dc71a7d9a04cf8290 commit: 5be6069bcbd5a7fa3f114f28366597bc5ddbb891 Author: Patrice Clement gentoo org> AuthorDate: Tue Mar 8 21:02:55 2022 +0000 Commit: Matt Turner gentoo org> CommitDate: Sat Apr 2 23:50:16 2022 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=5be6069b catalyst: support 3 new options * stage4/groups: create a a list of groups. * stage4/users: create a list of users. users can also be added to groups using the "foo.bar=wheel,audio,baz" format. * stage4/ssh_public_keys: copy an SSH public key into the stage4 user's home (.ssh/authorized_keys) and set the file permission to 0644. Bug: https://bugs.gentoo.org/236905 Signed-off-by: Patrice Clement gentoo.org> Signed-off-by: Matt Turner gentoo.org> catalyst/base/stagebase.py | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index de1e30ef..76feb5f0 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -201,6 +201,9 @@ class StageBase(TargetBase, ClearBase, GenBase): self.set_packages() self.set_rm() self.set_linuxrc() + self.set_groups() + self.set_users() + self.set_ssh_public_keys() self.set_busybox_config() self.set_overlay() self.set_repos() @@ -583,6 +586,39 @@ class StageBase(TargetBase, ClearBase, GenBase): self.settings[self.settings["spec_prefix"] + "/linuxrc"] del self.settings[self.settings["spec_prefix"] + "/linuxrc"] + def set_groups(self): + groups = self.settings["spec_prefix"] + "/groups" + if groups in self.settings: + if isinstance(self.settings[groups], str): + self.settings["groups"] = self.settings[groups].split(",") + self.settings["groups"] = self.settings[groups] + del self.settings[groups] + else: + self.settings["groups"] = [] + log.info('groups to create: %s' % self.settings["groups"]) + + def set_users(self): + users = self.settings["spec_prefix"] + "/users" + if users in self.settings: + if isinstance(self.settings[users], str): + self.settings["users"] = self.settings[users].split(",") + self.settings["users"] = self.settings[users] + del self.settings[users] + else: + self.settings["users"] = [] + log.info('users to create: %s' % self.settings["users"]) + + def set_ssh_public_keys(self): + ssh_public_keys = self.settings["spec_prefix"] + "/ssh_public_keys" + if ssh_public_keys in self.settings: + if isinstance(self.settings[ssh_public_keys], str): + self.settings["ssh_public_keys"] = self.settings[ssh_public_keys].split(",") + self.settings["ssh_public_keys"] = self.settings[ssh_public_keys] + del self.settings[ssh_public_keys] + else: + self.settings["ssh_public_keys"] = [] + log.info('ssh public keys to copy: %s' % self.settings["ssh_public_keys"]) + def set_busybox_config(self): if self.settings["spec_prefix"] + "/busybox_config" in self.settings: if isinstance(self.settings[self.settings['spec_prefix'] + '/busybox_config'], str): @@ -894,6 +930,40 @@ class StageBase(TargetBase, ClearBase, GenBase): cmd(['rsync', '-a', x + '/', self.settings['stage_path']], env=self.env) + def groups(self): + for x in self.settings["groups"].split(): + log.notice("Creating group: '%s'", x) + cmd(["groupadd", "-R", self.settings['chroot_path'], x], env=self.env) + + def users(self): + for x in self.settings["users"]: + usr, grp = '', '' + try: + usr, grp = x.split("=") + except ValueError: + usr = x + log.debug("users: '=' separator not found on line " + x) + log.debug("users: missing separator means no groups found") + uacmd = ["useradd", "-R", self.settings['chroot_path'], "-m", x] + if grp != '': + uacmd = ["useradd", "-R", self.settings['chroot_path'], "-m", "-G", grp, usr] + log.notice("Creating user: '%s'", f"{usr}={grp}") + cmd(uacmd, env=self.env) + + def ssh_public_keys(self): + for x in self.settings["ssh_public_keys"]: + usr, pub_key_src = '', '' + try: + usr, pub_key_src = x.split("=") + except ValueError: + raise CatalystError(f"ssh_public_keys: '=' separator not found on line {x}") + log.notice("Copying SSH public key for user: '%s'", usr) + pub_key_dest = self.settings['chroot_path'] + f"/home/{usr}/.ssh/authorized_keys" + cpcmd = ["cp", "-av", pub_key_src, pub_key_dest] + cmd(cpcmd, env=self.env) + chcmd = ["chmod", "0644", pub_key_dest] + cmd(chcmd, env=self.env) + def bind(self): for x in [x for x in self.mount if self.mount[x]['enable']]: if str(self.mount[x]['source']) == 'config':