Skip to content

Commit 2aacb77

Browse files
authored
Merge pull request kubernetes#74444 from pjh/gce-windows-no-defender
Disable Windows Defender on Windows nodes.
2 parents a778f40 + 621df2c commit 2aacb77

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

cluster/gce/windows/common.psm1

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,20 @@ function MustDownload-File {
146146
}
147147
}
148148

149+
# Returns true if this node is part of a test cluster (see
150+
# cluster/gce/config-test.sh). $KubeEnv is a hash table containing the kube-env
151+
# metadata keys+values.
152+
function Test-IsTestCluster {
153+
param (
154+
[parameter(Mandatory=$true)] [hashtable]$KubeEnv
155+
)
156+
157+
if ($KubeEnv.Contains('TEST_CLUSTER') -and `
158+
($KubeEnv['TEST_CLUSTER'] -eq 'true')) {
159+
return $true
160+
}
161+
return $false
162+
}
163+
149164
# Export all public functions:
150165
Export-ModuleMember -Function *-*

cluster/gce/windows/configure.ps1

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,6 @@ function FetchAndImport-ModuleFromMetadata {
7777
Import-Module -Force C:\$Filename
7878
}
7979

80-
# Returns true if this node is part of a test cluster (see
81-
# cluster/gce/config-test.sh).
82-
#
83-
# $kube_env must be set before calling this function.
84-
function Test-IsTestCluster {
85-
if ($kube_env.Contains('TEST_CLUSTER') -and `
86-
($kube_env['TEST_CLUSTER'] -eq 'true')) {
87-
return $true
88-
}
89-
return $false
90-
}
91-
9280
try {
9381
# Don't use FetchAndImport-ModuleFromMetadata for common.psm1 - the common
9482
# module includes variables and functions that any other function may depend
@@ -104,8 +92,9 @@ try {
10492

10593
Set-PrerequisiteOptions
10694
$kube_env = Fetch-KubeEnv
95+
Disable-WindowsDefender
10796

108-
if (Test-IsTestCluster) {
97+
if (Test-IsTestCluster $kube_env) {
10998
Log-Output 'Test cluster detected, installing OpenSSH.'
11099
FetchAndImport-ModuleFromMetadata 'install-ssh-psm1' 'install-ssh.psm1'
111100
InstallAndStart-OpenSsh

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,6 @@ function Set-PrerequisiteOptions {
221221
sc.exe config wuauserv start=disabled
222222
sc.exe stop wuauserv
223223

224-
# Windows Defender periodically consumes 100% of the CPU.
225-
# TODO(pjh): this (all of a sudden, ugh) started failing with "The term
226-
# 'Set-MpPreference' is not recognized...". Investigate and fix or remove.
227-
#Log-Output "Disabling Windows Defender service"
228-
#Set-MpPreference -DisableRealtimeMonitoring $true
229-
#Uninstall-WindowsFeature -Name 'Windows-Defender'
230-
231224
# Use TLS 1.2: needed for Invoke-WebRequest downloads from github.com.
232225
[Net.ServicePointManager]::SecurityProtocol = `
233226
[Net.SecurityProtocolType]::Tls12
@@ -237,6 +230,24 @@ function Set-PrerequisiteOptions {
237230
Install-Module -Name powershell-yaml -Force
238231
}
239232

233+
# Disables Windows Defender realtime scanning if this Windows node is part of a
234+
# test cluster.
235+
#
236+
# ${kube_env} must have already been set.
237+
function Disable-WindowsDefender {
238+
# Windows Defender periodically consumes 100% of the CPU, so disable realtime
239+
# scanning. Uninstalling the Windows Feature will prevent the service from
240+
# starting after a reboot.
241+
# TODO(pjh): move this step to image preparation, since we don't want to do a
242+
# full reboot here.
243+
if ((Test-IsTestCluster ${kube_env}) -and
244+
((Get-WindowsFeature -Name 'Windows-Defender').Installed)) {
245+
Log-Output "Disabling Windows Defender service"
246+
Set-MpPreference -DisableRealtimeMonitoring $true
247+
Uninstall-WindowsFeature -Name 'Windows-Defender'
248+
}
249+
}
250+
240251
# Creates directories where other functions in this module will read and write
241252
# data.
242253
function Create-Directories {

0 commit comments

Comments
 (0)