Skip to content
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

Windows (MSI) Installer Creation #134

Closed
Tracked by #128
vikman90 opened this issue Sep 11, 2024 · 4 comments · Fixed by #191
Closed
Tracked by #128

Windows (MSI) Installer Creation #134

vikman90 opened this issue Sep 11, 2024 · 4 comments · Fixed by #191
Assignees
Labels
level/subtask Subtask issue module/packages Agent packages type/enhancement Enhancement issue

Comments

@vikman90
Copy link
Member

vikman90 commented Sep 11, 2024

Parent Issue:

Description

This issue involves creating an MSI installer for Windows to simplify the installation of the Wazuh agent. The installer should ensure that the agent is correctly registered as a Windows Service and handle all required dependencies and installation tasks.

Functional Requirements

  • Develop an MSI installer for the Wazuh agent compatible with Windows platforms.
  • Ensure the installer correctly registers the agent as a Windows Service.
  • Implement any required pre/post-installation scripts to set up the agent.
  • Handle dependency installation as part of the MSI installer process.

Implementation Restrictions

  • Avoid using VB scripts, as the VBScript engine is planned to be deprecated (ref).

Acceptance Criteria

  • The MSI installer successfully installs the Wazuh agent.
  • The Wazuh agent is registered as a Windows Service and starts automatically after installation.
  • The installation, uninstallation, and upgrade processes are tested and verified on supported Windows versions.
@jotacarma90
Copy link
Member

jotacarma90 commented Oct 1, 2024

Update 01/10/2024

On hold

Update 18/11/2024

Update 19/11/2024

  • Local compilation completed after multiple dependency fixes in the process.
  • I continue to work on generating the same .vbs scripts into powershell .ps1 scripts.
  • Pending to generate package locally and analyze the process for further definition.

Update 20/11/2024

  • How to compile in local Windows 11 VM:

  • Current .ps1 scripts:

RemoveAllScript.zip
InstallerScript.zip

On hold

@vikman90 vikman90 removed the mvp label Oct 28, 2024
@wazuhci wazuhci moved this to In progress in XDR+SIEM/Release 5.0.0 Nov 18, 2024
@wazuhci wazuhci moved this from In progress to On hold in XDR+SIEM/Release 5.0.0 Nov 20, 2024
@wazuhci wazuhci moved this from On hold to In progress in XDR+SIEM/Release 5.0.0 Dec 2, 2024
@wazuhci wazuhci moved this from In progress to On hold in XDR+SIEM/Release 5.0.0 Dec 3, 2024
@wazuhci wazuhci moved this from On hold to In progress in XDR+SIEM/Release 5.0.0 Dec 16, 2024
@jotacarma90
Copy link
Member

jotacarma90 commented Dec 17, 2024

Update 16/12/2024

  • I have picked up the issue where I left off.
  • Analysis of the current status of the package.
  • Review of the scripts made.
  • Researching the vbs deprecation and the current operation of the package generation script.
  • Progressing on the actual generation.

Update 17/12/2024

  • Checked complete flow, after successful compilation.
  • Moving necessary files and scripts to wazuh-agent/packages/windows
  • Adapting all left over or modified paths.
  • Continued to solve some problems and errors in the execution of the msi generation script.
  • Pending to adapt the compilation to the new script with the new agent steps.

Update 18/12/2024

  • Created PR with the necessary file movements: Create Windows installer MSI #191
  • Investigating error when installing the .exe to check that the paths are correct.
  • Example of errors to be fixed during package generation:
    Image
  • Continued working on the wxs script that contains each specific case of new files and directories.

Update 19/12/2024

  • Installation fixed and corrected the paths to be created.
  • During the development of the wxs script, I have found information about the CPack tool, with which it is feasible to generate the msi package from the cmake project, which seems much more convenient for our solution.

Update 20/12/2024

  • I was able to perform an installation with cmake --install and verify in the Windows eventviewer some errors related to the path of the configuration file. Solved.
  • I am investigating and analyzing the cpack settings to create the msi package.
  • Absolute path related errors in the cmakelist.

Update 23/12/2024

  • In-depth research on the creation of directories and files in CPACK.
  • Trying to find a way to use relative path to create the configuration directory in programdata.
  • Research on package generation techniques with CPACK.

