diff --git a/.changes/PRODENG-3924-windows-allsigned.md b/.changes/PRODENG-3924-windows-allsigned.md new file mode 100644 index 00000000..b58a7738 --- /dev/null +++ b/.changes/PRODENG-3924-windows-allsigned.md @@ -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. diff --git a/examples/terraform/aws-simple/launchpad.tf b/examples/terraform/aws-simple/launchpad.tf index 93739644..0f9aa2a4 100644 --- a/examples/terraform/aws-simple/launchpad.tf +++ b/examples/terraform/aws-simple/launchpad.tf @@ -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 @@ -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} diff --git a/pkg/configurer/windows.go b/pkg/configurer/windows.go index b49e1a30..50ff0fdc 100644 --- a/pkg/configurer/windows.go +++ b/pkg/configurer/windows.go @@ -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 { @@ -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)) } } diff --git a/test/smoke/smoke_test.go b/test/smoke/smoke_test.go index 0ad29591..e1f37886 100644 --- a/test/smoke/smoke_test.go +++ b/test/smoke/smoke_test.go @@ -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