Skip to content

Fix corrupted Windows k0s install command (Flags double-unquote, --kubelet-extra-args double-quote) - #1120

Merged
kke merged 1 commit into
k0sproject:mainfrom
vikramhh:fix/windows-flags-unquote-1114
Jul 28, 2026
Merged

kke merged 1 commit into
k0sproject:mainfrom
vikramhh:fix/windows-flags-unquote-1114

Conversation

@vikramhh

Copy link
Copy Markdown
Contributor

On a Windows worker host (Host.FS() is rig/v2 WinFS, whose ShellQuote is
powershell.SingleQuote and always wraps its argument in single quotes), the
generated k0s install worker … command is corrupted two ways:

  • --data-dir / --token-file / --kubelet-root-dir lose their backslashes
    (C:\var\lib\k0s → C:varlibk0s), so k0s resolves them as relative paths.
  • --kubelet-extra-args is double-quoted and backtick-mangled
    ('--cluster-dns=``10.96.0.10`` …').

Root cause:

  1. Flags.AddOrReplace / AddUnlessExist unquote their argument, then call
    Flags.Add, which unquotes again. shellescape.Unquote is not idempotent
    on backslashes — the second pass treats \ as an escape and eats it.
  2. Flags.Each (used by Join) unquotes the value part unconditionally, with
    the same hazard for a bare backslash value.
  3. Host.K0sInstallFlags wraps extra.Join(h.FS()) in an extra quote(...),
    but the final flags.Join already quotes once; on Windows SingleQuote
    wraps every value, so this double-quotes.

All three are Windows-specific because rig/v2's SingleQuote wraps every value,
unlike POSIX shellescape.Quote which leaves simple tokens bare.

Fix:

  1. AddOrReplace / AddUnlessExist append the already-unquoted value directly
    instead of routing through Add (which would unquote a second time).
  2. Flags.Each only unquotes a value actually wrapped in matching quotes (new
    isQuoted helper), leaving bare backslash values intact.
  3. K0sInstallFlags drops the redundant outer quote(...); the final
    flags.Join in K0sInstallCommand quotes once, cleanly.

Per review on the issue, the standalone repro is now a table test run against
both a POSIX quoter and a Windows SingleQuote quoter: TestK0sInstallFlagsQuoting
asserts the full rendered command tail for both, and TestFlagsUnquoteOnce
guards the Flags primitives against backslash corruption on both. Both fail on
the pre-fix code and pass after; existing host_posix_test.go suites are
unchanged. go vet and gofmt are clean.

Fixes #1114

…belet-extra-args double-quote)

On Windows hosts the rig/v2 SingleQuote quoter wraps every value, exposing two
bugs in Flags: AddOrReplace/AddUnlessExist unquote a second time via Add and
strip backslashes from paths (C:\var\lib\k0s -> C:varlibk0s), and Each unquotes
bare values with the same hazard. K0sInstallFlags also double-quoted
--kubelet-extra-args by wrapping extra.Join in a redundant quote().

Append already-unquoted values directly, only unquote genuinely quoted values in
Each (new isQuoted helper), and drop the redundant outer quote. Add a table test
covering both a POSIX quoter and a Windows SingleQuote quoter.

Fixes k0sproject#1114

Signed-off-by: Vikram bir Singh <vsingh@mirantis.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vikramhh
vikramhh force-pushed the fix/windows-flags-unquote-1114 branch from 9f71168 to 3430dbb Compare July 23, 2026 15:42
@kke
kke requested a review from Copilot July 28, 2026 22:29

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Fixes Windows-specific corruption in the rendered k0s install worker ... command by preventing repeated/unconditional unquoting from consuming backslashes in paths and by removing redundant quoting of --kubelet-extra-args. This change sits in the config API layer (cluster.Flags and Host.K0sInstallFlags), which is responsible for constructing safe CLI flag strings across platforms.