Update 24/12/2024

  • The issue of relative paths has been solved. We are going to generate everything in an installation directory in “program files”, and then in a postinstall script create and move the rest of the paths.
  • Working with the different CPACK variables to pick up all the old wxs script operation.

Update 26/12/2024

  • Finally and after much research and trial and error I have managed to put together all the features of CPACK to end up generating an msi correctly.
  • At the moment, the agent is installed and a post install script is used to create the special directories, move the configuration file, and raise the Wazuh service.
  • The uninstall, upgrade and file signing functionalities are pending.

Update 27/12/2024

  • Fixed a few minor bugs in the package generation. Folder name, postinstall scripts, etc.
  • Added functionality to delete the data directory (except for a list of files that should not be deleted, such as the configuration file).
  • Complete check of current functionality.
  • Uploaded changes with all functionality.
  • Pending to add the functionality of the package signature and its files.

Update 30/12/2024

  • Working on package signature functionality and debug symbols.

Update 7/1/2025

  • Finally got an msi package with all the expected functionalities.
  • Code uploaded to PR:
  • Fixed multiple bugs like debug symbols (waiting for PR to be ported to wazuh-agent), file signing, configuration file backup, upgrade from the same version, installer working properly.
  • Pending to do an exhaustive testing.
  • Pending to verify the correct start of the Wazuh service after the installation.

Update 8/01/2025

  • Testing package installation.
  • Testing service install, start and register using mock_server.py
  • Analyzing some errors found in event viewer related to service.

@jotacarma90 jotacarma90 linked a pull request Dec 17, 2024 that will close this issue
@jotacarma90
Copy link
Member

jotacarma90 commented Jan 9, 2025

Generate compiled code:

PS C:\Users\vagrant\wazuh\wazuh-agent\packages\windows> .\generate_compiled_windows_agent.ps1
Output
    Directory: C:\Users\vagrant\wazuh\wazuh-agent


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----          1/9/2025   1:45 AM                build
CMake Deprecation Warning at vcpkg/scripts/buildsystems/vcpkg.cmake:40 (cmake_policy):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
  C:/Users/vagrant/wazuh/wazuh-agent/build/CMakeFiles/3.31.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:9 (project)


-- Running vcpkg install
warning: Embedding `vcpkg-configuration` in a manifest file is an EXPERIMENTAL feature.
Detecting compiler hash for triplet x64-windows...
Compiler found: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.42.34433/bin/Hostx64/x64/cl.exe
All requested packages are currently installed.
Total install time: 1.3 us
The package boost-asio is compatible with built-in CMake targets of FindBoost.cmake:

    find_package(Boost REQUIRED COMPONENTS asio)
    target_link_libraries(main PRIVATE Boost::asio)

or the generated cmake configs via:

    find_package(boost_asio REQUIRED CONFIG)
    target_link_libraries(main PRIVATE Boost::asio)

The package boost-beast is compatible with built-in CMake targets of FindBoost.cmake:

    find_package(Boost REQUIRED COMPONENTS beast)
    target_link_libraries(main PRIVATE Boost::beast)

or the generated cmake configs via:

    find_package(boost_beast REQUIRED CONFIG)
    target_link_libraries(main PRIVATE Boost::beast)

The package boost-program-options is compatible with built-in CMake targets of FindBoost.cmake:

    find_package(Boost REQUIRED COMPONENTS program_options)
    target_link_libraries(main PRIVATE Boost::program_options)

or the generated cmake configs via:

    find_package(boost_program_options REQUIRED CONFIG)
    target_link_libraries(main PRIVATE Boost::program_options)

The package boost-url is compatible with built-in CMake targets of FindBoost.cmake:

    find_package(Boost REQUIRED COMPONENTS url)
    target_link_libraries(main PRIVATE Boost::url)

or the generated cmake configs via:

    find_package(boost_url REQUIRED CONFIG)
    target_link_libraries(main PRIVATE Boost::url)

The package boost-uuid is compatible with built-in CMake targets of FindBoost.cmake:

    find_package(Boost REQUIRED COMPONENTS uuid)
    target_link_libraries(main PRIVATE Boost::uuid)

or the generated cmake configs via:

    find_package(boost_uuid REQUIRED CONFIG)
    target_link_libraries(main PRIVATE Boost::uuid)

