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

podman: do not set rlimits to the default value #24228

Merged
merged 4 commits into from
Oct 15, 2024

Conversation

giuseppe
Copy link
Member

since the effect would be to lower the rlimits when their definition is higher than the default value.

The test doesn't fail on the previous version, unless the system is configured with a nofile ulimit higher than the default value.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2317721

Does this PR introduce a user-facing change?

None

@openshift-ci openshift-ci bot added release-note-none approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Oct 10, 2024
Copy link
Member

@Luap99 Luap99 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
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

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

I think we can do better in the test. Need some time to work on it.

@edsantiago
Copy link
Member

edsantiago commented Oct 10, 2024

This fails as root under old-podman, passes root+rootless with new-podman:

# #24228: podman used to set this to hardcoded value, ignoring current settings
# bats test_tags=ci:parallel
@test "podman run - can use maximum ulimit value" {
    skip_if_remote "cannot check local ulimits with podman remote"
    run -0 ulimit -n -H
    max=$output
    oldmax=$max

    # This test is more meaningful when root
    if ! is_rootless; then
        max=$((max + $RANDOM))
        ulimit -n -H $max
    fi
    run_podman run --rm $IMAGE sh -c 'ulimit -n -H'
    assert "$output" = "$max" "podman inherits parent ulimit"
    ulimit -n -H $oldmax
}

I removed the command-line --ulimit because (unless I read things very very wrong) that is entirely against the purpose of this PR. Again, I may be wrong.

I also noticed that, on my f40 system, this reduces the default root setting for podman:

$ for i in /usr/bin/podman bin/podman; do sudo $i run --rm quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
1048576
524288

Could that be considered a breaking change?

@Luap99
Copy link
Member

Luap99 commented Oct 10, 2024

I removed the command-line --ulimit because (unless I read things very very wrong) that is entirely against the purpose of this PR. Again, I may be wrong.

The --ulimit is needed here, the point is podman has a default limit that it sets for rootless containers (up to 1048576) even when the host allows more. So the point here is that if your host has more than that --ulimit must be able to set that value and should not be capped at 1048576 (default). This did not work because the podman init code capped the limit at 1048576 thus the bug report. And this only fails as rootless with limit higher than 1048576 because rootful has CAP_SYS_RESOURCE and can increase the limit higher all it wants.

We would need to bump the ulimit for our rootless CI user > 1048576 in order for this to even be testable.

What I do not get is a we do not document this rootless default and rootful seems to inherit and not use the 1048576 number but I am not sure why?

@giuseppe
Copy link
Member Author

This fails as root under old-podman, passes root+rootless with new-podman:

# #24228: podman used to set this to hardcoded value, ignoring current settings
# bats test_tags=ci:parallel
@test "podman run - can use maximum ulimit value" {
    skip_if_remote "cannot check local ulimits with podman remote"
    run -0 ulimit -n -H
    max=$output
    oldmax=$max

    # This test is more meaningful when root
    if ! is_rootless; then
        max=$((max + $RANDOM))
        ulimit -n -H $max
    fi
    run_podman run --rm $IMAGE sh -c 'ulimit -n -H'
    assert "$output" = "$max" "podman inherits parent ulimit"
    ulimit -n -H $oldmax
}

I removed the command-line --ulimit because (unless I read things very very wrong) that is entirely against the purpose of this PR. Again, I may be wrong.

I also noticed that, on my f40 system, this reduces the default root setting for podman:

$ for i in /usr/bin/podman bin/podman; do sudo $i run --rm quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
1048576
524288

Could that be considered a breaking change?

Thanks for noticing it. Yes, I think this should not happen.

I'll take a look

@giuseppe
Copy link
Member Author

/hold

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 10, 2024
@edsantiago
Copy link
Member

Okay, I have a 1mt with

/etc/security/limits.conf:*             hard    nofile          12345678

and:

# ulimit -n -H
12345678
# for i in /usr/bin/podman bin/podman; do $i run --rm quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
1048576     <<< expected
12345678    <<< expected

$ ulimit -n -H
12345678
$ for i in /usr/bin/podman bin/podman; do $i run --rm quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
1048576     <<< expected
1048576     <<< UNEXPECTED but that's probably because Ed is clueless

