Skip to content

feat: Allow containers to use both host network and user namespace#12518

Merged
AkihiroSuda merged 3 commits intocontainerd:mainfrom
HirazawaUi:support-hostnetwork-userns
Mar 30, 2026
Merged

feat: Allow containers to use both host network and user namespace#12518
AkihiroSuda merged 3 commits intocontainerd:mainfrom
HirazawaUi:support-hostnetwork-userns

Conversation

@HirazawaUi
Copy link
Copy Markdown
Contributor

@HirazawaUi HirazawaUi commented Nov 16, 2025

This PR implements the feature proposed in KEP: kubernetes/enhancements#5607 for containerd.

This PR modifies the behavior to use bind mounts for /sys when a pod employs both hostNetwork and user namespace.

relate: #12489

Allow containers to use user namespaces with host networking

@github-project-automation github-project-automation Bot moved this to Needs Triage in Pull Request Review Nov 16, 2025
@dosubot dosubot Bot added the area/cri Container Runtime Interface (CRI) label Nov 16, 2025
@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 23b8502 to da87ae8 Compare November 27, 2025 14:16
@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from da87ae8 to 4043d30 Compare November 27, 2025 14:18
@HirazawaUi HirazawaUi changed the title WIP: Allow user namespace with hostNetwork in pod sandbox feat: Allow use user namespace with host network in container Nov 27, 2025
@HirazawaUi HirazawaUi changed the title feat: Allow use user namespace with host network in container feat: Allow containers to use both host network and user namespace Dec 3, 2025
@mikebrow
Copy link
Copy Markdown
Member

mikebrow commented Dec 3, 2025

Hello! see: " FAIL - does not have a valid DCO" All commits must be signed. Suggest setting your git config to have user name and email.. Then git commit -s --amend to sign your commit." Detail: https://github.com/containerd/project/blob/main/CONTRIBUTING.md#sign-your-work

@mikebrow mikebrow self-assigned this Dec 3, 2025
@mikebrow
Copy link
Copy Markdown
Member

mikebrow commented Dec 3, 2025

note to self.. needs feature issue for tracking support of the case.

@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 4043d30 to 97c1095 Compare December 4, 2025 14:00
@HirazawaUi
Copy link
Copy Markdown
Contributor Author

Hello! see: " FAIL - does not have a valid DCO" All commits must be signed. Suggest setting your git config to have user name and email.. Then git commit -s --amend to sign your commit." Detail: https://github.com/containerd/project/blob/main/CONTRIBUTING.md#sign-your-work

Signed

Copy link
Copy Markdown
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

Oh, I missed this PR was open, sorry! Thanks a lot for the PR.

The code looks good, simple and effective. I've tested it locally and works as expected.

I've revisited #10607 to make sure I wasn't forgetting any reason to pin the userns. But no, the pinning is just needed because the netns is created by containerd and, therefore, the userns needs to be created by containerd (since that PR, before we were letting runc create it for us).

So, when no netns is created (using the host netns), the pinning is not needed. So, just skping it and adding the /sys bind mount works just fine, with both runc and crun. This is a quite an elegant solution :)

IMHO now is safe to add tests, as everything works and IMHO looks good. For that, please check TestLinuxSandboxContainerSpec() and TestLinuxSandboxContainerSpec() to test the changes in these two functions. There are quite a bunch of userns tests you can check. For the not pinned userns, see the specCheck func in the user namespace test case. You can use something similar but with assert.NotContains, for example.

Please ping me when tests are ready and thanks again for the PR! :)

@mikebrow mikebrow force-pushed the support-hostnetwork-userns branch from 97c1095 to 5c45615 Compare December 19, 2025 15:29
@rata
Copy link
Copy Markdown
Contributor

rata commented Dec 19, 2025

Also, can you update the PR description? The runc pr is not needed.

Comment thread internal/cri/server/container_create.go
@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 5c45615 to 9f843b3 Compare December 21, 2025 14:36
@HirazawaUi
Copy link
Copy Markdown
Contributor Author

Also, can you update the PR description? The runc pr is not needed.

updated.

Please ping me when tests are ready and thanks again for the PR! :)

Unit tests have been added.

@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 9f843b3 to 89b5612 Compare December 21, 2025 14:39
Copy link
Copy Markdown
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

Thanks!

Sorry, my previous suggestion was wrong. Let's change back that code :-/

Comment thread internal/cri/server/container_create.go Outdated
Comment thread internal/cri/server/container_create_linux_test.go
Comment thread internal/cri/server/container_create_linux_test.go Outdated
@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 89b5612 to 114fd58 Compare December 22, 2025 15:14
Copy link
Copy Markdown
Contributor

@rata rata left a comment

Choose a reason for hiding this comment

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

This mostly LGTM, left some comments on the tests (on the existing threads we had).

@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 114fd58 to 200b05f Compare January 3, 2026 15:50
@HirazawaUi
Copy link
Copy Markdown
Contributor Author

@HirazawaUi can you push again? Checking quickly the CI failure seems unrelated, but without a green CI this might not get a lot of attention :(

I have recommited it

@rata
Copy link
Copy Markdown
Contributor

rata commented Mar 17, 2026

@HirazawaUi CI is still broken :(

@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch 2 times, most recently from 8317fba to 76bbb4b Compare March 21, 2026 15:24
@HirazawaUi
Copy link
Copy Markdown
Contributor Author

@mikebrow all tests have passed. Could you please approve this PR?

@HirazawaUi HirazawaUi force-pushed the support-hostnetwork-userns branch from 76bbb4b to 50e372b Compare March 22, 2026 04:12
@rata
Copy link
Copy Markdown
Contributor

rata commented Mar 27, 2026

CI is broken (windows, so unrelated). Can you push again?

@samuelkarp
Copy link
Copy Markdown
Member

/retest

(you can do this too, it should rerun the failing GitHub Actions workflows)

@rata
Copy link
Copy Markdown
Contributor

rata commented Mar 30, 2026

Oh, I missed containerd suppoted this! Cool, CI is green now, PTAL :)

@AkihiroSuda AkihiroSuda enabled auto-merge March 30, 2026 10:15
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
Signed-off-by: HirazawaUi <695097494plus@gmail.com>
@mikebrow mikebrow force-pushed the support-hostnetwork-userns branch from 50e372b to 339b0cc Compare March 30, 2026 14:01
Copy link
Copy Markdown
Member

@mikebrow mikebrow left a comment

Choose a reason for hiding this comment

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

LGTM
/cc @MikeZappa87

@github-project-automation github-project-automation Bot moved this from Needs Triage to Review In Progress in Pull Request Review Mar 30, 2026
@AkihiroSuda AkihiroSuda added this pull request to the merge queue Mar 30, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Mar 30, 2026
@AkihiroSuda AkihiroSuda added this pull request to the merge queue Mar 30, 2026
Merged via the queue into containerd:main with commit 6667c76 Mar 30, 2026
52 of 54 checks passed
@github-project-automation github-project-automation Bot moved this from Review In Progress to Done in Pull Request Review Mar 30, 2026
@AkihiroSuda AkihiroSuda added this to the 2.3 milestone Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cri Container Runtime Interface (CRI) impact/changelog size/L

Projects

Development

Successfully merging this pull request may close these issues.

7 participants