wazuh-dashboard-plugins icon indicating copy to clipboard operation
wazuh-dashboard-plugins copied to clipboard

Windows deployment command is broken

Open zbalkan opened this issue 11 months ago • 3 comments

Wazuh Rev Browser
4.7.3 N/A N/A

Description Windows deployment command generated in the "Deploy new agent" window includes an invalid variable ${env.tmp} while it should be $ENV:TMP or $env:tmp -Powershell is not case-sensitive.

Preconditions

  1. Have the latest Wazuh Dashboard, yet it may be applicable to older versions.

Steps to reproduce

  1. Navigate to 'Deploy New Agent'
  2. Click on Windows agent settings
  3. Scroll down to generated command

Expected Result

Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-4.7.3-1.msi -OutFile $env:tmp\wazuh-agent; msiexec.exe /i $env:tmp\wazuh-agent /q WAZUH_MANAGER='' WAZUH_REGISTRATION_PASSWORD='' WAZUH_AGENT_GROUP='default' WAZUH_REGISTRATION_SERVER='' 

Actual Result

Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-4.7.3-1.msi -OutFile ${env.tmp}\wazuh-agent; msiexec.exe /i ${env.tmp}\wazuh-agent /q WAZUH_MANAGER='' WAZUH_REGISTRATION_PASSWORD='' WAZUH_AGENT_GROUP='default' WAZUH_REGISTRATION_SERVER='' 

Screenshots

image

Additional context I don't know when this is broken but it was not there when we deployed it earlier, around 4.3.10.

zbalkan avatar Mar 14 '24 13:03 zbalkan

Hi @zbalkan , thank you so much for reporting us this issue.

It seems the bug is present in 4.6.0 until the current release 4.7.3 at the moment. Older versions are using ${env:tmp}. 4.6.0 uses ${env.tmp}: https://github.com/wazuh/wazuh-dashboard-plugins/blob/v4.6.0-2.8.0/plugins/main/public/controllers/register-agent/services/register-agent-os-commands-services.tsx#L121 4.5.4 uses ${env:tmp}: https://github.com/wazuh/wazuh-dashboard-plugins/blob/v4.5.4-2.6.0/public/controllers/agent/components/register-agent.js#L1029

I did a check on Windows Server 2019, and ${env.tmp} does not resolve to anything while the ${env:tmp} returns the temporal directory: image

I did not check if its usage in the command provided by the deploy new agent guide, but I guess the provided command to deploy the Windows agent could be working because the file is downloaded into the current directory instead of the temporal directory.

I saw some E2E tests, that we did it, did not have any functional problem executing the command with ${env.tmp}:

  • https://github.com/wazuh/wazuh/issues/19465#issuecomment-1753649108
  • https://github.com/wazuh/wazuh/issues/21361#issuecomment-1889560992

I understand the intention is the package is downloaded into the temporal directory so the usage of ${env.tmp} is not valid.

We should change it to ${env:tmp}.

Desvelao avatar Mar 15 '24 09:03 Desvelao

Hi @Desvelao,

Even though ${env:tmp} works, it is not the Powershell way. It's generally $Env:TMP.

One the other hand, TMP and TEMP outdates Powershell itself. It's a bit of nitpicking as Powershell is case insensitive.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_environment_variables?view=powershell-7.4 https://devblogs.microsoft.com/oldnewthing/20150417-00/?p=44213

zbalkan avatar Mar 15 '24 09:03 zbalkan

Hi @zbalkan , thank you so much for the provided information. It is appreciated.

Desvelao avatar Apr 08 '24 07:04 Desvelao

Today we had this input from a user in a community:

I'd like to point out a change in the Windows agent deployment command.
The environment variable used is not correct and causes the .MSI to be downloaded to the root of C:\.
OLD :
Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-4.7.5-1.msi -OutFile ${env.tmp}\wazuh-agent; msiexec.exe /i ${env.tmp}\wazuh-agent /q WAZUH_MANAGER='test.fr' WAZUH_REGISTRATION_SERVER='test.fr'
NEW :
Invoke-WebRequest -Uri https://packages.wazuh.com/4.x/windows/wazuh-agent-4.7.5-1.msi -OutFile $env:temp\wazuh-agent; msiexec.exe /i $env:temp\wazuh-agent /q WAZUH_MANAGER='test.fr' WAZUH_REGISTRATION_SERVER='test.fr'
Replace ${env.tmp} by $env:temp
Thank You,
Loris

image

image

aritosteles avatar Aug 09 '24 15:08 aritosteles

Isn't that funny that this simple thing has not been fixed for several versions published since I created this issue?

zbalkan avatar Aug 09 '24 15:08 zbalkan