Add KUBEVIRT_VSOCK_CHILD_NS_MODE #1720
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),
}
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'.
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?
Can you make it default to "", so the opt will not change the node if the opt was not provided?
Can you please still add validation for the values that can be passed to this flag?
The return value is a private struct. Can you return the interface instead?
Can you move this validation to the constructor NewVsockOpt()? Then, it can fail before any of the other commands are executed.
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.
The PR description and commit message mention that the parameter defaults to global, but that is no longer true. Can you update them?
Can you also add a simple unit test?
This pattern is consistent with all of the existing options, the consumer side explictly uses the Opt interface.
I agree, the long form is cleaner
Sure
Can you also add a simple unit test?
Oh yes, thanks for spotting this.
Yes
/retest
/retest
@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 -->
PTAL @dhiller
/override check-provision-alpine-with-test-tooling
@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>
/approve
[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:
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":[]} -->
Approved these changes.
/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.
dhiller
Ruclo
<!-- 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.
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