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

Set workable permissions on OCI -> sandbox rootless builds #4522

Merged
merged 1 commit into from
Oct 2, 2019
Merged

Set workable permissions on OCI -> sandbox rootless builds #4522

merged 1 commit into from
Oct 2, 2019

Conversation

dtrudg
Copy link
Contributor

@dtrudg dtrudg commented Sep 25, 2019

Description of the Pull Request (PR):

We previously used a patched version of image-tools to extract OCI layers into a rootfs. This was patched to ensure all files and dirs extracted from a layer had minimum permissions such that when performing a rootless sandbox build:

  1. overwrites from subsequent layers succeeded even over files with 000 or similar permissions
  2. the rootfs could be moved and deleted by the non-root user/owner

In 3.4.0 we switched to umoci for extractions, as it is more faithful to the content of the layers than image-tools. umoci handles (1) above. However, we need to fix (2) ourself, as umoci will faithfully create a rootfs with 000 files in it, which cannot be moved or trivially rm'd by the non-root user.

This fixes or addresses the following GitHub issues:

Before submitting a PR, make sure you have done the following:

Attn: @singularity-maintainers

@dtrudg dtrudg self-assigned this Sep 25, 2019
jmstover
jmstover previously approved these changes Sep 25, 2019
Copy link
Contributor

@jmstover jmstover left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@ikaneshiro ikaneshiro left a comment

Choose a reason for hiding this comment

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

looks good. Fixes the issue when testing locally for me

e2e/imgbuild/imgbuild.go Outdated Show resolved Hide resolved
e2e/imgbuild/imgbuild.go Outdated Show resolved Hide resolved
internal/pkg/build/sources/oci_unpack_linux.go Outdated Show resolved Hide resolved
internal/pkg/build/sources/oci_unpack_linux.go Outdated Show resolved Hide resolved
@DrDaveD
Copy link
Collaborator

DrDaveD commented Sep 25, 2019

I did a build with this patch to test it, and it works with setuid-root singularity, but I still get this error when I run with -u:

INFO:    Starting build...
INFO:    Building into existing container: /cloud/login/dwd/scratch/centos7-sandbox
FATAL:   While performing build: failed to retrieve path for /cloud/login/dwd/scratch/centos7-sandbox: lstat /cloud/login/dwd/scratch/centos7-sandbox: no such file or directory

@dtrudg
Copy link
Contributor Author

dtrudg commented Sep 25, 2019

@DrDaveD - thanks... I think that is another somewhat separate issue. I think I need to ask @cclerget to look at that . I'll try to split the different issues out into separate things tomorrow morning.

e2e/internal/e2e/fileutil.go Outdated Show resolved Hide resolved
e2e/regressions/build.go Outdated Show resolved Hide resolved
e2e/regressions/build.go Outdated Show resolved Hide resolved
e2e/regressions/build.go Outdated Show resolved Hide resolved
@dtrudg
Copy link
Contributor Author

dtrudg commented Sep 26, 2019

Noting here that I chatted with @mem out of band on this, with particular reference to the comment above.

The current state of this work is that:

Upshot is that I don't think this should be rushed for a 3.4.2. It is probably wise there is some thought on it over the weekend, and that it is picked up in the working group meeting Sylabs developers have, and we look to comment from other developers here too.

@dtrudg
Copy link
Contributor Author

dtrudg commented Oct 1, 2019

