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 2F7D515808D for ; Tue, 19 Apr 2022 15:23:36 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 971C9E0922; Tue, 19 Apr 2022 15:23:33 +0000 (UTC) Received: from rs234.mailgun.us (rs234.mailgun.us [209.61.151.234]) (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 pigeon.gentoo.org (Postfix) with ESMTPS id 7A942E0922 for ; Tue, 19 Apr 2022 15:23:32 +0000 (UTC) DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=xxoo.ws; q=dns/txt; s=mx; t=1650381812; h=In-Reply-To: Content-Type: MIME-Version: References: Message-ID: Subject: Subject: Cc: To: To: From: From: Date: Sender: Sender; bh=6lXssgll2jCg4xvPXD1rwMBxJGqdkWgJsMnyJ1+l18U=; b=GY2tHDP/mM7faXh/LODaGcaNBKHXLWMFmlQtlrhuG6WGzZ1NzBhnfZ7eS7zio+FhmGLz4yoz ey9veounOFxGZ7qw2Qyqc54fNZyqz3hfhu6k4CzoxQY0S0sqx+Gf0J2xEYIoQ90ItCaKY1/h a9Ll9ArtZ0v6v7vsOQVQPO+lKNI= X-Mailgun-Sending-Ip: 209.61.151.234 X-Mailgun-Sid: WyIxYmU3MyIsICJnZW50b28tY2F0YWx5c3RAbGlzdHMuZ2VudG9vLm9yZyIsICJlYTQwNTYiXQ== Received: from mail.0xdc.io (mail.0xdc.io [54.37.0.172]) by smtp-out-n02.prod.us-west-2.postgun.com with SMTP id 625ed3f0487c9ee854e86564 (version=TLS1.3, cipher=TLS_AES_128_GCM_SHA256); Tue, 19 Apr 2022 15:23:28 GMT Sender: gentoo.catalyst@xxoo.ws Received: from pulsar (5.b.0.d.c.4.e.f.f.f.1.0.5.8.8.4.0.a.4.7.9.0.c.0.0.b.8.0.1.0.0.2.ip6.arpa [IPv6:2001:8b0:c09:74a0:4885:1ff:fe4c:d0b5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.0xdc.io (Postfix) with ESMTPSA id ECDAC1023FC; Tue, 19 Apr 2022 15:25:16 +0000 (UTC) Date: Tue, 19 Apr 2022 15:23:22 +0000 From: Daniel Cordero To: gentoo-catalyst@lists.gentoo.org Cc: Matt Turner , Patrice Clement Subject: Re: [gentoo-catalyst] [PATCH 1/3] catalyst: support 3 new options Message-ID: References: <20220327233712.1282001-1-mattst88@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-catalyst@lists.gentoo.org Reply-to: gentoo-catalyst@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220327233712.1282001-1-mattst88@gentoo.org> X-Archives-Salt: 1ba6774c-9008-4de0-904f-fb1afa7488a2 X-Archives-Hash: 25fe3fb0dfd04297bda21296b9b7973e On Sun, Mar 27, 2022 at 04:37:10PM -0700, Matt Turner wrote: > From: Patrice Clement > > * 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 > --- > 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 > @@ -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(): For users() and ssh_public_keys() the setting is used as-is, but for groups it is .split(). None of them handle 0/1/2+ length settings as they get converted into lists and strings. These need to be able to handle both cases. INFO:catalyst:groups to create: [] INFO:catalyst:users to create: [] INFO:catalyst:ssh public keys to copy: [] ... Traceback (most recent call last): File "/catalyst/base/stagebase.py", line 38, in run_sequence func() File "/catalyst/base/stagebase.py", line 934, in groups for x in self.settings["groups"].split(): AttributeError: 'list' object has no attribute '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"]: With the specfile fragment: stage4/groups: a stage4/users: me=a INFO:catalyst:groups to create: a INFO:catalyst:users to create: me=a INFO:catalyst:ssh public keys to copy: [] ... NOTICE:catalyst:--- Running action sequence: groups NOTICE:catalyst:Creating group: 'a' NOTICE:catalyst:--- Running action sequence: users NOTICE:catalyst:Creating user: 'm=' NOTICE:catalyst:Creating user: 'e=' NOTICE:catalyst:Creating user: '=' useradd: invalid user name '=': use --badname to ignore ERROR:catalyst:CatalystError: cmd(['useradd', '-R', '/substrate/tmp/stage4-amd64', '-m', '=']) exited 3 > + 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': > -- > 2.34.1 > >