unofficial mirror of bug-guix@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60890: least-authority-wrapper and make-forkexec-constructor composition problem
@ 2023-01-17 19:30 Maxim Cournoyer
  2023-01-19 17:04 ` Ludovic Courtès
  0 siblings, 1 reply; 3+ messages in thread
From: Maxim Cournoyer @ 2023-01-17 19:30 UTC (permalink / raw)
  To: 60890

Hi,

I'm creating a bug to keep track of a problem that was uncovered when
attempting to migrate the jami-service-type service to use the
least-authority-wrapper [0], to avoid forgetting about it.

It was found that using something like:

--8<---------------cut here---------------start------------->8---
(make-forkexec-constructor
  (least-authority
    (list (file-append coreutils "/bin/true"))
    (mappings (delq 'user %namespaces))
  #:user  "nobody"
  #:group "nobody"))
--8<---------------cut here---------------end--------------->8---

Would fail with EPERM, because in order to be able to drop the user
namespace, the CAP_SYS_ADMIN capability is required, but in the above
case, make-forkexec-constructor has already changed the user to
"nobody", which lacks such capability.

The solution proposed by Ludovic in would be to [1]:

> [...] add #:user and #:group to ‘least-authority-wrapper’ and
> have it call setuid/setgid.  ‘make-forkexec-constructor’ doesn’t need to
> be modified, but the user simply won’t pass #:user and #:group to it.

[0]  https://issues.guix.gnu.org/54786#16
[1]  https://issues.guix.gnu.org/54786#17

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#60890: least-authority-wrapper and make-forkexec-constructor composition problem
  2023-01-17 19:30 bug#60890: least-authority-wrapper and make-forkexec-constructor composition problem Maxim Cournoyer
@ 2023-01-19 17:04 ` Ludovic Courtès
  2023-01-20 13:42   ` Maxim Cournoyer
  0 siblings, 1 reply; 3+ messages in thread
From: Ludovic Courtès @ 2023-01-19 17:04 UTC (permalink / raw)
  To: Maxim Cournoyer; +Cc: 60890

Hello!

Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:

> It was found that using something like:
>
> (make-forkexec-constructor
>   (least-authority
>     (list (file-append coreutils "/bin/true"))
>     (mappings (delq 'user %namespaces))
>   #:user  "nobody"
>   #:group "nobody"))
>
> Would fail with EPERM, because in order to be able to drop the user
> namespace, the CAP_SYS_ADMIN capability is required, but in the above
> case, make-forkexec-constructor has already changed the user to
> "nobody", which lacks such capability.

Thanks for the reminder!

I guess the problem is limited to cases where you need the program to
run in the global user namespace.

For example, Tor does not need to run in the global user namespace, and
thus does the following:

--8<---------------cut here---------------start------------->8---
(define (tor-shepherd-service config)
  "Return a <shepherd-service> running Tor."
  (let* ((torrc (tor-configuration->torrc config))
         (tor   (least-authority-wrapper
                 (file-append (tor-configuration-tor config) "/bin/tor")
                 #:name "tor"
                 #:mappings (list …)
                 #:namespaces (delq 'net %namespaces))))
    (list (shepherd-service
           (provision '(tor))
           ;; …
           (start #~(make-forkexec-constructor
                     (list #$tor "-f" #$torrc)
                     #:user "tor" #:group "tor"))
           (stop #~(make-kill-destructor))
           (actions (list (shepherd-configuration-action torrc)))
           (documentation "Run the Tor anonymous network overlay.")))))
--8<---------------cut here---------------end--------------->8---

Here ‘make-forkexec-constructor’ calls setuid/setgid before it invokes
the wrapped program, and everything’s fine.

Ludo’.




^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#60890: least-authority-wrapper and make-forkexec-constructor composition problem
  2023-01-19 17:04 ` Ludovic Courtès
@ 2023-01-20 13:42   ` Maxim Cournoyer
  0 siblings, 0 replies; 3+ messages in thread
From: Maxim Cournoyer @ 2023-01-20 13:42 UTC (permalink / raw)
  To: Ludovic Courtès; +Cc: 60890

Hi,

Ludovic Courtès <ludo@gnu.org> writes:

> Hello!
>
> Maxim Cournoyer <maxim.cournoyer@gmail.com> skribis:
>
>> It was found that using something like:
>>
>> (make-forkexec-constructor
>>   (least-authority
>>     (list (file-append coreutils "/bin/true"))
>>     (mappings (delq 'user %namespaces))
>>   #:user  "nobody"
>>   #:group "nobody"))
>>
>> Would fail with EPERM, because in order to be able to drop the user
>> namespace, the CAP_SYS_ADMIN capability is required, but in the above
>> case, make-forkexec-constructor has already changed the user to
>> "nobody", which lacks such capability.
>
> Thanks for the reminder!
>
> I guess the problem is limited to cases where you need the program to
> run in the global user namespace.

Yes, it's limited to that case, because when clone(2) is called without
CLONE_NEWUSER, the child process does *not* start with a complete set of
capabilities (CAP_SYS_ADMIN), quoting my original investigation from
[0]:

> The problem then seems to be that since we need CAP_SYS_ADMIN when
> dropping the user namespace, as CLONE_NEWUSER is what gives us
> superpowers.  Per 'man user_namespaces':

> The child process created by clone(2) with the CLONE_NEWUSER flag starts
> out with a complete set of capabilities in the new user namespace.

[0]  https://issues.guix.gnu.org/54786#16

-- 
Thanks,
Maxim




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-01-20 13:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 19:30 bug#60890: least-authority-wrapper and make-forkexec-constructor composition problem Maxim Cournoyer
2023-01-19 17:04 ` Ludovic Courtès
2023-01-20 13:42   ` Maxim Cournoyer

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).