* shepherd service, unexplained permission errors
@ 2023-06-28 20:27 Attila Lendvai
2023-06-28 20:56 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
0 siblings, 1 reply; 3+ messages in thread
From: Attila Lendvai @ 2023-06-28 20:27 UTC (permalink / raw)
To: guix-devel
dear Guix,
i have a daemon that i (try to) run/start through Shepherd's fork+exec-command, with a specific user and group. i can start it up using su or sudo, both work:
$ sudo --user zigbee2mqtt bash -c "guix shell node gcc-toolchain make python libuv -- bash -c 'cd /srv/zigbee2mqtt && npm start'"
# su zigbee2mqtt --command "guix shell node gcc-toolchain make python libuv -- bash -c 'cd /srv/zigbee2mqtt && npm start'"
but through Shepherd the daemon fails while starting up due to a permission denied error:
"Error: Permission denied, cannot open /dev/ttyUSB0"
$ ls -l /dev/ttyUSB0
crw-rw---- 1 root dialout 188, 0 Jun 28 21:04 /dev/ttyUSB0
i created a user for that daemon, and added dialout as a supplementary group:
(user-account
(name "zigbee2mqtt")
(comment "zigbee2mqtt service")
(group "homeaut")
(supplementary-groups '("dialout"))
(system? #true))
(user-group
(name "homeaut")
(system? #true))
i start the service like this:
(simple-service
'zigbee2mqtt
shepherd-root-service-type
(list
(shepherd-service
(requirement '(...))
(provision '(...))
(documentation "")
(start
#~(lambda _
(let* ((cmd (list
"guix" "shell"
"node" "gcc-toolchain" "make" "python" "libuv"
"--"
"bash" "-c" "cd /srv/zigbee2mqtt && npm start")))
(fork+exec-command
cmd
#:log-file "/var/log/zigbee2mqtt.log"
#:user "zigbee2mqtt"
#:group "homeaut")))))))
so, my question boils down to this:
what is different in the two environments? what am i missing?
PS: i have another daemon where i have a very similar issue, so it's probably not a daemon-specific issue.
PS2: i know that i should package zigbee2mqtt, but i'm taking this shortcut because life is short.
--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“The trouble is, you think you have time.”
— Siddhartha Gutama, aka Buddha (c. 5th century BC)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: shepherd service, unexplained permission errors
2023-06-28 20:27 shepherd service, unexplained permission errors Attila Lendvai
@ 2023-06-28 20:56 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2023-06-29 7:42 ` Attila Lendvai
0 siblings, 1 reply; 3+ messages in thread
From: Felix Lechner via Development of GNU Guix and the GNU System distribution. @ 2023-06-28 20:56 UTC (permalink / raw)
To: Attila Lendvai; +Cc: guix-devel
Hi Attila,
On Wed, Jun 28, 2023 at 1:27 PM Attila Lendvai <attila@lendvai.name> wrote:
>
> but through Shepherd the daemon fails while starting up due to a permission denied error:
>
> i created a user for that daemon, and added dialout as a supplementary group:
>
> (supplementary-groups '("dialout"))
>
> (fork+exec-command
> cmd
> #:log-file "/var/log/zigbee2mqtt.log"
> #:user "zigbee2mqtt"
> #:group "homeaut")))))))
The declaration of Shepherd's fork+exec-command has another optional
parameter for "supplementary-groups" [1] which is passed straight to
exec-command. [2]
With a double negation, the language in the manual is a bit hard to
parse, but the explicit argument may be required in order for the
supplementary group to work the way you expect:
"Likewise, command will be run under the current group, unless the
group keyword argument is present and not false, and
supplementary-groups is not '(). " [3]
Kind regards
Felix
[1] https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/service.scm#n1569
[2] https://git.savannah.gnu.org/cgit/shepherd.git/tree/modules/shepherd/service.scm#n1610
[3] https://www.gnu.org/software/shepherd/manual/shepherd.html#index-exec_002dcommand
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: shepherd service, unexplained permission errors
2023-06-28 20:56 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
@ 2023-06-29 7:42 ` Attila Lendvai
0 siblings, 0 replies; 3+ messages in thread
From: Attila Lendvai @ 2023-06-29 7:42 UTC (permalink / raw)
To: Felix Lechner; +Cc: guix-devel
thank you Felix!
the broken expectation from me was that users "have" a group and supplementar-groups (as suggested by the (user-account #:group ...) constructor), and if i specify the user to fork+exec-command, then it sets "its" group, too (i tried with and without specifying a #:group).
in retrospect it should have been obvious, because the fork+exec-command API is on the abstraction level of linux, not that of guix.
the solution that works now is essentially:
(fork+exec-command
cmd
#:user "zigbee2mqtt"
#:group '#$(user-account-group *zigbee2mqtt-user*)
#:supplementary-groups
'#$(user-account-supplementary-groups *zigbee2mqtt-user*))
thanks again,
--
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Enlightenment is man's leaving his self-caused immaturity. Immaturity is the incapacity to use one's intelligence without the guidance of another.”
— Immanuel Kant (1724–1804)
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-06-29 7:42 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-28 20:27 shepherd service, unexplained permission errors Attila Lendvai
2023-06-28 20:56 ` Felix Lechner via Development of GNU Guix and the GNU System distribution.
2023-06-29 7:42 ` Attila Lendvai
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/guix.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).