All of lore.kernel.org
 help / color / mirror / Atom feed
From: ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org (Eric W. Biederman)
To: Serge Hallyn <serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.org>
Cc: Linux Containers
	<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
	Pkg-shadow-devel-XbBxUvOt3X2LieD7tvxI8l/i77bcL1HB@public.gmane.org,
	"Michael Kerrisk (man-pages)"
	<mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Christian PERRIER
	<bubulle-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org>
Subject: Re: [Pkg-shadow-devel] [PATCH 00/11] pkg-shadow support subordinate ids with user namespaces
Date: Wed, 07 Aug 2013 11:04:59 -0700	[thread overview]
Message-ID: <87eha5peb8.fsf@xmission.com> (raw)
In-Reply-To: <20130807153352.GA5022@sergelap> (Serge Hallyn's message of "Wed, 7 Aug 2013 10:33:52 -0500")

Serge Hallyn <serge.hallyn@ubuntu.com> writes:

> Quoting Nicolas François (nicolas.francois@centraliens.net):
>> Hi,
>> 
>> On Tue, Aug 06, 2013 at 02:54:03PM +0000, serge@hallyn.com wrote:
>> > 
>> > I rebased and pushed the patchset yesterday.
>> 
>> Thanks (this removes me the burden of finding how to merge a branch).
>> 
>> I started to review and read about user namespaces (thanks to Michael!)
>> o
>> Here are some questions/remarks:
>> 
>>  1] It would be nice to be able to disable the new tools / manpages /
>>     options on some systems (i.e. they only make sense on Linux, with
>>     recent Kernel). It would be OK for me if it is enabled by default.
>>     Do you agree?
>
> Makes sense.
>
>>  2] I think we can assume that UID/GIDs are (at least) 32 bits, right?
>>     (or at least when the feature is not disabled - see point 1)
>
> Hm, what about systems compiled with CONFIG_UID16?
>
>>  3] For PAM versions of shadow, I think it would be nice to authenticate
>>     the caller of newuidmap / newgidmap. Do you agree?
>
> I'm not sure what you mean.  Do you mean that pam_something.so could
> otherwise call newuidmap/newgidmap before being authenticated?

It sounded to me like he was suggesting newuidmap/newgidmap should make
an appropriate pam call.  I am not familiar with that part of pam so I
don't know what would be an appropriate pam call.

The closest analog I can think of is newgrp, and to my knowledge newgrp
does not cal into pam.


>>  4] What happens when newuidmap / newgidmap are used within a new namespace?
>>     Is there a risk to do something wrong by recursively creating shells in
>>     cascaded namespace and using these tools? (I don't think so)
>>     Is there a way to enforce that it would only be used in the top-most
>>     namespace? (Maybe it's not needed to forbid it)
>
> The kernel user namespace implementation is designed to support nesting.
>
> Actually I'm not 100% sure, but I think that setuid-root is currently
> only honored in the initial user namespace.  If that were changed,
> then calling newuidmap from a child user namespace would only give
> the caller privilege over his child user namespace.  Therefore he
> could only delegate userids from his own (non-init) namespace to
> his own descendent user namespaces.
>
> calling newuidmap on a pid in the initial user namespace results in
> -EPERM (as otherwise an unprivileged user could remap privileged
> tasks to his permitted subuids :)

There are slightly funny things with setuid and setcap.

The short version however is that once in a user namespace you will
never have more permissions than your the root user in your user
namespace.

So from the outside of the user namespace you can't do anything bad even
with nesting.  Aka there is no defined means to escapte privileges from
inside a user namespace to anything privileged outside a user namespace.

From inside the user namespace you can only follow /etc/subuid or
/etc/subgid (when setting up a nested user namespace).  And if that is a
concern the root user of a user namespace can just create a new mount
namespace and mount over the top of them.

So I don't see anything to concern about.

>>     It would be worth to have at least a paragraph about it in the
>>     manpages. (i.e. IDs in /etc/sub*id are according to the caller's
>>     namespace)
>
> Agreed.
>
>>  5] It would be worth documenting on which processes newuidmap / newgidmap
>>     can act.
>>     With newuidmap, an user can set the UID mapping for any process with
>>     restrictions on the process and on the requested ranges.
>>     We could also mention that the kernel enforce also restriction (5
>>     lines at most; can only be written once)
>
> Note that there are under-development very detailed manpages for
> namespaces(7) and user_namespaces(7).  I agree the newuidmap
> manpage should document what it can act, a one or two line addition
> to DESCRIPTION.  Then it should simply refer to the other manpages.

Yeah.  I should follow up and see what has happend with all of that.

>>  5.1] The restriction on the caller or processes seems to be the followings:
>>     if ((getuid() != pw->pw_uid) ||   // not needed (already enforced
>>                                       // by get_my_pwent()) - but does not
>>                                       // harm.
>>         (getgid() != pw->pw_gid) ||   // I don't understand this
>>                                       // restriction. If I execute a
>>                                       // shell with another GID (e.g. using
>>                                       // newgrp) why should it be denied?
>
> I'm not sure.  I don't know whether Eric was following conventions
> elsewhere in the code, or had specific attacks in mind.

I don't have the context handy, but I think that was general paranoia.
On the lines of if something strange is going on don't allow it.

>>         (pw->pw_uid != st.st_uid) ||
>>         (pw->pw_gid != st.st_gid)) {  // Is it also needed? What would be
>>                                       // the problem
>
> IIUC uid 1000, authorized to use subuids 100000-110000, could otherwise
> use newuidmap to remap a namespace owned by uid 1001.
>
>>  6] Documenting the APIs would be useful. Especially the ones in
>>     lib/subordinateio.c (after 5 minutes, I get lost with the
>>     is_range_free, range_exists, find_range, have_range, ...)
>
> In-line (above each function) or elsewhere?
>
>>  7] I'm not sure about the handling of limits of ranges.
>>     * First, I'm not sure what is intended. (e.g. is SUB_GID_MAX included in
>>     the range)
>>     * In libmisc/find_new_sub_uids.c: Is it intended to forbid min == max
>>       (I'm not claiming this is very useful, but if
>>       SUB_GID_MIN=SUB_GID_MAX and SUB_GID_COUNT is set to 1, this should
>>       be valid to set a single mapping for one UID)
>
> Agreed that sounds like it should be allowed.
>
>>     * In find_free_range(), min==max is also forbidden.
>>     * In find_free_range(), the check (high > low) forbids to reuse a hole
>>       of just 1 UID starting at min
>>     ...