There has been some general discussion about the permissions issue, thinking about the context of changes for 3.4.2 and a future 3.5.0. To summarize, general consensus is that:

  1. Not mangling permissions would be the 'right' thing to do, to ensure that a sandbox is faithful to the upstream layer content. Switching to umoci was partly to pursue this aim (ref Importing docker image results in incorrect file permissions #3880). A faithful sandbox should be an ultimate goal.
  2. Incorporating the non-relocation of sandboxes from master into a 3.4.2 would prevent build failures, create faithful sandboxes, but leave them unable to be removed without changing permissions. This is against user expectations since 2.x and we have many users who are likely unfamiliar with the consequences of owned, but 000 files, leaving them to believe that faithful permissions are an 'error' in our extraction.

Note that with regard to the above, as @mem has pointed out above, you can create true 000 files in a sandbox via build from definition file etc. which would lead to the 'surprise' when a user tries to copy/move/delete a sandbox. Therefore we have inconsistency here, and the 'correct' way to resolve it agrees with (1)... that we should be faithful to permissions specified in any source.

With these points in mind, we plan to move forward to:

  1. Bring back permission mangling to 3.4.2 to restore the previous behavior so that there is no surprise for users in the 3.4 series. This will likely be accomplished via a (revised?) version of this PR... to the 3.4 branch only.
  2. Do not mangle permissions in master. Raise the topic with the community via all routes. Explore if we can e.g. warn users about 000 perms and consequences when building a sandbox, and/or provide a command to remove such a sandbox. Take the temperature of the community for the balance of 'faithful sandbox permissions' vs 'no surprises'.

@dtrudg dtrudg changed the title Set workable permissions on OCI -> sandbox rootless builds [WIP] Set workable permissions on OCI -> sandbox rootless builds Oct 1, 2019
@dtrudg
Copy link
Contributor Author

dtrudg commented Oct 1, 2019

Setting WIP on this as need to ensure the perm change only comes in on sandbox destinations, and not in oci->sandbox->sif intermediate step to avoid regressing on #3880 in sif (via a different mechanism)

@dtrudg
Copy link
Contributor Author

dtrudg commented Oct 1, 2019

Well - turns out we cant do the perm change on only sandbox destinations as we will hit #4532 then. Will revert to the full <=3.3. behavior of modifying perms directly on OCI extraction. This means that with regard to #3880 permissions changes on subsequent layers are honored properly during umoci extraction, but then mangled by us... so may not match 100% docker perms, even in a SIF.

#4532 is going to need to be addressed by different means on master if we are not going to mangle permissions - as the faithful container permissions after extraction prevent insertion of some files we put / modify in the container.

This fix addresses #4524, where the recent change to use the umoci
extracter for OCI layers can lead to sandboxes that cannot be mv'd across
filesystems (leading to a build failure), or deleted/modified by the
user.

Return to the <=3.3 behaviour here, by modifying permissions on the
temporary rootfs sandbox once it is extracted, and before the mv to
its final location.
@dtrudg dtrudg changed the title [WIP] Set workable permissions on OCI -> sandbox rootless builds Set workable permissions on OCI -> sandbox rootless builds Oct 1, 2019
@dtrudg dtrudg requested review from mem and jmstover October 1, 2019 19:59
Copy link
Contributor

@mem mem left a comment

Choose a reason for hiding this comment

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

It looks good for what we need right now.

Note that because walk is doing a depth-first traversal, and because readDirNames is reading all the directory entries at once, this is going to consume quite a bit of memory for large and deep directory structures (it's going to allocate memory for all the entries in a directory, recurse into one directory, allocate memory for all the entries there and keep going until it finds a directory without any further subdirectories; only when going back up it's going to start releasing the slices it allocated along the way). No need to fix this right now, but it's worth keeping it in mind.

@dtrudg dtrudg mentioned this pull request Oct 2, 2019
5 tasks
@dtrudg dtrudg merged commit bf3e7d6 into apptainer:release-3.4 Oct 2, 2019
@DrDaveD
Copy link
Collaborator

DrDaveD commented Oct 23, 2019

Note for those looking at this in the future: this fix is only in the 3.4 branch. At this time the master (3.5) branch does not always make directories user-writable (and therefore deletable) and the current plan is to not change the permissions there, even though it is not backward compatible, in order to make it more compatible with other OCI compliant tools.

@dtrudg
Copy link
Contributor Author

dtrudg commented Oct 23, 2019

With regard to the above comment, we have discussion sought on the mailing list here: https://groups.google.com/a/lbl.gov/forum/#!topic/singularity/wScrzv7_fxc

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.

5 participants