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

chroot: on Linux, try to pivot_root before falling back to chroot #5874

Merged
merged 1 commit into from
Dec 13, 2024

Conversation

nalind
Copy link
Member

@nalind nalind commented Dec 12, 2024

Unless --no-pivot or the equivalent API flag is set, try to pivot_root() to enter the rootfs during Run(). Fall back to using chroot() as before if that fails for any reason.

What type of PR is this?

/kind design

What this PR does / why we need it:

When using chroot isolation, if we can pivot_root() instead of using chroot() for running the command, do that, because it's closer to what a proper runtime can do.

How to verify it

Extended unit tests!

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

We still need chroot() for things like unpacking layers while pulling images, so if you're hoping this means we no longer ever need CAP_SYS_CHROOT, sorry.

Does this PR introduce a user-facing change?

`buildah build` or `buildah run` with `--isolation chroot` will now default to using pivot_root() internally, unless the `--no-pivot` CLI flag is used.

@openshift-ci openshift-ci bot added kind/design Categorizes issue or PR as related to design. approved labels Dec 12, 2024
Unless --no-pivot or the equivalent API flag is set, try to pivot_root()
to enter the rootfs during Run().  Fall back to using chroot() as before
if that fails for any reason.

Signed-off-by: Nalin Dahyabhai <[email protected]>
@rhatdan
Copy link
Member

rhatdan commented Dec 13, 2024

LGTM
@giuseppe @flouthoc @mtrmac PTAL

Copy link
Member

@giuseppe giuseppe 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

openshift-ci bot commented Dec 13, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, nalind

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit cf7d80a into containers:main Dec 13, 2024
19 checks passed
@nalind nalind deleted the chroot-pivot-root branch December 13, 2024 20:12
if err := RunUsingChroot(g.Config, bundleDir, "/", new(bytes.Buffer), output, output); err != nil {
t.Fatalf("run: %v: %s", err, output.String())
if err := RunUsingChroot(g.Config, bundleDir, "/", new(bytes.Buffer), output, output, noPivot); err != nil {
t.Fatalf("run(noPivot=false): %v: %s", err, output.String())
Copy link
Member Author

Choose a reason for hiding this comment

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

Ugh, just spotted the literal "=false" instead of using the passed-in value, opened #5876 to fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved kind/design Categorizes issue or PR as related to design. lgtm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants