Allow containers to use both host network and user namespace#9634
Conversation
|
Hi @HirazawaUi. Thanks for your PR. I'm waiting for a github.com member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
WalkthroughFetches sandbox ID mappings before preparing sysfs mounts and passes both the sandbox and mappings into addSysfsMounts; addSysfsMounts signature updated across platforms and Linux sysfs mounting now branches based on presence of user namespace mappings. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
|
Thank youf for the PR @HirazawaUi, please sign-off your commit. /ok-to-test |
4c89848 to
3a70524
Compare
3a70524 to
dfe7542
Compare
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: giuseppe, HirazawaUi The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/lgtm cancel Please fix the linter: https://github.com/cri-o/cri-o/actions/runs/19898717159/job/57037105155?pr=9634 |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #9634 +/- ##
==========================================
- Coverage 66.97% 66.90% -0.07%
==========================================
Files 205 205
Lines 28826 28842 +16
==========================================
- Hits 19306 19298 -8
- Misses 7867 7890 +23
- Partials 1653 1654 +1 🚀 New features to boost your workflow:
|
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
dfe7542 to
6bb8a38
Compare
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
server/container_create_linux.go (1)
870-871: Tidy upaddSysfsMountsparameters and userns detection (optional)Two minor cleanups you might consider:
sb *sandbox.Sandboxis currently unused in this helper; if you don’t plan to use it soon, you could drop it to keep the function signature minimal and avoid potential linter complaints about unused parameters.- If there’s any chance of passing an “empty” but non‑nil
IDMappings,usernsEnabledcould track that more explicitly:-func addSysfsMounts(ctr ctrfactory.Container, containerConfig *types.ContainerConfig, hostNet bool, sb *sandbox.Sandbox, containerIDMappings *idtools.IDMappings) { - usernsEnabled := containerIDMappings != nil +func addSysfsMounts(ctr ctrfactory.Container, containerConfig *types.ContainerConfig, hostNet bool, sb *sandbox.Sandbox, containerIDMappings *idtools.IDMappings) { + usernsEnabled := containerIDMappings != nil && !containerIDMappings.Empty()Not mandatory, but would make the intent around “userns actually in use” a bit clearer.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
server/container_create.go(1 hunks)server/container_create_freebsd.go(2 hunks)server/container_create_linux.go(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- server/container_create.go
- server/container_create_freebsd.go
🧰 Additional context used
📓 Path-based instructions (1)
**/*.go
📄 CodeRabbit inference engine (AGENTS.md)
**/*.go: Use interface-based design and dependency injection patterns in Go code
Propagate context.Context through function calls in Go code
Usefmt.Errorfwith%wfor error wrapping in Go code
Use logrus with structured fields for logging in Go code
Add comments explaining 'why' not 'what' in Go code
Use platform-specific file naming:*_{linux,freebsd}.gofor platform-dependent code
Files:
server/container_create_linux.go
🧬 Code graph analysis (1)
server/container_create_linux.go (2)
internal/oci/container.go (1)
Container(44-92)internal/factory/container/container.go (1)
Container(40-142)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (18)
- GitHub Check: rpm-build:fedora-rawhide-x86_64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-aarch64:fedora-rawhide
- GitHub Check: rpm-build:fedora-rawhide-aarch64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-aarch64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-x86_64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-rawhide-x86_64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-aarch64:fedora-rawhide
- GitHub Check: rpm-build:fedora-rawhide-aarch64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-aarch64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-aarch64:fedora-rawhide
- GitHub Check: rpm-build:centos-stream-9-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-rawhide-aarch64:fedora-rawhide
- GitHub Check: rpm-build:fedora-rawhide-x86_64:fedora-rawhide
- GitHub Check: rpm-build:fedora-43-aarch64:fedora-rawhide
🔇 Additional comments (1)
server/container_create_linux.go (1)
870-898: HostNetwork + userns handling for/sysand cgroups looks correctThe new
usernsEnabledbranch that bind‑mounts/sysfor hostNetwork pods with user namespaces cleanly avoids re‑mounting sysfs in that configuration, while the non‑userns path still mounts a fresh sysfs plus the cgroup filesystem as before. This keeps existing behavior for non‑userns pods and aligns with the KEP intent for hostNetwork+userns pods, including interaction withhasCgroupMount/setupSystemd.
Thanks for the heads up. The lint error has been fixed. |
|
/lgtm |
|
/retest |
1 similar comment
|
/retest |
| } | ||
|
|
||
| func addSysfsMounts(ctr ctrfactory.Container, containerConfig *types.ContainerConfig, hostNet bool) { | ||
| func addSysfsMounts(ctr ctrfactory.Container, containerConfig *types.ContainerConfig, hostNet bool, sb *sandbox.Sandbox, containerIDMappings *idtools.IDMappings) { |
There was a problem hiding this comment.
I think this would be better as hostUser and do the usernsEnabled check in the caller. WDYT?
There was a problem hiding this comment.
Of course. This code was modified in PR #9660, and some additional cleanup was performed.
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
Follow up on PR #9634 to clean up redundant code
What type of PR is this?
/kind feature
What this PR does / why we need it:
This is the implementation of KEP-5607 in cri-o.
In KEP-5607, we allow containers to use both user namespace and host network simultaneously. This requires us to change the sys mount to a bind mount when the user employs both user namespace and host network, because mounting sys in the standard way is a privileged operation, which would prevent the container from using the standard /sys mount.
Which issue(s) this PR fixes:
Special notes for your reviewer:
Does this PR introduce a user-facing change?
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.