Skip to content

[PRODENG-3920] Replace hand-rolled quoting on license, credential and reset paths - #676

Open
james-nesbitt wants to merge 1 commit into
mainfrom
PRODENG-3920-replace-hand-rolled-quoting
Open

james-nesbitt wants to merge 1 commit into
mainfrom
PRODENG-3920-replace-hand-rolled-quoting

Conversation

@james-nesbitt

@james-nesbitt james-nesbitt commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What

Replace hand-rolled quoting on the license, credential and reset command paths; fix the inverted emptiness check in GetDockerDaemonConfig.

Why

Four Linux paths built root-privileged commands with manual or no quoting, so a single quote byte in a license file or admin password broke out into the remote shell, and the host-reported docker root paths reached sudo'd rm -rf/umount unvalidated.

How

  • SetupLicenseFile, InstallMKE admin credentials: shellescape.Quote instead of hand-rolled '...'; redactions retained.
  • Ubuntu keyring import: gpgURL validated with url.ParseRequestURI; command rebuilt as sh.Command("bash", "-c", ...), matching the SLES shape.
  • CleanupLingeringMCR: host-reported Root/ExecRoot/DockerRootDir must pass isSafeRemotePath or are ignored; rm/umount sinks built with sh.Command, including the previously unguarded umount.
  • common.go:42 inverted check fixed — daemon.json Root/ExecRoot never reached the reset logic; both callers verified quoting before the fix, so no injection path is opened.

Testing

  • make unit-test: pass; make lint: 0 issues.
  • TestIsSafeRemotePath: 18 cases covering substitution, separators, traversal, spaces, newline.
  • TestResetCommandsQuoteHostPaths: metacharacter-bearing paths are quoted by construction.

Links

Checklist

  • Tests added or updated
  • Docs updated if user-visible behaviour changed
  • No debug output or dead code left in

Written by AI: claude-opus-5

… reset paths

Four Linux paths built root-privileged commands with manual or no quoting:

SetupLicenseFile and InstallMKE wrapped values in '...' by hand, so a
single quote byte in a license file or admin password broke out into the
remote shell. Both now emit shellescape.Quote'd values (the license content
is also trimmed, since it is a command-line flag value). The
--admin-username/--admin-password flags keep their redaction options.

The Ubuntu keyring import spliced a repoURL-derived gpgURL into a sudo'd
string containing $(curl ...). gpgURL is now validated with
url.ParseRequestURI before use and the command is assembled by sh.Command
with the substitution embedded in one quoted bash -c argument - the URL
never touches the outer shell. Mirrors the sh.Command shape the SLES
installer already uses.

CleanupLingeringMCR built root rm -rf and umount commands from the
host-reported DockerRootDir and daemon.json Root/ExecRoot with plain
Sprintf. Host-reported paths must now pass isSafeRemotePath - absolute, no
metacharacters, spaces, empty segments or traversal - or they are ignored
with a warning; every sink (attemptPathSudoDelete and the umount at
linux.go:557) builds its command with sh.Command, which quotes by
construction.

pkg/configurer/common.go:42 inverted its emptiness check so
GetDockerDaemonConfig returned errConfigEmpty for every non-empty input,
meaning daemon.json Root/ExecRoot never reached CleanupLingeringMCR at all.
The condition is now correct; because the callers validate and quote the
values, fixing it opens no injection path. Callers were confirmed before
the fix: pkg/configurer/linux.go:556 and windows.go:484; the Windows
caller already quotes through ps.SingleQuote.

Covers secf_7def0007cfc6eb3b9d466843, secf_777f11c24bc0f0a56607429e,
secf_8fed7df1b14f3db189694b4d.

make lint 0 issues, make unit-test clean.

Written by AI: claude-opus-5

Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
@james-nesbitt
james-nesbitt force-pushed the PRODENG-3920-replace-hand-rolled-quoting branch from 9eebb7c to a53141d Compare October 22, 2026 14:07
@james-nesbitt james-nesbitt added the smoke-modern Run modern smoke test label Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

smoke-modern Run modern smoke test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant