1 |
On Sun, Mar 27, 2022 at 04:37:10PM -0700, Matt Turner wrote: |
2 |
> From: Patrice Clement |
3 |
> |
4 |
> * stage4/groups: create a a list of groups. |
5 |
> * stage4/users: create a list of users. users can also be added to |
6 |
> groups using the "foo.bar=wheel,audio,baz" format. |
7 |
> * stage4/ssh_public_keys: copy an SSH public key into the stage4 user's home |
8 |
> (.ssh/authorized_keys) and set the file permission to 0644. |
9 |
> |
10 |
> Bug: https://bugs.gentoo.org/236905 |
11 |
> --- |
12 |
> catalyst/base/stagebase.py | 70 ++++++++++++++++++++++++++++++++++++++ |
13 |
> 1 file changed, 70 insertions(+) |
14 |
> |
15 |
> diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
16 |
> index de1e30ef..76feb5f0 100644 |
17 |
> --- a/catalyst/base/stagebase.py |
18 |
> +++ b/catalyst/base/stagebase.py |
19 |
> @@ -894,6 +930,40 @@ class StageBase(TargetBase, ClearBase, GenBase): |
20 |
> cmd(['rsync', '-a', x + '/', self.settings['stage_path']], |
21 |
> env=self.env) |
22 |
> |
23 |
> + def groups(self): |
24 |
> + for x in self.settings["groups"].split(): |
25 |
|
26 |
For users() and ssh_public_keys() the setting is used as-is, but for |
27 |
groups it is .split(). |
28 |
|
29 |
None of them handle 0/1/2+ length settings as they get converted into lists and strings. |
30 |
|
31 |
These need to be able to handle both cases. |
32 |
|
33 |
|
34 |
INFO:catalyst:groups to create: [] |
35 |
INFO:catalyst:users to create: [] |
36 |
INFO:catalyst:ssh public keys to copy: [] |
37 |
... |
38 |
Traceback (most recent call last): |
39 |
File "/catalyst/base/stagebase.py", line 38, in run_sequence |
40 |
func() |
41 |
File "/catalyst/base/stagebase.py", line 934, in groups |
42 |
for x in self.settings["groups"].split(): |
43 |
AttributeError: 'list' object has no attribute 'split' |
44 |
|
45 |
|
46 |
> + log.notice("Creating group: '%s'", x) |
47 |
> + cmd(["groupadd", "-R", self.settings['chroot_path'], x], env=self.env) |
48 |
> + |
49 |
> + def users(self): |
50 |
> + for x in self.settings["users"]: |
51 |
|
52 |
With the specfile fragment: |
53 |
stage4/groups: |
54 |
a |
55 |
|
56 |
stage4/users: |
57 |
me=a |
58 |
|
59 |
|
60 |
|
61 |
INFO:catalyst:groups to create: a |
62 |
INFO:catalyst:users to create: me=a |
63 |
INFO:catalyst:ssh public keys to copy: [] |
64 |
... |
65 |
NOTICE:catalyst:--- Running action sequence: groups |
66 |
NOTICE:catalyst:Creating group: 'a' |
67 |
NOTICE:catalyst:--- Running action sequence: users |
68 |
NOTICE:catalyst:Creating user: 'm=' |
69 |
NOTICE:catalyst:Creating user: 'e=' |
70 |
NOTICE:catalyst:Creating user: '=' |
71 |
useradd: invalid user name '=': use --badname to ignore |
72 |
ERROR:catalyst:CatalystError: cmd(['useradd', '-R', '/substrate/tmp/stage4-amd64', '-m', '=']) exited 3 |
73 |
|
74 |
|
75 |
> + usr, grp = '', '' |
76 |
> + try: |
77 |
> + usr, grp = x.split("=") |
78 |
> + except ValueError: |
79 |
> + usr = x |
80 |
> + log.debug("users: '=' separator not found on line " + x) |
81 |
> + log.debug("users: missing separator means no groups found") |
82 |
> + uacmd = ["useradd", "-R", self.settings['chroot_path'], "-m", x] |
83 |
> + if grp != '': |
84 |
> + uacmd = ["useradd", "-R", self.settings['chroot_path'], "-m", "-G", grp, usr] |
85 |
> + log.notice("Creating user: '%s'", f"{usr}={grp}") |
86 |
> + cmd(uacmd, env=self.env) |
87 |
> + |
88 |
> + def ssh_public_keys(self): |
89 |
> + for x in self.settings["ssh_public_keys"]: |
90 |
> + usr, pub_key_src = '', '' |
91 |
> + try: |
92 |
> + usr, pub_key_src = x.split("=") |
93 |
> + except ValueError: |
94 |
> + raise CatalystError(f"ssh_public_keys: '=' separator not found on line {x}") |
95 |
> + log.notice("Copying SSH public key for user: '%s'", usr) |
96 |
> + pub_key_dest = self.settings['chroot_path'] + f"/home/{usr}/.ssh/authorized_keys" |
97 |
> + cpcmd = ["cp", "-av", pub_key_src, pub_key_dest] |
98 |
> + cmd(cpcmd, env=self.env) |
99 |
> + chcmd = ["chmod", "0644", pub_key_dest] |
100 |
> + cmd(chcmd, env=self.env) |
101 |
> + |
102 |
> def bind(self): |
103 |
> for x in [x for x in self.mount if self.mount[x]['enable']]: |
104 |
> if str(self.mount[x]['source']) == 'config': |
105 |
> -- |
106 |
> 2.34.1 |
107 |
> |
108 |
> |