fix(libcontainer): preserve rootfs slave propagation for rslave containers#5200
Conversation
|
Thanks, I'll take a look next week. One small request: please use |
739bdaa to
2a80f7b
Compare
lifubang
left a comment
There was a problem hiding this comment.
Thanks!
The patch looks correct, though I've left a few comments. Also, could you move the integration test to a separate commit? It would make it easier for maintainers to review the changes step-by-step.
| } | ||
| } | ||
|
|
||
| func TestRootfsParentMountPropagationFlags(t *testing.T) { |
There was a problem hiding this comment.
Nice, thanks for the detailed test cases.
There was a problem hiding this comment.
OTOH I don't think this test makes sense. The code which it tests is:
func rootfsParentMountPropagationFlags(rootPropagation int) uintptr {
if rootPropagation&unix.MS_SLAVE != 0 {
return unix.MS_SLAVE
}
return unix.MS_PRIVATE
}and I don't think this code is that complicated to deserve a test case. You can "test" it by just reading it.
More to say, if we ever want to change it for whatever reason, it's more work now (as the test cases will fail).
So I'd rather remove the unit test. @lifubang WDYT?
There was a problem hiding this comment.
In fact, I originally wanted to keep this unit test to ensure we wouldn’t forget MS_SLAVE during future refactoring. However, now that we have an integration test covering this behavior -- and although the logic is simple yet critical -- I think we can safely remove the unit test.
@xujihui1985
There was a problem hiding this comment.
ok, unittest for this function has been removed
928a051 to
dc1ae2a
Compare
|
@xujihui1985 you also need to run |
5e9e5e0 to
7e21150
Compare
7e21150 to
30275eb
Compare
Some of runc integration tests may do something that I would not like when running those on my development laptop. Examples include - changing the root mount propagation [1]; - replacing /root/runc [2]; - changing the file in /etc (see checkpoint.bats). Yet it is totally fine to do all that in a throwaway CI environment, or inside a Docker container. Introduce a mechanism to skip specific "unsafe" tests unless an environment variable, RUNC_ALLOW_UNSAFE_TESTS, is set. Use it from a specific checkpoint/restore test which modifies /etc/criu/default.conf. [1]: opencontainers#5200 [2]: opencontainers#5207 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
30275eb to
f77f958
Compare
Some of runc integration tests may do something that I would not like when running those on my development laptop. Examples include - changing the root mount propagation [1]; - replacing /root/runc [2]; - changing the file in /etc (see checkpoint.bats). Yet it is totally fine to do all that in a throwaway CI environment, or inside a Docker container. Introduce a mechanism to skip specific "unsafe" tests unless an environment variable, RUNC_ALLOW_UNSAFE_TESTS, is set. Use it from a specific checkpoint/restore test which modifies /etc/criu/default.conf. [1]: opencontainers#5200 [2]: opencontainers#5207 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
|
The test in this PR (which modifies / propagation) should benefit from the feature from #5212, so if that one is approved and merged, the test here needs to add require unsafe. |
Some of runc integration tests may do something that I would not like when running those on my development laptop. Examples include - changing the root mount propagation [1]; - replacing /root/runc [2]; - changing the file in /etc (see checkpoint.bats). Yet it is totally fine to do all that in a throwaway CI environment, or inside a Docker container. Introduce a mechanism to skip specific "unsafe" tests unless an environment variable, RUNC_ALLOW_UNSAFE_TESTS, is set. Use it from a specific checkpoint/restore test which modifies /etc/criu/default.conf. [1]: opencontainers#5200 [2]: opencontainers#5207 Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
f77f958 to
a191f22
Compare
14eafe9 to
d5951ea
Compare
3382d5d to
f15a20b
Compare
a09515f to
0d3e2ca
Compare
When rootfsPropagation is set to rslave, prepareRoot() was forcing the rootfs parent mount to MS_PRIVATE before bind-mounting and pivoting into the rootfs. That breaks the slave relationship needed for HostToContainer propagation, so later unmount/remount events on host mountpoints under the rootfs are not reflected inside the running container. Fix this by keeping the rootfs parent mount as MS_SLAVE for slave-like rootfs propagation settings, while leaving the final root propagation remount in place. Signed-off-by: sean <xujihui1985@gmail.com>
add bat integration test for rootfs propagation test, expect to see the mount propagation is slave, the test will create a isolate mntns to run the test as the test will mutate the rootfs propagation Signed-off-by: sean <xujihui1985@gmail.com>
0d3e2ca to
38245cc
Compare
|
@kolyshkin @lifubang Thanks for reviewing the MR. This was a great learning opportunity, and I learned a lot from this process. |
I set the 1.3.6 milestone because this bug affects all releases from 1.3.x through 1.5.x, and the impact is broader than it appears:
@xujihui1985 WDYT? |
|
Oh, looking at the actual OCI spec generated by Kubernetes/docker, there's no |
https://github.com/containerd/containerd/blob/f006ee06cabf52ee4a32429487b93d334c009589/internal/cri/opts/spec_linux_opts.go#L173
@lifubang I didn't test on the latest kubernetes and containerd, but from our internal version, the rootfsPropagation actually set on the bundle json, I'm not sure right now if this is a internal feature, I will check it later
|
Have you had a chance to look into it yet? |
Hi, I check the current upstream version from internal codebase, it's from 1.5.4, and it's not an internal logic, https://github.com/containerd/containerd/blob/v1.5.4/pkg/cri/opts/spec_linux.go#L180-L197 |
|
Thanks, this appears to be a long-standing bug. Do you think we should backport this to |

When rootfsPropagation is set to rslave, prepareRoot() was forcing the rootfs parent mount to MS_PRIVATE before bind-mounting and pivoting into the rootfs. That breaks the slave relationship needed for HostToContainer propagation, so later unmount/remount events on host mountpoints under the rootfs are not reflected inside the running container.
Fix this by keeping the rootfs parent mount as MS_SLAVE for slave-like rootfs propagation settings, while leaving the final root propagation remount in place.
Fixes: #5192