With the command-line option, your PR seems to do the right thing:

$ for i in /usr/bin/podman bin/podman; do $i run --rm --ulimit=nofile=12345678:12345678 quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
Error: crun: setrlimit `RLIMIT_NOFILE`: Operation not permitted: OCI permission denied
12345678

@giuseppe giuseppe force-pushed the do-not-lower-rlimits branch from 47ff5b1 to 88afdbb Compare October 10, 2024 15:58
@giuseppe
Copy link
Member Author

# ulimit -n -H
12345678
# for i in /usr/bin/podman bin/podman; do $i run --rm quay.io/libpod/testimage:20241010 sh -c 'ulimit -n -H';done
1048576     <<< expected
12345678    <<< expected

The first version of this PR was not correct, and this is wrong. It must be 1048576 in both cases to honor what the default is.

I've changed the behaviour of Podman in the last version to honor the default settings also with root.

@giuseppe giuseppe force-pushed the do-not-lower-rlimits branch from 88afdbb to 8b9ebd5 Compare October 11, 2024 07:52
@Luap99
Copy link
Member

Luap99 commented Oct 11, 2024

Please also document in the man page the the default nofile and nproc is 1048576 under the --ulimit option if we now also do this as root.

@giuseppe giuseppe force-pushed the do-not-lower-rlimits branch from 8b9ebd5 to 85fc7f9 Compare October 11, 2024 09:51
@giuseppe
Copy link
Member Author

Please also document in the man page the the default nofile and nproc is 1048576 under the --ulimit option if we now also do this as root.

thanks. I've added a note to the documentation but I prefer to not specify their value (if you really want them I can change it again) to not have to worry about them getting out of sync

@mheon
Copy link
Member

mheon commented Oct 11, 2024

LGTM

@Luap99
Copy link
Member

Luap99 commented Oct 11, 2024

Please also document in the man page the the default nofile and nproc is 1048576 under the --ulimit option if we now also do this as root.

thanks. I've added a note to the documentation but I prefer to not specify their value (if you really want them I can change it again) to not have to worry about them getting out of sync

I think it somewhat important, it is not like we randomly will change the values. Saying look in containers.conf but then thee is nothing in the containers.conf docs is confusing. I think most users really want to know the defaults and we document them in most cases but I am fine with not blocking over this and to merge without it

@damaestro
Copy link

It would have been nice to have this default documented when I was working through figuring out what was going on here.

@giuseppe
Copy link
Member Author

fine so I'll add it to the documentation.

Before that though, we need containers/common#2199

Not sure why we do that, but it is just wrong IMO: we set it to the maximum value possible, and we change the limits from a library

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
the previous implementation was expecting the rlimits to be set for the
entire process and clamping the values only when running as rootless.

Change the implementation to always specify the expected values in the
OCI spec file and do the clamping only when running as rootless and
using the default values.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
since the effect would be to lower the rlimits when their definition
is higher than the default value.

The test doesn't fail on the previous version, unless the system is
configured with a nofile ulimit higher than the default value.

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=2317721

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the do-not-lower-rlimits branch from 85fc7f9 to 9e1d001 Compare October 11, 2024 21:04
@giuseppe giuseppe added the bloat_approved Approve a PR in which binary file size grows by over 50k label Oct 11, 2024
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
@giuseppe giuseppe force-pushed the do-not-lower-rlimits branch from 9e1d001 to 3d57560 Compare October 11, 2024 21:24
@giuseppe
Copy link
Member Author

vendored the change in c/common and pushed a new version ⬆️

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

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

LGTM

@giuseppe
Copy link
Member Author

/hold cancel

@containers/podman-maintainers PTAL

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 15, 2024
Copy link
Member

@lsm5 lsm5 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 Oct 15, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, lsm5, Luap99

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:
  • OWNERS [Luap99,giuseppe,lsm5]

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

@rhatdan
Copy link
Member

rhatdan commented Oct 15, 2024

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 15, 2024
@openshift-merge-bot openshift-merge-bot bot merged commit d5be88e into containers:main Oct 15, 2024
82 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. bloat_approved Approve a PR in which binary file size grows by over 50k lgtm Indicates that a PR is ready to be merged. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants