From: Daniel Cordero <gentoo.catalyst@xxoo.ws>
To: gentoo-catalyst@lists.gentoo.org
Cc: Matt Turner <mattst88@gentoo.org>,
Patrice Clement <monsieurp@gentoo.org>
Subject: Re: [gentoo-catalyst] [PATCH 1/3] catalyst: support 3 new options
Date: Tue, 19 Apr 2022 15:23:22 +0000 [thread overview]
Message-ID: <Yl7T6rttNrVPETOh@pulsar.localdomain> (raw)
In-Reply-To: <20220327233712.1282001-1-mattst88@gentoo.org>
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
>
>
next prev parent reply other threads:[~2022-04-19 15:23 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-03-27 23:37 [gentoo-catalyst] [PATCH 1/3] catalyst: support 3 new options Matt Turner
2022-03-27 23:37 ` [gentoo-catalyst] [PATCH 2/3] catalyst: add new options to stage4 step list Matt Turner
2022-03-27 23:37 ` [gentoo-catalyst] [PATCH 3/3] example: document new options Matt Turner
2022-04-19 14:17 ` [gentoo-catalyst] [PATCH 1/3] catalyst: support 3 " Daniel Cordero
2022-04-20 23:25 ` Matt Turner
2022-04-19 15:23 ` Daniel Cordero [this message]
2022-04-20 23:26 ` Matt Turner
2022-04-21 7:08 ` [gentoo-catalyst] [PATCH 1/4] stage4: fix handling of groups, users and keys Daniel Cordero
2022-04-21 7:08 ` [gentoo-catalyst] [PATCH 2/4] stage4/groups: don't run split on a list Daniel Cordero
2022-04-21 7:08 ` [gentoo-catalyst] [PATCH 3/4] stage4/users: don't split a single entry Daniel Cordero
2022-04-21 7:08 ` [gentoo-catalyst] [PATCH 4/4] stage4/groups: improve log message Daniel Cordero
2022-04-21 21:01 ` Daniel Cordero
2022-05-09 11:20 ` [gentoo-catalyst] [PATCH v2 4/4] stage4/users: " Daniel Cordero
2022-05-09 17:06 ` [gentoo-catalyst] [PATCH 1/4] stage4: fix handling of groups, users and keys Matt Turner
2022-05-12 10:09 ` Daniel Cordero
2022-05-13 17:45 ` Matt Turner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Yl7T6rttNrVPETOh@pulsar.localdomain \
--to=gentoo.catalyst@xxoo.ws \
--cc=gentoo-catalyst@lists.gentoo.org \
--cc=mattst88@gentoo.org \
--cc=monsieurp@gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox