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: Add --fakeroot support to --oci mode #1135

Merged
merged 1 commit into from
Nov 28, 2022
Merged

Conversation

dtrudg
Copy link
Member

@dtrudg dtrudg commented Nov 21, 2022

Description of the Pull Request (PR):

Implements initial --fakeroot support for --oci mode. Mirrors behavior with --compat / --contain.

The process of accomplishing this is fairly complex. In theory, we should be able to call crun directly from host namespaces. We can let crun create a default userns and user mapping, or be able to request arbitrary explicit uid mappings (permitted by /etc/subuid /etc/subgid) to be applied.

Unfortunately this can hit bugs as this path is not well tested in crun. See e.g.

To avoid requiring the very latest crun with fixes, instead move to creating a userns ourselves, with a 'fakeroot' ID mapping in place, and call crun from that. This is the kind of flow implemented in other runtimes that call crun, such as podman.... so crun is well tested with it.

We can use the singularity starter with the fakeroot engine ,and a minimal config, to create the userns and id mapping. We already use it this way to perform a simple rm cleanup in --fakeroot execution of a native singularity container. This approach avoids having to implement further C/Go executables, or making large imports, such as the reexec + unshare packages from github.com/containers/storage

We are now, by default, calling crun or runc with a fakeroot setup... with host uid/gid mapped to 0 inside the userns. This is default for most OCI runtimes, however singularity default is to preserve the host id.

We need to have (fake) root inside the userns for crun / runc to work properly... so to return to the host uid in the container we insert an inner user namespace / ID mapping request into the bundle config.json. This reverses the mapping, i.e.

  • User ID on host (1001)
  • Root in outer user namespace (0)
  • User ID in container (1001)

I've added a README.md in this PR, as things are rather complex:

https://github.com/sylabs/singularity/blob/9680663bb1eccbfade2de9f639e1e4be49ffb3bf/internal/pkg/runtime/launcher/oci/README.md

Note that there are likely still some rough edges, and the oci launcher package is getting toward the point where it should be split, but I don't want to add too much more to this single review.

This fixes or addresses the following GitHub issues:

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

@dtrudg dtrudg added the ci:e2e label Nov 21, 2022
@dtrudg dtrudg added this to the SingularityCE 3.11 milestone Nov 21, 2022
@dtrudg dtrudg self-assigned this Nov 21, 2022
@dtrudg dtrudg force-pushed the oci-fakeroot branch 16 times, most recently from 2ab8ec8 to a370a87 Compare November 25, 2022 15:39
Initial --fakeroot support for --oci mode. Mirrors behavior with
--compat / --contain.

Closes sylabs#1035
@dtrudg dtrudg marked this pull request as ready for review November 25, 2022 16:04
Copy link
Member

@tri-adam tri-adam left a comment

Choose a reason for hiding this comment

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

Phew, there's a lot here! Thank you very much for the added README... very helpful.

Haven't had a chance to test extensively myself, so approving based on code review. Will definitely be digging deeper early next week, and don't think there's any need to hold up merging if you're comfortable doing so.

@dtrudg
Copy link
Member Author

dtrudg commented Nov 28, 2022

Will merge this now, as there are a couple of small PRs to knock out next, and I can branch those of main then, instead of stacking the,.

@dtrudg dtrudg merged commit 5f6d753 into sylabs:main Nov 28, 2022
@dtrudg dtrudg deleted the oci-fakeroot branch November 28, 2022 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support '--fakeroot' with OCI launcher.
2 participants