Scratching my head.  When ranges are bounded by two numbers it gets
weird.  All I remember for certain is I deliberately choose the file
format of uid, length so that it would be hard to make off by one
mistakes in the files.

>>  8] Is there a need to check somewhere that that UID_MAX < SUB_UID_MIN in
>>     login.defs? Or is it valid to have overlaps?
>
> That sounds like a dangerous condition to me, and I had assumed it was
> already checked somewhere.

These were fairly arbitrary defines, with no sanity checks and I didn't
add any.  I just had sensible defaults.  As that tends to be the unix
way. You can have rope to shoot yourself if you really want it.

I really have no opinion on the need for sanity checks one way or another.

>>  9] Add manpage NOTE that newuidmap / newgidmap can be used only once on a
>>     given process?
>
> Agreed.
>
>> 10] useradd adds sub*id when the /etc/sub*id files are present, right?
>>     Is it also correct/intended for system users?
>>     I think there should be options to enable or disable the feature.
>>     (I would have chosen the first solution, but I can also understand
>>     that we consider that the presence of the files is a request to use
>>     the feature by default)
>
> Not sure on both of those.  Actually given the (artificial) definition
> of a system user in useradd(8), it sounds to me like subuids could be
> useful for system users on a system where tasks get started in a userns
> by boot scripts using a system userid.

I believe the question was.  If /etc/subuid does not exist and we add a
new user do we want to add an entry in /etc/subuid.  Similarly for
/etc/subgid.

I followed convention in shadow and figured that if /etc/subuid and
/etc/subgid are not present we don't want to add subuids and subgids.

I don't expect we want to add subuids and subgids for system users by
default but as Serge says there may be instances where we want to add
them manually.

>> 11] Ranges will be defined for new users. Do you think there would be a
>>     need for another tool to initialize a system for this feature?
>>     (similar to pwconv)
>
> Do you mean to add ranges for existing users?

I believe it was either useradd or usermod that I modified so that I
could add subuids and subgids for an existing user manually.

As for upgrades I don't know.  Serge with your distro hat on do you see
a use for automatically giving user on a system subids and subgids when
they upgrade versions of shadow?

>> 12] There could be additions in pwck:
>>      * check that users in /etc/sub*id exist
>>      * check overlaps?
>
> Overlaps may actually be a feature in some cases, as a way to allow
> users to share data.

I know I deliberately allowed (but would never create by default)
multiple users having access to the same range of subordinate uids.

Shared read-only system images may benefit from such a practice.

In a similar vein there may be uses of being able to log in to a system
with what is ordinarily a subordinate uid.

