Skip to content

Commit 4509b55

Browse files
authored
Add Windows Defender exception for integration tests (#4357)
Sometimes Windows Defender reports a false positive on the temporary mage binary while starting mage targets.
1 parent 6db169e commit 4509b55

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pkg/testing/runner/windows.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@ type WindowsRunner struct{}
2121

2222
// Prepare the test
2323
func (WindowsRunner) Prepare(ctx context.Context, sshClient SSHClient, logger Logger, arch string, goVersion string) error {
24+
// Adding the user directory as an exception to Windows Defender, so it does not detect
25+
// temporary mage binaries as malware.
26+
//
27+
// https://github.com/elastic/elastic-agent/issues/4355
28+
// https://learn.microsoft.com/en-us/powershell/module/defender/set-mppreference?view=windowsserver2022-ps
29+
logger.Logf("Adding exception in Windows Defender...")
30+
defenderException := `Set-MpPreference -Force -ExclusionPath $env:USERPROFILE`
31+
stdOut, errOut, err := sshRunPowershell(ctx, sshClient, defenderException)
32+
if err != nil {
33+
return fmt.Errorf("failed to add exception in Windows Defender: %w (stdout: %s, stderr: %s)", err, stdOut, errOut)
34+
}
35+
2436
// install chocolatey
2537
logger.Logf("Installing chocolatey")
2638
chocoInstall := `"[System.Net.ServicePointManager]::SecurityProtocol = 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))"`
27-
stdOut, errOut, err := sshRunPowershell(ctx, sshClient, chocoInstall)
39+
stdOut, errOut, err = sshRunPowershell(ctx, sshClient, chocoInstall)
2840
if err != nil {
2941
return fmt.Errorf("failed to install chocolatey: %w (stdout: %s, stderr: %s)", err, stdOut, errOut)
3042
}

0 commit comments

Comments
 (0)