Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SETUID/SETGID not required for changing user #6083

Merged

Conversation

bernerdschaefer
Copy link
Contributor

With this changeset, providing a user in container configuration does not require that you also grant SETUID and SETGID capabilities to the contained process.

It accomplishes this by:

  • dropping the bounding set while still fully privileged
  • calling prctl(PR_SET_KEEPCAPS, 1), to preserve capabilities while changing users
  • changing user (unchanged)
  • calling prctl(PR_SET_KEEPCAPS, 0) to clear the setting
  • dropping capabilities (unchanged)

before

> grep capabilities container.json
  "capabilities": ["SETUID", "SETGID"],
> sudo nsinit exec /bin/grep Cap /proc/self/status
CapInh: 00000000000000c0
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 00000000000000c0

> grep capabilities container.json
  "capabilities": [],
>  sudo nsinit exec /bin/grep Cap /proc/self/status
2014/05/28 15:00:43 unable to initialize for container: finalize namespace setup user setgroups operation not permitted

after

> grep capabilities container.json
  "capabilities": ["SETUID", "SETGID"],
> sudo nsinit exec /bin/grep Cap /proc/self/status
CapInh: 00000000000000c0
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 00000000000000c0

> grep capabilities container.json
  "capabilities": [],

> sudo nsinit exec /bin/grep Cap /proc/self/status
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
CapBnd: 0000000000000000

Fixes #4556

Docker-DCO-1.1-Signed-off-by: Bernerd Schaefer <bj.schaefer@gmail.com> (github: bernerdschaefer)
It is no longer necessary to pass "SETUID" or "SETGID" capabilities to
the container when a "user" is specified in the config.

Docker-DCO-1.1-Signed-off-by: Bernerd Schaefer <bj.schaefer@gmail.com> (github: bernerdschaefer)
@vmarmol
Copy link
Contributor

vmarmol commented May 28, 2014

LGTM. Great change :) thanks for the followup! @crosbymichael for pkg/system and the second on libcontainer.

@crosbymichael
Copy link
Contributor

LGTM

1 similar comment
@vieux
Copy link
Contributor

vieux commented May 29, 2014

LGTM

vieux added a commit that referenced this pull request May 29, 2014
…s-after-changing-user

SETUID/SETGID not required for changing user
@vieux vieux merged commit b204b97 into moby:master May 29, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

capset() might randomly fail with -EPERM
4 participants