The distinction is a distinction of use not a distinction made in the
kernel.

That said having overlaps is usually a mistake and a warning in the
manual process may be called for in case someone simply didn't see
something.

>>      * check overlaps with UIDs?
>>      * ...
>> 
>> I do not think that they are blocking points. (i.e. there could be a
>> release without a solution)
>
> I'll wait for comments or ("no time for a comment") on any of these
> from Eric, then look at addressing those that I can.

I hope that helps put some context to things.  I am totally not looking
at the userspace issues around newuidmap and newgidmap right now, and I
appreciate others being able to look at it and make things better.

Eric

_______________________________________________
Containers mailing list
Containers@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/containers

  reply	other threads:[~2013-08-07 18:04 UTC|newest]

Thread overview: 59+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-22  9:11 [PATCH 00/11] pkg-shadow support subordinate ids with user namespaces Eric W. Biederman
     [not found] ` <87d2wxshu0.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-01-22  9:12   ` [PATCH 01/11] Documentation for /etc/subuid and /etc/subgid Eric W. Biederman
2013-01-22  9:12   ` [PATCH 02/11] login.defs.5: Document the new variables in login.defs Eric W. Biederman
2013-01-22  9:13   ` [PATCH 03/11] Implement commonio_append Eric W. Biederman
2013-01-22  9:13   ` Eric W. Biederman
2013-01-22  9:14   ` [PATCH 04/11] Add backend support for suboridnate uids and gids Eric W. Biederman
     [not found]     ` <87liblr344.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-01-23 18:22       ` Serge E. Hallyn
     [not found]         ` <20130123182206.GA4468-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2013-01-24 22:42           ` Eric W. Biederman
     [not found]             ` <87a9ryyzh2.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-01-24 22:50               ` Serge Hallyn
2013-01-24 22:59                 ` Eric W. Biederman
2013-01-24 23:13                 ` [PATCH] subordinateio: Fix subordinate_parse to have an internal static buffer Eric W. Biederman
2013-01-22  9:15   ` [PATCH 05/11] Implement find_new_sub_uids find_new_sub_gids Eric W. Biederman
2013-01-22  9:16   ` [PATCH 06/11] userdel: Add support for removing subordinate user and group ids Eric W. Biederman
2013-01-22  9:17   ` [PATCH 07/11] useradd: Add support for subordinate user identifiers Eric W. Biederman
2013-01-22  9:17   ` [PATCH 08/11] Add support for detecting busy subordinate user ids Eric W. Biederman
2013-01-22  9:18   ` [PATCH 09/11] usermod: Add support for subordinate uids and gids Eric W. Biederman
2013-01-22  9:19   ` [PATCH 10/11] newusers: Add support for assiging " Eric W. Biederman
2013-01-22  9:20   ` [PATCH 11/11] newuidmap, newgidmap: New suid helpers for using " Eric W. Biederman
     [not found]     ` <87ehhdpoag.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-02-04 18:31       ` [PATCH 11/11] newuidmap,newgidmap: " Serge E. Hallyn
     [not found]         ` <20130204183129.GA27179-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2013-02-05 17:20           ` Serge E. Hallyn
2013-02-06  0:28           ` [PATCH 11/11] newuidmap, newgidmap: " Eric W. Biederman
     [not found]             ` <87sj5ai8us.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-02-06  3:00               ` [PATCH 11/11] newuidmap,newgidmap: " Serge E. Hallyn
     [not found]       ` <87fw1tr33a.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-06-15  0:15         ` [PATCH 05/11] Implement find_new_sub_uids find_new_sub_gids Seth Arnold
2013-10-25 20:30       ` [PATCH 11/11] newuidmap,newgidmap: New suid helpers for using subordinate uids and gids Serge E. Hallyn
     [not found]         ` <20131025203025.GA2467-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2013-10-26  0:42           ` [PATCH 11/11] newuidmap, newgidmap: " Eric W. Biederman
     [not found]             ` <87zjpw278b.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-10-26  2:33               ` Serge Hallyn
2013-10-26 21:50                 ` Eric W. Biederman
     [not found]                   ` <87iowjya4j.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-10-27 23:53                     ` Serge E. Hallyn
2013-01-29 18:15   ` [PATCH 00/11] pkg-shadow support subordinate ids with user namespaces Rob Landley
2013-01-29 22:28     ` Eric W. Biederman
2013-01-30  5:35   ` Vasily Kulikov
2013-01-30  6:40     ` Eric W. Biederman
     [not found]       ` <87vcafyy0k.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-01-30  7:38         ` Vasily Kulikov
