Skip to content

Conversation

@AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Oct 15, 2018

Signed-off-by: Akihiro Suda suda.akihiro@lab.ntt.co.jp

- What I did

Ubuntu kernel supports overlayfs in user namespaces.

However, Docker had previously crafting overlay opaques directly
using mknod(2) and setxattr(2), which are not supported in userns.

This PR allows pkg/archive to craft opaques by creating overlayfs rather than mknod/setxattr.

Tested with LXD, Ubuntu 18.04, kernel 4.15.0-36-generic #39-Ubuntu.

Cherry-picked from Usernetes patch set: https://github.com/rootless-containers/usernetes

- How I did it

mknod c 0 0:

  • Mkdir lower,upper,merged,work
  • Create lower/dummy
  • Mount overlayfs
  • Unlink merged/dummy
  • Unmount overlayfs
  • The 0,0 character node is ready as upper/dummy

mkdir with trusted.overlay.opaque xattr:

  • Mkdir lower,upper,merged,work
  • Mkdir lower/dummy
  • Mount overlayfs
  • Rmdir merged/dummy
  • Mkdir merged/dummy
  • Unmount overlayfs
  • The dir with trusted.overlay.opaque xattr is ready as upper/dummy

- How to verify it

Without patch, docker pull ubuntu fails as follows:

root@c0:~# docker version
Client:
 Version:           master-dockerproject-2018-10-14
 API version:       1.39
 Go version:        go1.11.1
 Git commit:        d18aad38
 Built:             Sun Oct 14 23:42:14 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
 Engine:
  Version:          master-dockerproject-2018-10-14
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.11.1
  Git commit:       ee6fc90
  Built:            Sun Oct 14 23:51:03 2018
  OS/Arch:          linux/amd64
  Experimental:     false
root@c0:~# docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
124c757242f8: Pull complete 
9d866f8bde2a: Pull complete 
fa3f2f277e67: Extracting [==================================================>]     469B/469B
398d32b153e8: Download complete 
afde35469481: Download complete 
failed to register layer: Error processing tar file(exit status 1): operation not permitted

- Description for the changelog

pkg/archive: support overlayfs in userns (Ubuntu kernel only)

- A picture of a cute animal (not mandatory but encouraged)
🐧

@AkihiroSuda
Copy link
Member Author

cc @brauner @stgraber @dmcgowan

@AkihiroSuda
Copy link
Member Author

also cc @dhiltonp

@estesp
Copy link
Contributor

estesp commented Oct 15, 2018

Looks good @AkihiroSuda; windows CI failure looks to be a teardown test flake; unrelated to changes

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

I haven't validated this yet, but just a minor comment on the code.

Copy link
Member

Choose a reason for hiding this comment

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

Instead of the if/else here, could we have a wrapper for the userns case that catches the error and handles accordingly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Could you be more specific?

Copy link
Member

Choose a reason for hiding this comment

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

I was thinking we could just wrap ConverRead with something like if err := c.wrapped.ConvertRead(...); err != nil && c.isInUserNS {...}

But looking back now, I think that may not be all that clean.

@thaJeztah
Copy link
Member

/cc @dmcgowan @tonistiigi

@codecov
Copy link

codecov bot commented Oct 19, 2018

Codecov Report

❗ No coverage uploaded for pull request base (master@6e3113f). Click here to learn what that means.
The diff coverage is 8.82%.

@@            Coverage Diff            @@
##             master   #38038   +/-   ##
=========================================
  Coverage          ?   36.53%           
=========================================
  Files             ?      610           
  Lines             ?    45371           
  Branches          ?        0           
=========================================
  Hits              ?    16575           
  Misses            ?    26467           
  Partials          ?     2329

Copy link
Member

Choose a reason for hiding this comment

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

(only glancing over the code); It's not an exported function, so not a big deal; just thinking if it would be cleaner to pass the options struct, instead of adding a boolean

Copy link
Member Author

Choose a reason for hiding this comment

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

What would be other fields of options?

Copy link
Member

Choose a reason for hiding this comment

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

not sure 😅 . My train of thought was that in case more options appeared in future, we didn't have to change the signature

@thaJeztah
Copy link
Member

ping @cpuguy83 @dmcgowan @tonistiigi PTAL

@AkihiroSuda
Copy link
Member Author

ping @cpuguy83 @dmcgowan @tonistiigi

@cpuguy83
Copy link
Member

This seems sane. Is there a good way we can add this to the test suite?

@AkihiroSuda
Copy link
Member Author

As this is Ubuntu-specific and planned to be deprecated in favor of containerd overlay snapshotter, I think manual testing is ok for now

@cpuguy83
Copy link
Member

IMO, if it's not worth adding tests for it's not worth merging.

@AkihiroSuda
Copy link
Member Author

Added TestReexecUserNSOverlayWhiteoutConverter.

The test passed locally on Ubuntu 18.04.1, kernel 4.15.0-39-generic #42-Ubuntu

@AkihiroSuda
Copy link
Member Author

The PR now contains commit from #38292 so that the PR can be tested on recent kernels.

Copy link
Member

Choose a reason for hiding this comment

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

I'm sure I don't know what this is doing, but why do we mention v3 and set 2 here, and then check 2 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.

2 is just a filename and had nothing to do with the version

Copy link
Member

@cpuguy83 cpuguy83 left a comment

Choose a reason for hiding this comment

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

LGTM

Ubuntu kernel supports overlayfs in user namespaces.

However, Docker had previously crafting overlay opaques directly
using mknod(2) and setxattr(2), which are not supported in userns.

Tested with LXD, Ubuntu 18.04, kernel 4.15.0-36-generic moby#39-Ubuntu.

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
`rootlesskit go test ./pkg/archive` now succeeds

Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
@AkihiroSuda
Copy link
Member Author

rebased the PR, as #38292 got merged

@dmcgowan PTAL?

@tonistiigi tonistiigi assigned dmcgowan and unassigned MHBauer Dec 13, 2018
@AkihiroSuda
Copy link
Member Author

@cpuguy83 @tonistiigi @dmcgowan mergeable?

@AkihiroSuda
Copy link
Member Author

ping @cpuguy83 @tonistiigi @dmcgowan

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

LGTM 🐯

@vdemeester vdemeester merged commit de640c9 into moby:master Jan 4, 2019
@thaJeztah
Copy link
Member

@dmcgowan let us know if there's any changes needed after-the-fact 🤗

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.

9 participants