Skip to content

Commit 9b043c9

Browse files
truthbkalbertvaka
andauthored
[windows] fixes + blacklist (DataDog#578)
* [windows] apply powershell remote fix before uninstall + idiomatic download * [windows] weak first attempt to blacklist bad MSIs * [windows] multiple fixes + blacklist + hash validation * addressing cops Apply suggestions from code review Co-Authored-By: Albert Vaca <albert.vaca@datadoghq.com>
1 parent e3c3ef3 commit 9b043c9

2 files changed

Lines changed: 24 additions & 8 deletions

File tree

manifests/params.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666
'Windows': {
6767
$agent5_default_repo = '<agent 5 is not supported by this module on windows>' # Param in init.pp so needs to be defined, but not used on Windows
68-
$agent6_default_repo = "https://s3.amazonaws.com/ddagent-windows-stable/datadog-agent-6-${agent_version}.amd64.msi"
68+
$agent6_default_repo = 'https://s3.amazonaws.com/ddagent-windows-stable/'
6969
$conf5_dir = 'C:/ProgramData/Datadog/agent5' # Not a real path, but integrations use it to ensure => absent so it needs to be a valid path
7070
$conf6_dir = 'C:/ProgramData/Datadog/conf.d'
7171
$dd_user = 'ddagentuser'

manifests/windows/agent6.pp

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,32 @@
1717
) inherits datadog_agent::params {
1818

1919
$msi_full_path = "${msi_location}/datadog-agent-6-${agent_version}.amd64.msi"
20+
$msi_source = "${baseurl}ddagent-cli-${agent_version}.msi"
2021

2122
if $ensure == 'present' {
23+
if ($agent_version in ['6.14.0', '6.14.1']) {
24+
fail('The specified agent version has been blacklisted, please specify a version other than 6.14.0 or 6.14.1')
25+
}
26+
27+
file { 'installer':
28+
path => $msi_full_path,
29+
source => $msi_source,
30+
provider => 'windows',
31+
}
2232

23-
exec { 'downloadmsi': # Using exec instead of file so we can specify an onlyif condition
24-
command => "Invoke-WebRequest ${baseurl} -outfile ${msi_full_path}",
25-
onlyif => "if ((Get-Package \"${datadog_agent::params::package_name}\") -or (test-path ${msi_full_path})) { exit 1 }",
26-
provider => powershell,
27-
notify => Package[$datadog_agent::params::package_name]
33+
exec { 'validate':
34+
command => "\$blacklist = '928b00d2f952219732cda9ae0515351b15f9b9c1ea1d546738f9dc0fda70c336','78b2bb2b231bcc185eb73dd367bfb6cb8a5d45ba93a46a7890fd607dc9188194';\$fileStream = [system.io.file]::openread('${msi_full_path}'); \$hasher = [System.Security.Cryptography.HashAlgorithm]::create('sha256'); \$hash = \$hasher.ComputeHash(\$fileStream); \$fileStream.close(); \$fileStream.dispose();\$hexhash = [system.bitconverter]::tostring(\$hash).ToLower().replace('-','');if (\$hexhash -match \$blacklist) { Exit 1 }",
35+
provider => 'powershell',
36+
logoutput => 'on_failure',
37+
require => File['installer'],
38+
notify => Package[$datadog_agent::params::package_name]
2839
}
2940

3041
package { $datadog_agent::params::package_name:
3142
ensure => installed,
3243
provider => 'windows',
3344
source => $msi_full_path,
34-
install_options => ['/quiet', {'APIKEY' => $api_key, 'HOSTNAME' => $hostname, 'TAGS' => $tags}]
45+
install_options => ['/norestart', {'APIKEY' => $api_key, 'HOSTNAME' => $hostname, 'TAGS' => $tags}]
3546
}
3647

3748
service { $service_name:
@@ -40,11 +51,16 @@
4051
require => Package[$datadog_agent::params::package_name]
4152
}
4253
} else {
54+
exec { 'datadog_6_14_fix':
55+
command => "((New-Object System.Net.WebClient).DownloadFile('https://s3.amazonaws.com/ddagent-windows-stable/scripts/fix_6_14.ps1', \$env:temp + '\\fix_6_14.ps1')); &\$env:temp\\fix_6_14.ps1",
56+
provider => 'powershell',
57+
}
4358

4459
package { $datadog_agent::params::package_name:
4560
ensure => absent,
4661
provider => 'windows',
47-
uninstall_options => ['/quiet']
62+
uninstall_options => ['/quiet'],
63+
subscribe => Exec['datadog_6_14_fix'],
4864
}
4965

5066
}

0 commit comments

Comments
 (0)