2013-02-22 12:16   ` Glauber Costa
     [not found]     ` <51276189.5040803-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2013-02-22 16:34       ` Eric W. Biederman
     [not found]         ` <87zjyw489z.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-02-22 17:09           ` Glauber Costa
     [not found]             ` <5127A657.3010909-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2013-02-25 14:34               ` Serge Hallyn
     [not found]             ` <20130225143451.GE4387@sergelap>
2013-02-25 14:38               ` Glauber Costa
     [not found]                 ` <512B7773.9060704-bzQdu9zFT3WakBO8gow8eQ@public.gmane.org>
2013-02-25 15:15                   ` Serge Hallyn
2013-02-26  1:03                   ` Eric W. Biederman
2013-02-25 14:30           ` Serge Hallyn
2013-03-03 15:37   ` Serge E. Hallyn
2013-03-07 15:23   ` Dwight Engen
2013-07-28 17:14   ` [Pkg-shadow-devel] " Christian PERRIER
     [not found]     ` <20130728171451.GX5670-FvNwPcshoeM/MCprI7ZU+I/wHUNs+SP4HZ5vskTnxNA@public.gmane.org>
2013-07-28 17:58       ` Eric W. Biederman
     [not found]         ` <87r4eilg6y.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-07-29  0:33           ` Serge Hallyn
     [not found]         ` <11218395-363e-46cd-b7a1-4488079a4986@email.android.com>
     [not found]           ` <11218395-363e-46cd-b7a1-4488079a4986-2ueSQiBKiTY7tOexoI0I+QC/G2K4zDHf@public.gmane.org>
2013-08-06 14:54             ` Serge E. Hallyn
     [not found]               ` <20130806145403.GA20913-7LNsyQBKDXoIagZqoN9o3w@public.gmane.org>
2013-08-06 22:53                 ` Nicolas François
     [not found]                   ` <20130806225332.GA14109-pDMkYksm/NDBVznEOA0nCqMXiC8k1aZu0e7PPNI6Mm0@public.gmane.org>
2013-08-07 15:33                     ` Serge Hallyn
2013-08-07 18:04                       ` Eric W. Biederman [this message]
     [not found]                         ` <87eha5peb8.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-08-09 18:40                           ` Nicolas François
     [not found] ` <20130303153726.GA14737@austin.hallyn.com>
     [not found]   ` <20130303153726.GA14737-anj0Drq5vpzx6HRWoRZK3AC/G2K4zDHf@public.gmane.org>
2013-03-04  5:56     ` Christian PERRIER
     [not found]   ` <20130304055654.GE2629@mykerinos.kheops.frmug.org>
     [not found]     ` <20130304055654.GE2629-FvNwPcshoeM/MCprI7ZU+I/wHUNs+SP4HZ5vskTnxNA@public.gmane.org>
2013-03-05 22:05       ` Serge E. Hallyn
     [not found] ` <20130307102352.4a5943cd@oracle.com>
     [not found]   ` <20130307102352.4a5943cd-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
2013-03-07 21:54     ` Serge E. Hallyn
     [not found]       ` <20130307215457.GB9348-anj0Drq5vpzx6HRWoRZK3AC/G2K4zDHf@public.gmane.org>
2013-03-07 22:56         ` Eric W. Biederman
     [not found]           ` <876212rf9b.fsf-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>
2013-03-08  6:50             ` [Pkg-shadow-devel] " Christian PERRIER
     [not found]               ` <20130308065019.GI5885-FvNwPcshoeM/MCprI7ZU+I/wHUNs+SP4HZ5vskTnxNA@public.gmane.org>
2013-06-02 13:48                 ` Serge E. Hallyn
     [not found]                   ` <20130602134823.GB8004-anj0Drq5vpzx6HRWoRZK3AC/G2K4zDHf@public.gmane.org>
2013-06-02 14:04                     ` Christian PERRIER
     [not found]                       ` <20130602140436.GK9152-FvNwPcshoeM/MCprI7ZU+I/wHUNs+SP4HZ5vskTnxNA@public.gmane.org>
2013-06-02 14:33                         ` Serge E. Hallyn

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=87eha5peb8.fsf@xmission.com \
    --to=ebiederm-as9lmozglivwk0htik3j/w@public.gmane.org \
    --cc=Pkg-shadow-devel-XbBxUvOt3X2LieD7tvxI8l/i77bcL1HB@public.gmane.org \
    --cc=bubulle-8fiUuRrzOP0dnm+yROfE0A@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=mtk.manpages-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=serge.hallyn-GeWIH/nMZzLQT0dZR+AlfA@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.