cjson provides CMake targets:

  # this is heuristically generated, and may not be correct
  find_package(cJSON CONFIG REQUIRED)
  target_link_libraries(main PRIVATE cjson)

cjson provides pkg-config modules:

  # Ultralightweight JSON parser in ANSI C
  libcjson

The package zlib is compatible with built-in CMake targets:

    find_package(ZLIB REQUIRED)
    target_link_libraries(main PRIVATE ZLIB::ZLIB)

curl is compatible with built-in CMake targets:

    find_package(CURL REQUIRED)
    target_link_libraries(main PRIVATE CURL::libcurl)

The package fmt provides CMake targets:

    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt)

    # Or use the header-only version
    find_package(fmt CONFIG REQUIRED)
    target_link_libraries(main PRIVATE fmt::fmt-header-only)

The package gtest is compatible with built-in CMake targets:

    enable_testing()

    find_package(GTest CONFIG REQUIRED)
    target_link_libraries(main PRIVATE GTest::gtest GTest::gtest_main GTest::gmock GTest::gmock_main)

    add_test(AllTestsInMain main)

jwt-cpp is header-only and can be used from CMake via:

  find_path(JWT_CPP_INCLUDE_DIRS "jwt-cpp/base.h")
  target_include_directories(main PRIVATE ${JWT_CPP_INCLUDE_DIRS})

openssl is compatible with built-in CMake targets:

  find_package(OpenSSL REQUIRED)
  target_link_libraries(main PRIVATE OpenSSL::SSL)
  target_link_libraries(main PRIVATE OpenSSL::Crypto)

libarchive is compatible with the CMake Find Module:

  find_package(LibArchive REQUIRED)
  target_link_libraries(main PRIVATE LibArchive::LibArchive) # since CMake 3.17

libarchive provides pkg-config modules:

  # library that can create and read several streaming archive formats
  libarchive

Use this package via the module FindLua that comes with CMake. To use in your CMakeLists.txt:

    include(FindLua)
    find_package(Lua REQUIRED)
    target_link_libraries(main PRIVATE ${LUA_LIBRARIES})
    target_include_directories(main PRIVATE ${LUA_INCLUDE_DIR})

For more information about the variables set by this module, please see:
    https://cmake.org/cmake/help/latest/module/FindLua.html
The package nlohmann-json provides CMake targets:

    find_package(nlohmann_json CONFIG REQUIRED)
    target_link_libraries(main PRIVATE nlohmann_json::nlohmann_json)

The package nlohmann-json can be configured to not provide implicit conversions via a custom triplet file:

    set(nlohmann-json_IMPLICIT_CONVERSIONS OFF)

For more information, see the docs here:

    https://json.nlohmann.me/api/macros/json_use_implicit_conversions/

The package spdlog provides CMake targets:

    find_package(spdlog CONFIG REQUIRED)
    target_link_libraries(main PRIVATE spdlog::spdlog)

    # Or use the header-only version
    find_package(spdlog CONFIG REQUIRED)
    target_link_libraries(main PRIVATE spdlog::spdlog_header_only)

sqlite3 provides pkgconfig bindings.
sqlite3 provides CMake targets:

    find_package(unofficial-sqlite3 CONFIG REQUIRED)
    target_link_libraries(main PRIVATE unofficial::sqlite3::sqlite3)

sqlitecpp provides CMake targets:

  # this is heuristically generated, and may not be correct
  find_package(SQLiteCpp CONFIG REQUIRED)
  target_link_libraries(main PRIVATE SQLiteCpp)

yaml-cpp provides CMake targets:

  # this is heuristically generated, and may not be correct
  find_package(yaml-cpp CONFIG REQUIRED)
  target_link_libraries(main PRIVATE yaml-cpp::yaml-cpp)

yaml-cpp provides pkg-config modules:

  # A YAML parser and emitter for C++
  yaml-cpp

-- Running vcpkg install - done
CMake Deprecation Warning at vcpkg/scripts/buildsystems/vcpkg.cmake:878 (cmake_policy):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.
Call Stack (most recent call first):
  C:/Users/vagrant/wazuh/wazuh-agent/build/CMakeFiles/3.31.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:9 (project)


