Skip to content

Add support for looking up user/groups via getent#27599

Merged
justincormack merged 1 commit intomoby:masterfrom
estesp:getent-path
Nov 3, 2016
Merged

Add support for looking up user/groups via getent#27599
justincormack merged 1 commit intomoby:masterfrom
estesp:getent-path

Conversation

@estesp
Copy link
Contributor

@estesp estesp commented Oct 20, 2016

Fixes #20191

Adds a path to user/uid and group/gid lookup to use the capabilities for getent to use host-configured external databases for passwd and group information.

This allows the processing of --userns-remap flag to find valid users and groups on such systems. Without this, user namespaces can't be enabled on these types of Linux hosts.

@justincormack
Copy link
Contributor

getent is not specified by Posix. I am kind of reluctant to use this, given the monumental mess we have with shelling out to useradd/adduser, as they are not standardised either and have random syntax on different distros.

We definitely need to improve this, but not sure what the best answer is.

@estesp
Copy link
Contributor Author

estesp commented Oct 26, 2016

@justincormack understand the concerns.. to me, given the way I put this PR together, if getent is "broken", missing, etc. user and group parsing function will work as it does today relying on our custom parsing of local files. Given that, having increased support for externally configured user/group databases seems reasonable for the "path of least resistance" where getent works in the mainstream way. My admittedly generic understanding is that the use of getent seems much simpler than the complicated story of useradd/adduser and friends across distros.

@runcom
Copy link
Member

runcom commented Oct 26, 2016

I'm +1 on this - my system is also setup such as that my user is on remote db (sssd)

@justincormack
Copy link
Contributor

Yes getent does seem more standard.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error is now always suppressed; is that desirable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e., the error from getEntUser will always mask this one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a version of the code that tried not to "hide" the orig. error but it was rather ugly, and in the end, ends up as a "can't find user" (getent would have done the same searching of local filesystem in default mode, so same error). If we think there are other potential edge case errors in this path that need to be exposed we can re-work

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, no problem, was just wondering if the original error would contain useful information

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just return getentUser?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return getentGroup

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return getentGroup

When processing the --userns-remap flag, add the
capability to call out to `getent` if the user and
group information is not found via local file
parsing code already in libcontainer/user.

Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com>
@thaJeztah
Copy link
Member

looks like it's updated @cpuguy83 @justincormack ptal 😇

@justincormack
Copy link
Contributor

LGTM

1 similar comment
@runcom
Copy link
Member

runcom commented Nov 3, 2016

LGTM

@justincormack justincormack merged commit 81683e8 into moby:master Nov 3, 2016
@thaJeztah thaJeztah added this to the 1.13.0 milestone Nov 3, 2016
tiborvass pushed a commit to tiborvass/docker that referenced this pull request Sep 24, 2019
About github.com/opencontainers/runc/libcontainer/user:

According to opencontainers/runc@195d8d5
this package has two functions:
- Have a static implementation of user lookup, which is now supported in the
  os/user stdlib package with the osusergo build tag, but wasn't at the time.
- Have extra functions that os/user doesn't have, but none of those are used
  in homedir.

Since moby#11287, homedir depended directly on
libcontainer's user package for CurrentUser().
This is being replaced with os/user.Current(), because all of our static
binaries are compiled with the osusergo tag, and for dynamic libraries it
is more correct to use libc's implementation than parsing /etc/passwd.

About github.com/docker/docker/pkg/idtools:

Only dependency was from GetStatic() which uses idtools.LookupUID(uid).
The implementation of idtools.LookupUID just calls to
github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks
to exec-ing to getent (since moby#27599).

This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out
of supporting nss lookups in static binaries via exec-ing to getent for
the homedir package.

If homedir package users need to support nss lookups, they are advised
to compile dynamically instead.

Signed-off-by: Tibor Vass <tibor@docker.com>
docker-jenkins pushed a commit to docker-archive/docker-ce that referenced this pull request Sep 26, 2019
About github.com/opencontainers/runc/libcontainer/user:

According to opencontainers/runc@195d8d5
this package has two functions:
- Have a static implementation of user lookup, which is now supported in the
  os/user stdlib package with the osusergo build tag, but wasn't at the time.
- Have extra functions that os/user doesn't have, but none of those are used
  in homedir.

Since moby/moby#11287, homedir depended directly on
libcontainer's user package for CurrentUser().
This is being replaced with os/user.Current(), because all of our static
binaries are compiled with the osusergo tag, and for dynamic libraries it
is more correct to use libc's implementation than parsing /etc/passwd.

About github.com/docker/docker/pkg/idtools:

Only dependency was from GetStatic() which uses idtools.LookupUID(uid).
The implementation of idtools.LookupUID just calls to
github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks
to exec-ing to getent (since moby/moby#27599).

This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out
of supporting nss lookups in static binaries via exec-ing to getent for
the homedir package.

If homedir package users need to support nss lookups, they are advised
to compile dynamically instead.

Signed-off-by: Tibor Vass <tibor@docker.com>
Upstream-commit: a8608b5b67c77169276863cf31c6bc89a9ab3d8c
Component: engine
burnMyDread pushed a commit to burnMyDread/moby that referenced this pull request Oct 21, 2019
About github.com/opencontainers/runc/libcontainer/user:

According to opencontainers/runc@195d8d5
this package has two functions:
- Have a static implementation of user lookup, which is now supported in the
  os/user stdlib package with the osusergo build tag, but wasn't at the time.
- Have extra functions that os/user doesn't have, but none of those are used
  in homedir.

Since moby#11287, homedir depended directly on
libcontainer's user package for CurrentUser().
This is being replaced with os/user.Current(), because all of our static
binaries are compiled with the osusergo tag, and for dynamic libraries it
is more correct to use libc's implementation than parsing /etc/passwd.

About github.com/docker/docker/pkg/idtools:

Only dependency was from GetStatic() which uses idtools.LookupUID(uid).
The implementation of idtools.LookupUID just calls to
github.com/opencontainers/runc/libcontainer/user.LookupUid or fallbacks
to exec-ing to getent (since moby#27599).

This patch replaces calls to homedir.GetStatic by homedir.Get(), opting out
of supporting nss lookups in static binaries via exec-ing to getent for
the homedir package.

If homedir package users need to support nss lookups, they are advised
to compile dynamically instead.

Signed-off-by: Tibor Vass <tibor@docker.com>
Signed-off-by: zach <Zachary.Joyner@linux.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants