-
Notifications
You must be signed in to change notification settings - Fork 259
[windows] fixes + blacklist #578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
a07720f
[windows] apply powershell remote fix before uninstall + idiomatic do…
truthbk 1b2cd02
[windows] weak first attempt to blacklist bad MSIs
truthbk 93e1e7e
[windows] multiple fixes + blacklist + hash validation
truthbk e1cb79a
addressing cops
truthbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,21 +17,32 @@ | |
| ) inherits datadog_agent::params { | ||
|
|
||
| $msi_full_path = "${msi_location}/datadog-agent-6-${agent_version}.amd64.msi" | ||
| $msi_source = "${baseurl}ddagent-cli-${agent_version}.msi" | ||
|
|
||
| if $ensure == 'present' { | ||
| if ($agent_version in ['6.14.0', '6.14.1']) { | ||
| fail('The specified agent version has been blacklisted, please specify a version other than 6.14.0 or 6.14.1') | ||
| } | ||
|
|
||
| file { 'installer': | ||
| path => $msi_full_path, | ||
| source => $msi_source, | ||
| provider => 'windows', | ||
| } | ||
|
|
||
| exec { 'downloadmsi': # Using exec instead of file so we can specify an onlyif condition | ||
| command => "Invoke-WebRequest ${baseurl} -outfile ${msi_full_path}", | ||
| onlyif => "if ((Get-Package \"${datadog_agent::params::package_name}\") -or (test-path ${msi_full_path})) { exit 1 }", | ||
| provider => powershell, | ||
| notify => Package[$datadog_agent::params::package_name] | ||
| exec { 'validate': | ||
| 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 }", | ||
| provider => 'powershell', | ||
| logoutput => 'on_failure', | ||
|
truthbk marked this conversation as resolved.
|
||
| require => File['installer'], | ||
| notify => Package[$datadog_agent::params::package_name] | ||
| } | ||
|
|
||
| package { $datadog_agent::params::package_name: | ||
| ensure => installed, | ||
| provider => 'windows', | ||
| source => $msi_full_path, | ||
| install_options => ['/quiet', {'APIKEY' => $api_key, 'HOSTNAME' => $hostname, 'TAGS' => $tags}] | ||
| install_options => ['/norestart', {'APIKEY' => $api_key, 'HOSTNAME' => $hostname, 'TAGS' => $tags}] | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👌 |
||
| } | ||
|
|
||
| service { $service_name: | ||
|
|
@@ -40,11 +51,16 @@ | |
| require => Package[$datadog_agent::params::package_name] | ||
| } | ||
| } else { | ||
| exec { 'datadog_6_14_fix': | ||
| 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", | ||
| provider => 'powershell', | ||
| } | ||
|
|
||
| package { $datadog_agent::params::package_name: | ||
| ensure => absent, | ||
| provider => 'windows', | ||
| uninstall_options => ['/quiet'] | ||
| uninstall_options => ['/quiet'], | ||
| subscribe => Exec['datadog_6_14_fix'], | ||
| } | ||
|
|
||
| } | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous behavior was to only download the MSI if it wasn't already installed. Now we are downloading it regardless. Any reason to prefer this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I missed something with my testing, but it didn't seem to download regardless. Once the file is in the temp directory I don't think the download was reattempted (ie. this resource doesn't behave like the chef counterpart that always pulls).
That said, we can go back to the original code. I made this change because I wanted to use the
validate_cmd, but it didn't work particularly well in my tests, so I eventually did the validation in theexecresource below. We could still do it the way it was before, but I left it like this because the behavior seemed similar. I can try to reconfirm this doesn't always download.The one thing that sucks, and I might change in a separate PR, is the fact we keep multiple files lying around, using up more and more disk space in temp over time. It might make sense to make
msi_full_patha constant where we always overwrite with what we pull from the source (if it's not chatty).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't always download, but clearing the temp directory will trigger a download that is not needed if the package is already installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tentative fix, yet to be tested: #582