-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- Source files: C:/Users/vagrant/wazuh/wazuh-agent/src/common/pal/src/windows/pal.c;C:/Users/vagrant/wazuh/wazuh-
agent/src/common/pal/src/windows/pal_string.c;C:/Users/vagrant/wazuh/wazuh-agent/src/common/pal/src/windows/pal_time.c
-- -------------------
-- Wazuh agent modules
-- -------------------
-- Inventory:      ON
-- Logcollector:   ON
-- -------------------
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  modules/inventory/CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio beast
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  modules/logcollector/CMakeLists.txt:19 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio system
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/task_manager/CMakeLists.txt:11 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/agent_info/CMakeLists.txt:11 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: uuid
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/centralized_configuration/CMakeLists.txt:8 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/command_handler/CMakeLists.txt:11 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/communicator/CMakeLists.txt:12 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio beast system url
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/multitype_queue/CMakeLists.txt:14 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio
CMake Warning (dev) at C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/vcpkg-cmake-wrapper.cmake:3 (_find_package):
  Policy CMP0167 is not set: The FindBoost module is removed.  Run "cmake
  --help-policy CMP0167" for policy details.  Use the cmake_policy command to
  set the policy and suppress this warning.

Call Stack (most recent call first):
  vcpkg/scripts/buildsystems/vcpkg.cmake:813 (include)
  agent/CMakeLists.txt:23 (find_package)
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Found Boost: C:/Users/vagrant/wazuh/wazuh-agent/build/vcpkg_installed/x64-windows/share/boost/BoostConfig.cmake (found version "1.85.0") found components: asio beast system program_options
-- Configuring done (4.5s)
-- Generating done (1.2s)
-- Build files have been written to: C:/Users/vagrant/wazuh/wazuh-agent/build
MSBuild version 17.12.12+1cce77968 for .NET Framework

  Logger.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\logger\Debug\Logger.lib
  SQLiteManager.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\sqlite_manager\Debug\SQLiteManager.lib
  AgentInfo.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\agent_info\Debug\AgentInfo.lib
  FilesystemWrapper.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\filesystem_wrapper\Debug\FilesystemWrapper.lib
  CentralizedConfiguration.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\centralized_configuration\Debug\CentralizedConfiguration.lib
  CommandStore.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\command_store\Debug\CommandStore.lib
  CommandHandler.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\command_handler\Debug\CommandHandler.lib
  Communicator.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\communicator\Debug\Communicator.lib
  ConfigurationParser.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\configuration_parser\Debug\ConfigurationParser.lib
  MultiTypeQueue.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\multitype_queue\Debug\MultiTypeQueue.lib
  dbsync.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\lib\Debug\dbsync.lib
  pal.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\pal\Debug\pal.lib
  time_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\time_op\Debug\time_op.lib
  pthreads_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\pthreads_op\Debug\pthreads_op.lib
  sysinfo.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\lib\Debug\sysinfo.lib
  Inventory.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\inventory\Debug\Inventory.lib
  Logcollector.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\logcollector\Debug\Logcollector.lib
  TaskManager.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\task_manager\Debug\TaskManager.lib
  ModuleManager.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\Debug\ModuleManager.lib
  Agent.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\Debug\Agent.lib
  CommandStore_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\command_store\tests\Debug\CommandStore_test.exe
  ConfigurationParserUtils_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\configuration_parser\tests\Debug\ConfigurationParserUtils_test.exe
  ConfigurationParser_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\configuration_parser\tests\Debug\ConfigurationParser_test.exe
  PalTime_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\pal\tests\windows\Debug\PalTime_test.exe
  agent_info_persistance_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\agent_info\tests\Debug\agent_info_persistance_test.exe
  agent_info_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\agent_info\tests\Debug\agent_info_test.exe
  agent_registration_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\tests\Debug\agent_registration_test.exe
  agent_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\tests\Debug\agent_test.exe
  binaries_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\binaries_op\Debug\binaries_op.lib
  centralized_configuration_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\centralized_configuration\tests\Debug\centralized_configuration_test.exe
  command_handler_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\command_handler\tests\Debug\command_handler_test.exe
  communicator_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\communicator\tests\Debug\communicator_test.exe
  http_client_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\communicator\tests\Debug\http_client_test.exe
  inv_normalizer_unit_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\inventory\tests\invNormalizer\Debug\inv_normalizer_unit_test.exe
  inventory_test_tool.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\inventory\testtool\Debug\inventory_test_tool.exe
  inventory_unit_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\inventory\tests\inventory\Debug\inventory_unit_test.exe
  inventoryimp_unit_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\inventory\tests\inventoryImp\Debug\inventoryimp_unit_test.exe
  logcollector_unit_tests.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\logcollector\tests\unit\Debug\logcollector_unit_tests.exe
  logger_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\logger\tests\Debug\logger_test.exe
  mem_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\mem_op\Debug\mem_op.lib
  message_queue_utils_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\tests\Debug\message_queue_utils_test.exe
  module_manager_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\modules\tests\Debug\module_manager_test.exe
  privsep_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\privsep_op\Debug\privsep_op.lib
  randombytes.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\randombytes\Debug\randombytes.lib
  regex_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\regex_op\Debug\regex_op.lib
  signal_handler_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\tests\Debug\signal_handler_test.exe
  task_manager_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\task_manager\tests\Debug\task_manager_test.exe
  test_MultiTypeQueue.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\multitype_queue\tests\Debug\test_MultiTypeQueue.exe
  test_SQLiteManager.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\sqlite_manager\tests\Debug\test_SQLiteManager.exe
  test_sqlitestorage.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\multitype_queue\tests\Debug\test_sqlitestorage.exe
  version_op.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\common\version_op\Debug\version_op.lib
  wazuh-agent.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\Debug\wazuh-agent.exe
        Embedding manifest in C:/Users/vagrant/wazuh/wazuh-agent/build/wazuh-agent
  Embedding manifest in the executable...
  windows_service_test.vcxproj -> C:\Users\vagrant\wazuh\wazuh-agent\build\agent\tests\Debug\windows_service_test.exe

