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

oci-worker: experimental support for rootless mode #419

Merged
merged 1 commit into from
Jun 1, 2018

Conversation

AkihiroSuda
Copy link
Member

Signed-off-by: Akihiro Suda [email protected]

This PR allows running BuildKit without root privileges using the latest unpatched runc.

  • The username space needs to be unshared before running buildkitd. To allow subuid/subgid/setgroups (typically required by apt), newuidmap and newgidmap can be used. (img automatically does this)
  • Network namespace is not used now, but we could set up it with either SUID lxc-usernet or slirp/netstack. I'll soon implement a utility for this, probably as a separate project.

For further information, please refer to docs/rootless.md.

Closes #252

cc @tonistiigi @jessfraz @alexellis @cyphar

# Rootless mode (Experimental)

Requirements:
- runc (May 30, 2018) or later
Copy link
Member Author

Choose a reason for hiding this comment

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

The upstream master is broken as of writing due to a merge conflict but will be fixed immediately in opencontainers/runc#1808

@@ -107,6 +107,13 @@ func main() {
Name: "tlscacert",
Usage: "ca certificate to verify clients",
},
cli.BoolFlag{
Name: "rootless",
Copy link
Member

Choose a reason for hiding this comment

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

should this be oci-worker-rootless ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess this should be global so that we can switch the default root dir and the default socket path?

Copy link
Member

Choose a reason for hiding this comment

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

maybe both then and change the description of this field to "set all the default options to be compatible with rootless containers". Global --rootless would then behave as a shortcut that is the only flag that needs to be set for quickly running in rootless mode. But if you set all the other flags (addr, root, worker-rootless) manually then you don't even need it.

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

# Rootless mode (Experimental)

Requirements:
- runc (May 30, 2018) or later
Copy link
Member

Choose a reason for hiding this comment

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

Should we update test.Dockerfile to this? Also, maybe create buildkit-runc with make binaries as executor already supports this optional override.

Copy link
Member

Choose a reason for hiding this comment

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

Also, can we get the integration tests running using the rootless worker? Can be follow-up if there are complications.

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably after we have the tool for setting up newuidmap newgidmap?

The test has been substantially covered in genuinetools/img.

docs/rootless.md Outdated
- Some distros such as Arch Linux require `echo 1 > /proc/sys/kernel/unprivileged_ns_clone`
- To run in a Docker container with non-root `USER`, `docker run --privileged` is still required. See also Jessie's blog: https://blog.jessfraz.com/post/building-container-images-securely-on-kubernetes/

Setting up rootless mode also requires some bothersome steps as follows, but we will soon have automation tool.
Copy link
Member

Choose a reason for hiding this comment

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

q: can this all run in buildkitd startup in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably it will be a separate binary so that it can be shared across different projects like

$ rootlesskit --user=suid --net=usermode buildkitd

But I'll try to implement rootlesskit so that it can be also used as a Go (>= 1.10) library that can be imported from buildkitd

Copy link
Member

Choose a reason for hiding this comment

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

So does this setup require setuid binary or not?

Copy link
Member Author

@AkihiroSuda AkihiroSuda May 30, 2018

Choose a reason for hiding this comment

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

still newuidmap and newgidmap with setuid bit are required.

We could also use ptrace instead as in https://github.com/rootless-containers/runrootless , but slow and unstable. (although probably acceptable for just installing binary packages: rootless-containers/runrootless#14 )

Copy link
Member Author

Choose a reason for hiding this comment

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

// Set the oom_score_adj of our children containers to that of the current process.
b, err := ioutil.ReadFile("/proc/self/oom_score_adj")
if err != nil {
return fmt.Errorf("reading /proc/self/oom_score_adj failed: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

nit: errors.Errorf, line 243 as well

docs/rootless.md Outdated

Requirements:
- runc (May 30, 2018) or later
- Some distros such as Arch Linux require `echo 1 > /proc/sys/kernel/unprivileged_ns_clone`
Copy link
Member

Choose a reason for hiding this comment

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

isn't this unprivileged_userns_clone ?

penguin:231072:65536
$ grep $(whoami) /etc/subgid
penguin:231072:65536
$ newuidmap $(cat /tmp/pid) 0 1001 1 1 231072 65536
Copy link
Member

Choose a reason for hiding this comment

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

recommend installing uidmap pkg ?

@AkihiroSuda AkihiroSuda force-pushed the rootless branch 7 times, most recently from 847f240 to 4bb4e25 Compare May 30, 2018 09:33
@AkihiroSuda
Copy link
Member Author

Opened containerd PR containerd/containerd#2006

Some duplicated codes can be eliminated after the containerd PR gets merged.

})
defaultRoot = appdefaults.UserRoot()
defaultAddress = appdefaults.UserAddress()
appdefaults.EnsureUserAddressDir()
Copy link
Member

Choose a reason for hiding this comment

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

Is there an easy way to switch the snapshotter as well when overlay is not supported? Or maybe just default to naive then.

@@ -35,6 +30,27 @@ func init() {
Name: "containerd-worker-labels",
Usage: "user-specific annotation labels (com.example.foo=bar)",
},
}
n := "containerd-worker-rootless"
Copy link
Member

Choose a reason for hiding this comment

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

Does it make sense to add this until containerd is not actually supported?

@AkihiroSuda
Copy link
Member Author

updated

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

LGTM

@AkihiroSuda
Copy link
Member Author

Mergeable?

@tonistiigi tonistiigi merged commit 65b5264 into moby:master Jun 1, 2018
@jessfraz
Copy link
Contributor

jessfraz commented Jun 1, 2018

Awesome!

@@ -225,6 +226,9 @@ export JAEGER_TRACE=0.0.0.0:6831

During development, BuildKit is tested with the version of runc that is being used by the containerd repository. Please refer to [runc.md](https://github.com/containerd/containerd/blob/v1.1.0/RUNC.md) for more information.

### Running BuildKit without root privileges

Please refer to `[docs/rootless.md]`(docs/rootless.md).
Copy link
Member

Choose a reason for hiding this comment

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

@AkihiroSuda (edit) this doesn't show as link because of quotes

@alexellis
Copy link

Very cool Akihiro - I think there will be a lot of interest for this.

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.

4 participants