-
Notifications
You must be signed in to change notification settings - Fork 1.4k
oci-worker: experimental support for rootless mode #419
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,21 +69,37 @@ func main() { | |
| app := cli.NewApp() | ||
| app.Name = "buildkitd" | ||
| app.Usage = "build daemon" | ||
|
|
||
| app.Flags = []cli.Flag{ | ||
| defaultRoot := appdefaults.Root | ||
| defaultAddress := appdefaults.Address | ||
| rootlessUsage := "set all the default options to be compatible with rootless containers" | ||
| if runningAsUnprivilegedUser() { | ||
| app.Flags = append(app.Flags, cli.BoolTFlag{ | ||
| Name: "rootless", | ||
| Usage: rootlessUsage + " (default: true)", | ||
| }) | ||
| defaultRoot = appdefaults.UserRoot() | ||
| defaultAddress = appdefaults.UserAddress() | ||
| appdefaults.EnsureUserAddressDir() | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| } else { | ||
| app.Flags = append(app.Flags, cli.BoolFlag{ | ||
| Name: "rootless", | ||
| Usage: rootlessUsage, | ||
| }) | ||
| } | ||
| app.Flags = append(app.Flags, | ||
| cli.BoolFlag{ | ||
| Name: "debug", | ||
| Usage: "enable debug output in logs", | ||
| }, | ||
| cli.StringFlag{ | ||
| Name: "root", | ||
| Usage: "path to state directory", | ||
| Value: appdefaults.Root, | ||
| Value: defaultRoot, | ||
| }, | ||
| cli.StringSliceFlag{ | ||
| Name: "addr", | ||
| Usage: "listening address (socket or tcp)", | ||
| Value: &cli.StringSlice{appdefaults.Address}, | ||
| Value: &cli.StringSlice{defaultAddress}, | ||
| }, | ||
| cli.StringFlag{ | ||
| Name: "group", | ||
|
|
@@ -107,8 +123,7 @@ func main() { | |
| Name: "tlscacert", | ||
| Usage: "ca certificate to verify clients", | ||
| }, | ||
| } | ||
|
|
||
| ) | ||
| app.Flags = append(app.Flags, appFlags...) | ||
|
|
||
| app.Action = func(c *cli.Context) error { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // +build linux | ||
|
|
||
| package main | ||
|
|
||
| import "github.com/opencontainers/runc/libcontainer/system" | ||
|
|
||
| func runningAsUnprivilegedUser() bool { | ||
| return system.GetParentNSeuid() != 0 || system.RunningInUserNS() | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // +build !linux | ||
|
|
||
| package main | ||
|
|
||
| func runningAsUnprivilegedUser() bool { | ||
| return false | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| # Rootless mode (Experimental) | ||
|
|
||
| Requirements: | ||
| - runc (May 30, 2018) or later | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we update
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably after we have the tool for setting up The test has been substantially covered in genuinetools/img. |
||
| - Some distros such as Debian and Arch Linux require `echo 1 > /proc/sys/kernel/unprivileged_userns_clone` | ||
| - `newuidmap` and `newgidmap` need to be installed on the host. These commands are provided by the `uidmap` package. | ||
| - `/etc/subuid` and `/etc/subgid` should contain >= 65536 sub-IDs. e.g. `penguin:231072:65536`. | ||
| - 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. | ||
|
|
||
| ## Terminal 1: | ||
|
|
||
| ``` | ||
| $ unshare -U -m | ||
| unshared$ echo $$ > /tmp/pid | ||
| ``` | ||
|
|
||
| Unsharing mountns (and userns) is required for mounting filesystems without real root privileges. | ||
|
|
||
| ## Terminal 2: | ||
|
|
||
| ``` | ||
| $ id -u | ||
| 1001 | ||
| $ grep $(whoami) /etc/subuid | ||
| penguin:231072:65536 | ||
| $ grep $(whoami) /etc/subgid | ||
| penguin:231072:65536 | ||
| $ newuidmap $(cat /tmp/pid) 0 1001 1 1 231072 65536 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. recommend installing |
||
| $ newgidmap $(cat /tmp/pid) 0 1001 1 1 231072 65536 | ||
| ``` | ||
|
|
||
| ## Terminal 1: | ||
|
|
||
| ``` | ||
| unshared# buildkitd | ||
| ``` | ||
|
|
||
| * The data dir will be set to `/home/penguin/.local/share/buildkit` | ||
| * The address will be set to `unix:///run/user/1001/buildkit/buildkitd.sock` | ||
| * `overlayfs` snapshotter is not supported except Ubuntu-flavored kernel: http://kernel.ubuntu.com/git/ubuntu/ubuntu-artful.git/commit/fs/overlayfs?h=Ubuntu-4.13.0-25.29&id=0a414bdc3d01f3b61ed86cfe3ce8b63a9240eba7 | ||
| * containerd worker is not supported ( pending PR: https://github.com/containerd/containerd/pull/2006 ) | ||
| * Network namespace is not used at the moment. | ||
|
|
||
| ## Terminal 2: | ||
|
|
||
| ``` | ||
| $ go get ./examples/build-using-dockerfile | ||
| $ build-using-dockerfile --buildkit-addr unix:///run/user/1001/buildkit/buildkitd.sock -t foo /path/to/somewhere | ||
| ``` | ||
There was a problem hiding this comment.
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