Generate package signed:

PS C:\Users\vagrant\wazuh\wazuh-agent\packages\windows> .\generate_wazuh_msi.ps1 -DEBUG no -SIGN yes 
-CERTIFICATE_PATH ./cert.pfx -CERTIFICATE_PASSWORD "1234" -SIGN_TOOLS_PATH "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64"
Output
MSI_NAME = wazuh-agent.msi
Signing ..\..\build\Debug\*.exe with
Done Adding Additional Store
Successfully signed: ..\..\build\Debug\wazuh-agent.exe
Signing ..\..\build\Debug\*.dll with
Done Adding Additional Store
Successfully signed: ..\..\build\Debug\boost_program_options-vc144-mt-gd-x64-1_85.dll
Successfully signed: ..\..\build\Debug\boost_url-vc144-mt-gd-x64-1_85.dll
Successfully signed: ..\..\build\Debug\cjson.dll
Successfully signed: ..\..\build\Debug\fmtd.dll
Successfully signed: ..\..\build\Debug\libcrypto-3-x64.dll
Successfully signed: ..\..\build\Debug\libssl-3-x64.dll
Successfully signed: ..\..\build\Debug\spdlogd.dll
Successfully signed: ..\..\build\Debug\sqlite3.dll
Successfully signed: ..\..\build\Debug\SQLiteCpp.dll
Successfully signed: ..\..\build\Debug\yaml-cppd.dll
Building MSI installer...
CPack: Create package using WIX
CPack: Install projects
CPack: - Install project: wazuh-agent [Debug]
CPack: Create package
CPack: - package: C:/Users/vagrant/wazuh/wazuh-agent/packages/windows/wazuh-agent.msi generated.
Signing wazuh-agent.msi...
Done Adding Additional Store
Successfully signed: wazuh-agent.msi

Install msi

