Repository navigation
[PRODENG-3917] Escape MSR bootstrapper credentials and host-reported facts - #675
Open
james-nesbitt wants to merge 1 commit into
Open
james-nesbitt wants to merge 1 commit into
james-nesbitt wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
The destroy command’s credential-decoding path can alter literal backslash escapes, causing authentication and cleanup to fail.
1 open issue
What changed in this PR
This PR hardens Launchpad’s MSR bootstrapper commands against shell injection through credentials and host-reported facts.
Changes:
- Shell-quotes MKE credentials and decodes them before building the destroy command.
- Validates hostnames and quotes hostname and replica ID arguments.
- Updates credential-quoting tests.
| File | Description |
|---|---|
| pkg/product/mke/phase/upgrade_msr.go | Quotes the existing replica ID during upgrades. |
| pkg/product/mke/phase/remove_nodes.go | Quotes replica IDs during node removal. |
| pkg/product/mke/phase/join_msr_replicas.go | Quotes hostname and replica IDs during joins. |
| pkg/product/mke/phase/install_msr.go | Quotes hostname and replica ID during installation. |
| pkg/product/mke/phase/gather_facts.go | Validates host-reported hostname characters. |
| pkg/msr/msr.go | Quotes credentials and adds decoding for destroy commands. |
| pkg/msr/msr_test.go | Updates flag expectations and adds quoting checks. |
Review effort: Balanced
Comment on lines
+157
to
+163
| unquote := func(flag string) string { | ||
| if raw, err := shellescape.Unquote(mkeFlags.GetValue(flag)); err == nil { | ||
| return raw | ||
| } | ||
|
|
||
| return mkeFlags.GetValue(flag) | ||
| } |
…facts BuildMKEFlags wrapped the MKE admin username, password and URL in literal double quotes, which do not suppress $(...), backticks or $VAR in the remote shell, and Flags.GetValue runs strconv.Unquote, so msr.Destroy spliced the recovered password straight into a DockerCmd.Arg call - re-quoting an already-quoted value and breaking on values with quotes. BuildMKEFlags now emits shellescape.Quote'd values; Destroy recovers the raw value with shellescape.Unquote before handing it to DockerCmd, which applies its own quoting. Verified the roundtrip for values containing $(...), backticks, single and double quotes. Host-reported facts: gather_facts records the hostname with no validation; it is now rejected unless it matches ^[a-zA-Z0-9.-]+$ (RFC 1123 shape), mirroring the existing net.ParseIP check on the internal address. ReplicaID - settable via host container labels - is quoted at every bootstrapper sink: install_msr, join_msr_replicas, remove_nodes and upgrade_msr. The hostname is quoted at the --ucp-node sinks. TestBuildMKEFlags pinned the old double-quoted flag format; updated to the shell-quoted form. TestBuildMKEFlagsQuotesCredentials and TestDestroyQuotesCredentials pin the credential roundtrip; the single-word property of every flag value is asserted for the payload password. make lint 0 issues, make unit-test clean. Covers secf_50a05cbd0de6b8b5bd2f0b93, secf_e38dc9e2e6b75d24ab91e08e. Written by AI: claude-opus-5 Signed-off-by: James Nesbitt <jnesbitt@mirantis.com>
james-nesbitt
force-pushed
the
PRODENG-3917-escape-msr-facts
branch
from
October 22, 2026 14:07
157d8db to
7d81ed5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

What
Shell-quote the MSR bootstrapper credentials and validate/quote the host-reported MSR facts.
Why
BuildMKEFlagswrapped the MKE admin credentials in literal double quotes, which do not suppress$(...), backticks or$VARin the remote shell; host-reported MSR facts (hostname, ReplicaID from settable container labels) reached bootstrapper flags unvalidated and unquoted.How
BuildMKEFlagsemitsshellescape.Quote'd values;Destroyrecovers raw values withshellescape.UnquotebeforeDockerCmd().Arg()re-quotes — fixes a double-quoting bug where an already-quoted value was re-quoted.gather_factsrejects hostnames not matching^[a-zA-Z0-9.-]+$, mirroring thenet.ParseIPcheck on internal address.ReplicaIDquoted at every bootstrapper sink:install_msr,join_msr_replicas,remove_nodes,upgrade_msr; hostname quoted at--ucp-nodesinks.Testing
make unit-test: pass;make lint: 0 issues.TestBuildMKEFlagsQuotesCredentials: password with$(...), backticks, quotes roundtrips through quote/unquote as a single shell-safe word.TestDestroyQuotesCredentials: DockerCmd quoting is reversible without payload loss.TestBuildMKEFlagsupdated from the double-quoted to the shell-quoted format.Links
Checklist
Written by AI: claude-opus-5