Changes:

  • Prevent Flags.AddOrReplace / AddUnlessExist from unquoting the same token twice (avoids backslash loss on Windows paths).
  • Make Flags.Each only unquote values that are actually wrapped in matching quotes (avoids corrupting bare C:\... values).
  • Remove redundant quoting around extra.Join(...) when setting --kubelet-extra-args, avoiding Windows PowerShell quote-escaping mangling.
  • Add table-driven tests covering both POSIX and Windows quoting behaviors.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/host.go Avoids double-quoting --kubelet-extra-args when composing worker install flags.
pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/flags.go Prevents double-unquoting and avoids unquoting bare values in Each to preserve Windows backslashes.
pkg/apis/k0sctl.k0sproject.io/v1beta1/cluster/flags_quoting_test.go Adds regression tests for Windows/POSIX quoting and single-unquote invariants.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +14 to +24
// isQuoted reports whether s is wrapped in a matching pair of single or double
// quotes. Only such values are safe to pass to shellescape.Unquote; a bare
// value must be left untouched so that literal backslashes (Windows paths) are
// not consumed as escape sequences.
func isQuoted(s string) bool {
if len(s) < 2 {
return false
}
c := s[0]
return (c == '\'' || c == '"') && s[len(s)-1] == c
}
@kke
kke merged commit 3edb2dc into k0sproject:main Jul 28, 2026
45 checks passed
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
k0sctl 0.32.2

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## What's Changed
* Remove long-removed podSecurityPolicy from k0sctl's init default config by @twz123 in k0sproject/k0sctl#1126
* Fix corrupted Windows k0s install command (Flags double-unquote, --kubelet-extra-args double-quote) by @vikramhh in k0sproject/k0sctl#1120
* build(deps): bump actions/setup-go from 6 to 7 by @dependabot[bot] in k0sproject/k0sctl#1115
* build(deps): bump actions/setup-python from 6 to 7 by @dependabot[bot] in k0sproject/k0sctl#1119
* build(deps): bump k8s.io/client-go from 0.36.2 to 0.36.3 by @dependabot[bot] in k0sproject/k0sctl#1123
* build(deps): bump github.com/mattn/go-isatty from 0.0.22 to 0.0.24 by @dependabot[bot] in k0sproject/k0sctl#1125
* build(deps): bump golang.org/x/text from 0.38.0 to 0.40.0 by @dependabot[bot] in k0sproject/k0sctl#1113
* build(deps): bump github.com/k0sproject/rig/v2 from 2.1.0 to 2.1.1 by @dependabot[bot] in k0sproject/k0sctl#1127

## New Contributors
* @vikramhh made their first contribution in k0sproject/k0sctl#1120

**Full Changelog**: k0sproject/k0sctl@v0.32.1...v0.32.2

### SHA256 Checksums

```
cb40948151451c68dfca16de000cf990ee112fb2ffb4f6a5d103e665cbb43d5e *k0sctl-linux-amd64
b8de441f03ba8b53dee590d675caba1c0508ba05c53d2c77a841d31959a12ca7 *k0sctl-linux-arm64
8c05e5793da7d9e463844e075156f9c544b40088a856b9c77387971a18b23195 *k0sctl-linux-arm
65f7de2b295578d60ac7019b2131052ac2151a8416d495ccc7ea1a988bce0e26 *k0sctl-linux-riscv64
3d06cca961ba0bd2571836a19f6a67a9c2b44fe0d5684944028393265562b467 *k0sctl-win-amd64.exe
1124a07e18831bcc6df442593dde15f3c2a149060a42c05001ba59c58120a2c9 *k0sctl-darwin-amd64
cee6db821bd255e67052e00fd054ed89e1a2421a05326686ed576210caf1ffdd *k0sctl-darwin-arm64
```
</pre>
  <p>View the full release notes at <a href="https://github.com/k0sproject/k0sctl/releases/tag/v0.32.2">https://github.com/k0sproject/k0sctl/releases/tag/v0.32.2</a>.</p>
</details>
<hr>

See merge request: Harmonybrew/homebrew-core!15395
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows k0s install command is corrupted: Flags double-unquotes backslash paths and double-quotes --kubelet-extra-args

3 participants