PS C:\Users\vagrant\wazuh\wazuh-agent\packages\windows> msiexec /i 'C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\wazuh-agent.msi' /l*v install.log
postinstall.ps1 log (contained in install.log file) ``` WixQuietExec: Directory already exists: C:\ProgramData\wazuh-agent WixQuietExec: Directory already exists: C:\ProgramData\wazuh-agent\config WixQuietExec: Creating directory: C:\ProgramData\wazuh-agent\config\shared WixQuietExec: Creating directory: C:\ProgramData\wazuh-agent\var WixQuietExec: Creating directory: C:\ProgramData\wazuh-agent\run WixQuietExec: Directories created successfully. WixQuietExec: Comparing C:\ProgramData\wazuh-agent\config\wazuh-agent.yml with C:\Program Files\wazuh-agent\wazuh-agent.yml WixQuietExec: Current configuration file is identical to the source. No backup needed. WixQuietExec: Config file moved successfully. WixQuietExec: Installing service Wazuh Agent. WixQuietExec: Service Wazuh Agent installed successfully. WixQuietExec: Starting agent. WixQuietExec: Starting service Wazuh Agent. WixQuietExec: Service Wazuh Agent started successfully. WixQuietExec: postinstall.ps1 script completed. ```
  • Event viewer:
[InstallService] Wazuh Agent Service successfully installed.
[ServiceMain] Starting Wazuh Agent.
[ServiceStart] Service Wazuh Agent started successfully.
[ServiceMain] Exception thrown in wazuh-agent: The agent is not registered.
  • Manual register using mockserver:
C:\Users\vagrant\wazuh\wazuh-agent\src\agent\testtool\mock_server (enhancement/134-windows-installer-creation)
λ python mock_server.py --protocol http --outfile test.log
Mock HTTP server running on port 55000
Mock HTTP server running on port 27000
PS C:\Users\vagrant\wazuh\wazuh-agent\packages\windows> & 'C:\Program Files\wazuh-agent\wazuh-agent.exe' --user wazuh --password wazuh --url http://localhost:27000 --name wazuh --register
Starting wazuh-agent registration
wazuh-agent registered

Uninstall msi

PS C:\Users\vagrant\wazuh\wazuh-agent\packages\windows> msiexec /x 'C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\wazuh-agent.msi' /l*v uninstall.log
cleanup.ps1 log (contained in uninstall.log file)
WixQuietExec:  Running cleanup.ps1 for path C:\ProgramData\wazuh-agent
WixQuietExec:  Skipping file (exception): C:\ProgramData\wazuh-agent\config\wazuh-agent.yml
WixQuietExec:  Removing file: C:\ProgramData\wazuh-agent\var\agent_info.db
WixQuietExec:  Removing file: C:\ProgramData\wazuh-agent\var\command_store.db
WixQuietExec:  Removing file: C:\ProgramData\wazuh-agent\var\queue.db
WixQuietExec:  Removing empty directory: C:\ProgramData\wazuh-agent\var
WixQuietExec:  Removing empty directory: C:\ProgramData\wazuh-agent\run
WixQuietExec:  Removing empty directory: C:\ProgramData\wazuh-agent\config\shared
WixQuietExec:  Removing service Wazuh Agent.
WixQuietExec:  Service Wazuh Agent removed successfully.
WixQuietExec:  cleanup.ps1 script completed.
  • Event viewer:
[HandleStopSignal] Wazuh Agent is stopping. Performing cleanup.
[RemoveService] Wazuh Agent Service successfully removed.

Testing upgrade and files

  • Folder and files generated after installation:
C:\PROGRAMDATA\WAZUH-AGENT
├───config
     ├───wazuh-agent.yml
│   └───shared
├───run
└───var
C:\PROGRAM FILES\WAZUH-AGENT
├───boost_container-vc144-mt-gd-x64-1_85.dll
├───boost_context-vc144-mt-gd-x64-1_85.dll
├───boost_coroutine-vc144-mt-gd-x64-1_85.dll
├───boost_date_time-vc144-mt-gd-x64-1_85.dll
├───boost_program_options-vc144-mt-gd-x64-1_85.dll
├───boost_random-vc144-mt-gd-x64-1_85.dll
├───boost_regex-vc144-mt-gd-x64-1_85.dll
├───boost_system-vc144-mt-gd-x64-1_85.dll
├───boost_url-vc144-mt-gd-x64-1_85.dll
├───cjson.dll
├───cleanup.ps1
├───fmtd.dll
├───postinstall.ps1
├───spdlogd.dll
├───sqlite3.dll
├───SQLiteCpp.dll
├───wazuh-agent.exe
└───yaml-cppd.dll
  • After modify config file wazuh-agent.yml, and upgrade agent:
C:\PROGRAMDATA\WAZUH-AGENT
├───config
     ├───wazuh-agent.yml.save
     ├───wazuh-agent.yml
