← Back to Pull requests

Add KUBEVIRT_VSOCK_CHILD_NS_MODE #1720

Merged
Ruclo merged 6 files (123 lines) on Jun 12, 2026 23:40 UTC
View on GitHub
Ruclo Ruclo commented on May 27, 2026 12:30 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:
1. Consider creating this PR as draft: https://github.com/kubevirt/kubevirt/blob/main/CONTRIBUTING.md#consider-opening-your-pull-request-as-draft
2. Follow the instructions for writing a release note from k8s: https://git.k8s.io/community/contributors/guide/release-notes.md
-->

What this PR does / why we need it:
Adds a new cluster-up option to set net.vsock.child_ns_mode on each node via modprobe vsock + sysctl. Example usage: KUBEVIRT_VSOCK_CHILD_NS_MODE=local make cluster-up.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Fixes #https://redhat.atlassian.net/browse/CNV-86488

Special notes for your reviewer:

Checklist

This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.

  • Design: A design document was considered and is present (link) or not required

  • PR: The PR description is expressive enough and will help future contributors

  • Code: Write code that humans can understand and Keep it simple

  • Refactor: You have left the code cleaner than you found it (Boy Scout Rule)

  • Upgrade: Impact of this change on upgrade flows was considered and addressed if required

  • Testing: New code requires new unit tests. New features and bug fixes require at least on e2e test

  • Documentation: A user-guide update was considered and is present (link) or not required. You want a user-guide update if it's a user facing feature / API change.

  • Community: Announcement to kubevirt-dev was considered
  • Release note:
    <!-- Write your release note:
    1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
    2. If no release note is required, just write "NONE".
    -->
    ``release-note
    NONE
    ``

    Diff: 123 lines (+123 / -0) across 6 files Reviewer: dhiller Review duration: 23710m
    All Vouch review confidence checks passed
    Residual risk 0.08 = Change Risk (0.62) × (1 − Review Confidence (0.87)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.62 · 123 lines diff across 6 files
    0.62
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.90 · 5 substantive comment(s)
    0.90
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    86%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.288
    Sensitive Paths sensitive_paths
    0.062
    Real PR Conversation Timeline
    26 items
    gemini-code-assist[bot] gemini-code-assist[bot] commented on code on May 27, 2026 12:30 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,33 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),
    +	}

    !security-high !high

    The mode parameter is directly formatted into a shell command and executed via SSH. To prevent potential command injection or execution of malformed sysctl commands, we should validate that o.mode is strictly restricted to the allowed values (global or local).

    func (o *vsockOpt) Exec() error {
    	if o.mode != "global" && o.mode != "local" {
    		return fmt.Errorf("invalid vsock child namespace mode %q: must be 'global' or 'local'", o.mode)
    	}
    
    	cmds := []string{
    		"modprobe vsock",
    		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),
    	}
    

    gemini-code-assist[bot] gemini-code-assist[bot] commented on May 27, 2026 12:30 UTC
    Reviewer

    Code Review

    This pull request introduces support for configuring the vsock child namespace mode (global or local) on nodes during provisioning. This includes adding a new CLI flag, updating the node configuration structures, executing sysctl commands over SSH, and passing the parameter from the shell scripts. The review feedback highlights a potential command injection vulnerability in the new vsock.go file where the mode parameter is formatted directly into a shell command without validation, and suggests restricting it strictly to 'global' or 'local'.

    Ruclo Ruclo commented on code on May 27, 2026 12:36 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,33 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),
    +	}

    This problem also occurs when parsing other options. I think the validation should take place in all vulnerable areas if possible. Perhaps a separate PR could address this?

    0xFelix 0xFelix commented on code on May 27, 2026 14:30 UTC
    Code Review
    cluster-provision/gocli/cmd/run.go:1
    @@ -171,6 +172,7 @@ func NewRunCommand() *cobra.Command {
     	run.Flags().StringArrayVar(&usbDisks, "usb", []string{}, "size of the emulate USB disk to pass to the node")
     	run.Flags().StringArrayVar(&sharedDisks, "shared-block-device", []string{}, "size of block device to share between all nodes")
     	run.Flags().Bool("deploy-network-resources-injector", false, "deploys Network Resources Injector")
    +	run.Flags().String("vsock-child-ns-mode", "global", "vsock child namespace mode (global or local)")

    Can you make it default to "", so the opt will not change the node if the opt was not provided?

    0xFelix 0xFelix commented on code on May 27, 2026 14:32 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,33 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),
    +	}

    Can you please still add validation for the values that can be passed to this flag?

    akrejcir akrejcir commented on code on Jun 01, 2026 09:29 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {

    The return value is a private struct. Can you return the interface instead?

    akrejcir akrejcir commented on code on Jun 01, 2026 09:30 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	if o.mode != "global" && o.mode != "local" {
    +		return fmt.Errorf("invalid vsock child namespace mode %q, must be one of: global, local", o.mode)
    +	}

    Can you move this validation to the constructor NewVsockOpt()? Then, it can fail before any of the other commands are executed.

    akrejcir akrejcir commented on code on Jun 01, 2026 09:32 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	if o.mode != "global" && o.mode != "local" {
    +		return fmt.Errorf("invalid vsock child namespace mode %q, must be one of: global, local", o.mode)
    +	}
    +
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),

    nit: In my opinion, it is more readable to use the long versions of command parameters in scripts and code, like --write. The short versions are better in interactive console, so we don't need to type much.

    akrejcir akrejcir commented on Jun 01, 2026 09:33 UTC
    Reviewer

    The PR description and commit message mention that the parameter defaults to global, but that is no longer true. Can you update them?

    akrejcir akrejcir commented on Jun 01, 2026 09:39 UTC
    Contributor

    Can you also add a simple unit test?

    Ruclo Ruclo commented on code on Jun 08, 2026 09:57 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {

    This pattern is consistent with all of the existing options, the consumer side explictly uses the Opt interface.

    Ruclo Ruclo commented on code on Jun 08, 2026 09:58 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	if o.mode != "global" && o.mode != "local" {
    +		return fmt.Errorf("invalid vsock child namespace mode %q, must be one of: global, local", o.mode)
    +	}
    +
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),

    I agree, the long form is cleaner

    Ruclo Ruclo commented on code on Jun 08, 2026 10:07 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,37 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	if o.mode != "global" && o.mode != "local" {
    +		return fmt.Errorf("invalid vsock child namespace mode %q, must be one of: global, local", o.mode)
    +	}

    Sure

    Ruclo Ruclo commented on Jun 08, 2026 10:09 UTC
    Author

    Can you also add a simple unit test?

    Oh yes, thanks for spotting this.

    Ruclo Ruclo commented on code on Jun 08, 2026 10:09 UTC
    Code Review
    cluster-provision/gocli/opts/vsock/vsock.go:1
    @@ -0,0 +1,33 @@
    +package vsock
    +
    +import (
    +	"fmt"
    +
    +	"kubevirt.io/kubevirtci/cluster-provision/gocli/pkg/libssh"
    +)
    +
    +type vsockOpt struct {
    +	sshClient libssh.Client
    +	mode      string
    +}
    +
    +func NewVsockOpt(sc libssh.Client, mode string) *vsockOpt {
    +	return &vsockOpt{
    +		sshClient: sc,
    +		mode:      mode,
    +	}
    +}
    +
    +func (o *vsockOpt) Exec() error {
    +	cmds := []string{
    +		"modprobe vsock",
    +		fmt.Sprintf("sysctl -w net.vsock.child_ns_mode=%s", o.mode),
    +	}

    Yes

    Ruclo Ruclo commented on Jun 09, 2026 08:26 UTC
    Author

    /retest

    Ruclo Ruclo commented on Jun 09, 2026 11:09 UTC
    Author

    /retest

    kubevirt-bot kubevirt-bot commented on Jun 09, 2026 12:35 UTC
    Bot

    @Ruclo: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

    Test name | Commit | Details | Required | Rerun command
    --- | --- | --- | --- | ---
    check-provision-k8s-1.34 | 5aec6e8c262a8a64056a29f157f11e63cd856326 | link | false | /test check-provision-k8s-1.34

    <details>

    Instructions 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. I understand the commands that are listed here.
    </details>
    <!-- test report -->

    0xFelix 0xFelix commented on Jun 10, 2026 09:15 UTC
    Contributor

    PTAL @dhiller

    dhiller dhiller commented on Jun 12, 2026 14:34 UTC
    Contributor

    /override check-provision-alpine-with-test-tooling

    kubevirt-bot kubevirt-bot commented on Jun 12, 2026 14:34 UTC
    Bot

    @dhiller: Overrode contexts on behalf of dhiller: check-provision-alpine-with-test-tooling

    <details>

    In response to this:

    >/override check-provision-alpine-with-test-tooling

    Instructions 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.
    </details>

    dhiller dhiller commented on Jun 12, 2026 14:34 UTC
    Reviewer

    /approve

    kubevirt-bot kubevirt-bot commented on Jun 12, 2026 14:34 UTC
    Bot

    [APPROVALNOTIFIER] This PR is APPROVED

    This pull-request has been approved by: <a href="https://github.com/kubevirt/kubevirtci/pull/1720#pullrequestreview-4486551461" title="Approved">dhiller</a>

    The full list of commands accepted by this bot can be found here.

    The pull request process is described here

    <details >
    Needs approval from an approver in each of these files:

  • ~~OWNERS~~ [dhiller]
  • Approvers can indicate their approval by writing /approve in a comment
    Approvers can cancel approval by writing /approve cancel in a comment
    </details>
    <!-- META={"approvers":[]} -->

    dhiller dhiller approved these changes on Jun 12, 2026 14:35 UTC
    Approved Reviewer

    Approved these changes.

    kubevirt-commenter-bot kubevirt-commenter-bot commented on Jun 12, 2026 20:48 UTC
    Bot

    /retest-required
    This bot automatically retries required jobs that failed/flaked on
    required test lanes of PRs.
    Silence the bot with an /lgtm cancel or /hold comment for consistent failures.

    Reviewers
    Assignees
    Ruclo Ruclo
    Labels
    risk: low confidence: 86.6% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 62.3% (MEDIUM) · Higher = larger blast radius
    62.3%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 86.6% · Lower = rushed or shallow review
    86.6%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 8.4% · Safe to merge
    8.4%