Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .changes/PRODENG-3924-windows-allsigned.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
**Windows MCR install failures now say why PowerShell refused the script.**

rig truncates a command's output into its error at roughly a hundred
characters, so a refusal arrived as `File C:\...\installerWindows123.ps1
cannot be loaded. The contents of file ...` — cut off exactly where the
reason would be. An install failure now carries the installer's own output,
the script's `Get-AuthenticodeSignature` status and signer, and the host's
effective execution policies.

**`spec.mcr.installURLWindowsAllowUnsigned` is exposed by the aws-simple
example**, as `launchpad.mcr_install_url_windows_allow_unsigned`. It
defaults to `false`, matching launchpad's own default.

The smoke suites set it to `true`. Enforcing `-ExecutionPolicy AllSigned`
causes a stock Windows host to refuse the signed script published at
get.mirantis.com, so every Windows host fails at Install MCR before any
launchpad behaviour is exercised. The opt-out keeps the suites meaningful
while the refusal is diagnosed.
12 changes: 10 additions & 2 deletions examples/terraform/aws-simple/launchpad.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,15 @@ variable "launchpad" {

mcr_channel = string
mcr_repo_url = optional(string, "https://repos.mirantis.com")
mke_version = string
msr_version = string // unused if you have no MSR hosts

// Runs the Windows MCR install script without requiring an Authenticode
// signature. Defaults to false, matching launchpad's own default. The
// smoke suites set it true while PRODENG-3924's AllSigned enforcement is
// under investigation: a stock Windows host refuses the signed script and
// the install fails before any launchpad behaviour is exercised.
mcr_install_url_windows_allow_unsigned = optional(bool, false)
mke_version = string
msr_version = string // unused if you have no MSR hosts

mke_connect = object({
username = string
Expand Down Expand Up @@ -257,6 +264,7 @@ spec:
channel: ${var.launchpad.mcr_channel}
repoURL: ${var.launchpad.mcr_repo_url}
installURLWindows: https://get.mirantis.com/install.ps1
installURLWindowsAllowUnsigned: ${var.launchpad.mcr_install_url_windows_allow_unsigned}
prune: true
mke:
version: ${var.launchpad.mke_version}
Expand Down
48 changes: 47 additions & 1 deletion pkg/configurer/windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,52 @@ func installerExecutionPolicy(allowUnsigned bool) string {
return "AllSigned"
}

// installerDiagnostics describes why PowerShell refused or failed the install
// script, for attaching to the error the caller returns.
//
// rig truncates a command's output into its error at about a hundred
// characters, so a PowerShell refusal arrives as
//
// File C:\...\installerWindows123.ps1 cannot be loaded. The contents of file ...
//
// cut off exactly where the reason would be. Those reasons need opposite
// fixes -- a hash mismatch means the file was altered in transit, an
// untrusted publisher means the host was never going to accept it -- and
// neither is recoverable from the truncated form. This is the Windows
// counterpart of the journalctl capture EnableMCR does on Linux, and it
// exists for the same reason: the only description of what went wrong was
// being discarded.
//
// Best effort throughout. A failure collecting diagnostics must not replace
// the original error, so every probe's own error is ignored.
func (c WindowsConfigurer) installerDiagnostics(h Host, installer, output string) string {
var diag strings.Builder

if trimmed := strings.TrimSpace(output); trimmed != "" {
diag.WriteString("\ninstaller output:\n")
diag.WriteString(trimmed)
}

sig, sigErr := h.ExecOutput(ps.Cmd(fmt.Sprintf(
"$s = Get-AuthenticodeSignature %s; "+
"Write-Output \"status=$($s.Status)\"; "+
"Write-Output \"statusMessage=$($s.StatusMessage)\"; "+
"Write-Output \"signer=$($s.SignerCertificate.Subject)\"",
ps.DoubleQuotePath(installer))))
if sigErr == nil && strings.TrimSpace(sig) != "" {
diag.WriteString("\nscript signature:\n")
diag.WriteString(strings.TrimSpace(sig))
}

policy, policyErr := h.ExecOutput(ps.Cmd("Get-ExecutionPolicy -List | Out-String"))
if policyErr == nil && strings.TrimSpace(policy) != "" {
diag.WriteString("\nexecution policy:\n")
diag.WriteString(strings.TrimSpace(policy))
}

return diag.String()
}

// windowsMCRInstallCommand passes the repo URL and channel as installer
// parameters, not `set` env vars, which a "cmd.exe /C" prefix loses (PRODENG-4062).
func windowsMCRInstallCommand(installer, repoURL, channel string, allowUnsigned bool) string {
Expand Down Expand Up @@ -169,7 +215,7 @@ func (c WindowsConfigurer) InstallMCR(h Host, engineConfig commonconfig.MCRConfi
if isExitCode3010(err) {
needsReboot = true
} else {
return fmt.Errorf("failed to run MCR installer: %w", err)
return fmt.Errorf("failed to run MCR installer: %w%s", err, c.installerDiagnostics(h, installer, output))
}
}

Expand Down
6 changes: 6 additions & 0 deletions test/smoke/smoke_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func runSmokeTest(t *testing.T, cfg smokeConfig) {
"mke_version": cfg.MKEVersion,
"msr_version": cfg.MSRVersion,
"mke_connect": mkeConnect,
// PRODENG-3924: a stock Windows host refuses the signed install
// script under -ExecutionPolicy AllSigned, so every Windows host
// fails at Install MCR before any launchpad behaviour is reached.
// The suites opt out until that is understood; the reason the host
// refuses is captured by installerDiagnostics in windows.go.
"mcr_install_url_windows_allow_unsigned": true,
}
if cfg.MCRRepoURL != "" {
launchpad["mcr_repo_url"] = cfg.MCRRepoURL
Expand Down
Loading