│   └───shared
├───run
└───var
  • After uninstallation of the agent:
C:\PROGRAMDATA\WAZUH-AGENT
└───config
     └───wazuh-agent.yml

@wazuhci wazuhci moved this from In progress to Pending review in XDR+SIEM/Release 5.0.0 Jan 9, 2025
@wazuhci wazuhci moved this from Pending review to In progress in XDR+SIEM/Release 5.0.0 Jan 9, 2025
@jotacarma90
Copy link
Member

Related to new generation scripts

The new scripts can be executed from any working directory.
Certain parameters have been included that must be the same in the execution of both scripts:

  • MSI_NAME: This is the name that the package will end up having, it MUST NOT HAVE the .msi suffix, this will be added automatically.
  • CMAKE_CONFIG: Corresponds to the type of cmake compilation to be used (Debug, Release, RelWithDebInfo or MinSizeRel).

Some parameters are related to the location of the executables of certain tools, these can be configured as environment variables, and then it is not necessary to set them:

  • SIGN_TOOLS_PATH: Signature tool that comes with the Windows Kits.
  • CV2PDB_PATH: Debug symbol extraction tool.

Testing

PS C:\Users\vagrant\wazuh\wazuh-agent> C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\generate_compiled_windows_agent.ps1
-MSI_NAME "testname1" -CMAKE_CONFIG "RelWithDebInfo"

[...]
PS C:\Users\vagrant\wazuh\wazuh-agent> C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\generate_wazuh_msi.ps1
-DEBUG yes -SIGN yes -CERTIFICATE_PATH "C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\cert.pfx"
-CERTIFICATE_PASSWORD "1234" -SIGN_TOOLS_PATH "C:\Program Files (x86)\Windows Kits\10\bin\10.0.22621.0\x64"
-CV2PDB_PATH "C:\Users\vagrant\Downloads\" -MSI_NAME "testname1" -CMAKE_CONFIG "RelWithDebInfo"

MSI_NAME = testname1.msi
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\wazuh-agent.exe
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\boost_program_options-vc144-mt-x64-1_85.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\boost_url-vc144-mt-x64-1_85.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\cjson.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\fmt.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\libcrypto-3-x64.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\libssl-3-x64.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\spdlog.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\sqlite3.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\SQLiteCpp.dll
Extracting dbg symbols from C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo\yaml-cpp.dll
Waiting for processes to finish
Compressing debug symbols to testname1-debug-symbols.zip


    Directory: C:\Users\vagrant\wazuh\wazuh-agent\build\RelWithDebInfo


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          1/9/2025   5:56 AM        9784938 testname1-debug-symbols.zip
Signing C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\*.exe with
Done Adding Additional Store
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\wazuh-agent.exe
Signing C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\*.dll with
Done Adding Additional Store
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\boost_program_options-vc144-mt-x64-1_85.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\boost_url-vc144-mt-x64-1_85.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\cjson.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\fmt.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\libcrypto-3-x64.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\libssl-3-x64.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\spdlog.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\sqlite3.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\SQLiteCpp.dll
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\..\..\build\RelWithDebInfo\yaml-cpp.dll
Signing C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\postinstall.ps1 with
Done Adding Additional Store
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\postinstall.ps1
Signing C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\cleanup.ps1 with
Done Adding Additional Store
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\cleanup.ps1
Building MSI installer...
CPack: Create package using WIX
CPack: Install projects
CPack: - Install project: wazuh-agent [RelWithDebInfo]
CPack: Create package
CPack: - package: C:/Users/vagrant/wazuh/wazuh-agent/packages/windows/testname1.msi generated.
Signing testname1.msi...
Done Adding Additional Store
Successfully signed: C:\Users\vagrant\wazuh\wazuh-agent\packages\windows\testname1.msi

@wazuhci wazuhci moved this from In progress to Pending review in XDR+SIEM/Release 5.0.0 Jan 9, 2025
@wazuhci wazuhci moved this from Pending review to In review in XDR+SIEM/Release 5.0.0 Jan 21, 2025
@wazuhci wazuhci moved this from In review to Done in XDR+SIEM/Release 5.0.0 Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
level/subtask Subtask issue module/packages Agent packages type/enhancement Enhancement issue
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants