mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-11 06:03:57 +08:00
runtime-spec: update pids.limit handling to match new guidance
The main update is actually in github.com/opencontainers/cgroups, but we need to also update runtime-spec to a newer pre-release version to get the updates from there as well. In short, the behaviour change is now that "0" is treated as a valid value to set in "pids.max", "-1" means "max" and unset/nil means "do nothing". As described in the opencontainers/cgroups PR, this change is actually backwards compatible because our internal state.json stores PidsLimit, and that entry is marked as "omitempty". So, an old runc would omit PidsLimit=0 in state.json, and this will be parsed by a new runc as being "nil" -- and both would treat this case as "do not set anything". Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
This commit is contained in:
@@ -526,20 +526,22 @@ func TestPidsSystemd(t *testing.T) {
|
||||
testPids(t, true)
|
||||
}
|
||||
|
||||
func mkPtr[T any](v T) *T { return &v }
|
||||
|
||||
func testPids(t *testing.T, systemd bool) {
|
||||
if testing.Short() {
|
||||
return
|
||||
}
|
||||
|
||||
config := newTemplateConfig(t, &tParam{systemd: systemd})
|
||||
config.Cgroups.Resources.PidsLimit = -1
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](-1)
|
||||
|
||||
// Running multiple processes, expecting it to succeed with no pids limit.
|
||||
runContainerOk(t, config, "/bin/sh", "-c", "/bin/true | /bin/true | /bin/true | /bin/true")
|
||||
|
||||
// Enforce a permissive limit. This needs to be fairly hand-wavey due to the
|
||||
// issues with running Go binaries with pids restrictions (see below).
|
||||
config.Cgroups.Resources.PidsLimit = 64
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
|
||||
runContainerOk(t, config, "/bin/sh", "-c", `
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
@@ -548,7 +550,7 @@ func testPids(t *testing.T, systemd bool) {
|
||||
|
||||
// Enforce a restrictive limit. 64 * /bin/true + 1 * shell should cause
|
||||
// this to fail reliably.
|
||||
config.Cgroups.Resources.PidsLimit = 64
|
||||
config.Cgroups.Resources.PidsLimit = mkPtr[int64](64)
|
||||
out, _, err := runContainer(t, config, "/bin/sh", "-c", `
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
/bin/true | /bin/true | /bin/true | /bin/true | /bin/true | /bin/true | bin/true | /bin/true |
|
||||
|
||||
Reference in New Issue
Block a user