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

Make libstdc++ static library for wazuh-agent #375

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

jotacarma90
Copy link
Member

@jotacarma90 jotacarma90 commented Dec 2, 2024

Related issue
#365

Description

We want to make the libstdc++ library static, so that it does not depend on actions that can affect the system in any way. To do this, we need to modify some of the SPECS files from the wazuh-agent package generation.

Test

Current 5.0 master branch agent package dynamic dependences:

root@d72253e361ec:/# ldd /usr/share/wazuh-agent/bin/wazuh-agent
        linux-vdso.so.1 (0x00007ffc15dd3000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007a1436f07000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007a1436f01000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007a1436edf000)
        libstdc++.so.6 => /usr/share/wazuh-agent/lib/libstdc++.so.6 (0x00007a1436c7f000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007a1436c65000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007a1436a91000)
        /lib64/ld-linux-x86-64.so.2 (0x00007a1437055000)

Package testing:
wazuh-agent_5.0.0-0_amd64_845a271d4.zip

Ubuntu 22:

  • Installed (no restarted packagekit, no prompts):
root@ubuntu22:/home/vagrant# apt install /vagrant/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Note, selecting 'wazuh-agent' instead of '/vagrant/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb'
The following NEW packages will be installed:
  wazuh-agent
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/4,325 kB of archives.
After this operation, 15.5 MB of additional disk space will be used.
Get:1 /vagrant/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb wazuh-agent amd64 5.0.0-0 [4,325 kB]
Preconfiguring packages ...
Selecting previously unselected package wazuh-agent.
(Reading database ... 44902 files and directories currently installed.)
Preparing to unpack .../wazuh-agent_5.0.0-0_amd64_845a271d4.deb ...
Unpacking wazuh-agent (5.0.0-0) ...
Setting up wazuh-agent (5.0.0-0) ...
Scanning processes...
Scanning linux images...

Running kernel seems to be up-to-date.

No services need to be restarted.

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.
  • Check:
root@ubuntu22:/home/vagrant# ldd /usr/share/wazuh-agent/bin/wazuh-agent
        linux-vdso.so.1 (0x00007ffc71734000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f53db41f000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f53db41a000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f53db415000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f53db3f5000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f53db1cc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007f53db50d000)
        
root@ubuntu22:/home/vagrant# /usr/share/wazuh-agent/bin/wazuh-agent
[2024-12-02 15:16:54.494] [wazuh-agent] [info] [INFO] [process_options_unix.cpp:24] [StartAgent] Starting wazuh-agent
[2024-12-02 15:16:54.526] [wazuh-agent] [info] [INFO] [inventory.cpp:17] [Start] Starting inventory.
[2024-12-02 15:16:54.527] [wazuh-agent] [info] [INFO] [logcollector.cpp:23] [Start] Logcollector started
[2024-12-02 15:16:54.527] [wazuh-agent] [info] [INFO] [file_reader.cpp:57] [AddLocalfiles] Reading log file: /var/log/auth.log
[2024-12-02 15:16:54.527] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:907] [SyncLoop] Module started.
[2024-12-02 15:16:54.527] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:890] [Scan] Starting evaluation.
[2024-12-02 15:16:54.530] [wazuh-agent] [error] [ERROR] [http_client.cpp:356] [PerformHttpRequestInternal] Error: Error connecting to host: Connection refused.
[2024-12-02 15:16:54.530] [wazuh-agent] [warning] [WARN] [http_client.cpp:244] [AuthenticateWithUuidAndKey] Error: 500.
[2024-12-02 15:16:54.530] [wazuh-agent] [warning] [WARN] [communicator.cpp:31] [SendAuthenticationRequest] Failed to authenticate with the manager. Retrying in 30 seconds.
[2024-12-02 15:16:55.831] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:902] [Scan] Evaluation finished.

Debian 10 from Dockerfile for agent compilation:

  • Removed env vars related to libs:
root@d72253e361ec:/# echo $LD_LIBRARY_PATH 

root@d72253e361ec:/# echo $CPLUS_INCLUDE_PATH

root@d72253e361ec:/# echo $PATH  
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  • Installed:
root@d72253e361ec:/# apt install /share/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb
Reading package lists... Done
Building dependency tree
Reading state information... Done
Note, selecting 'wazuh-agent' instead of '/share/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb'
The following packages were automatically installed and are no longer required:
  cpp-8 lib32gcc1 lib32stdc++6 libapt-inst2.0 libarmadillo9 libasan5 libc6-i386 libclang-common-7-dev libclang1-7    
  libdap25 libdapserver7v5 libffi-dev libgdal20 libgeos-3.7.1 libgeotiff2 libhdf5-103 libhdf5-fortran-102
  libhdf5-hl-fortran-100 libisl19 libjson-c3 libkmlconvenience1 libkmlregionator1 libkmlxsd1 libllvm7 libmpdec2      
  libmpx2 libncurses-dev libnetcdf13 libobjc4 libogdi3.2 libomp-7-dev libomp5-7 libpoppler82 libpython-stdlib        
  libpython2-stdlib libpython3.7-minimal libpython3.7-stdlib libqhull7 libtinfo-dev llvm-7 llvm-7-dev
  llvm-7-runtime python python-minimal python-yaml python2 python2-minimal python2.7 python2.7-minimal
  python3.7-minimal
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
  wazuh-agent
0 upgraded, 1 newly installed, 0 to remove and 427 not upgraded.
Need to get 0 B/4325 kB of archives.
After this operation, 15.5 MB of additional disk space will be used.
Get:1 /share/packages/wazuh-agent_5.0.0-0_amd64_845a271d4.deb wazuh-agent amd64 5.0.0-0 [4325 kB]
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package wazuh-agent.
(Reading database ... 44447 files and directories currently installed.)
Preparing to unpack .../wazuh-agent_5.0.0-0_amd64_845a271d4.deb ...
Unpacking wazuh-agent (5.0.0-0) ...
Setting up wazuh-agent (5.0.0-0) ...
  • Check:
root@d72253e361ec:/# /usr/share/wazuh-agent/bin/wazuh-agent
[2024-12-02 15:11:35.520] [wazuh-agent] [info] [INFO] [process_options_unix.cpp:24] [StartAgent] Starting wazuh-agent
[2024-12-02 15:11:35.524] [wazuh-agent] [info] [INFO] [inventory.cpp:17] [Start] Starting inventory.
[2024-12-02 15:11:35.524] [wazuh-agent] [info] [INFO] [logcollector.cpp:23] [Start] Logcollector started
[2024-12-02 15:11:35.525] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:907] [SyncLoop] Module started.
[2024-12-02 15:11:35.525] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:890] [Scan] Starting evaluation.
[2024-12-02 15:11:35.531] [wazuh-agent] [error] [ERROR] [http_client.cpp:356] [PerformHttpRequestInternal] Error: Error connecting to host: Connection refused.
[2024-12-02 15:11:35.531] [wazuh-agent] [warning] [WARN] [http_client.cpp:244] [AuthenticateWithUuidAndKey] Error: 500.
[2024-12-02 15:11:35.531] [wazuh-agent] [warning] [WARN] [communicator.cpp:31] [SendAuthenticationRequest] Failed to authenticate with the manager. Retrying in 30 seconds.
[2024-12-02 15:11:35.604] [wazuh-agent] [info] [INFO] [inventoryImp.cpp:902] [Scan] Evaluation finished.


root@d72253e361ec:/# ldd /usr/share/wazuh-agent/bin/wazuh-agent
        linux-vdso.so.1 (0x00007fff4bc5d000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007edb66ff2000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007edb66fec000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007edb66fca000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007edb66fb0000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007edb66ddc000)
        /lib64/ld-linux-x86-64.so.2 (0x00007edb67140000)

@jotacarma90 jotacarma90 force-pushed the fix/365-make-libstdc++-static branch 2 times, most recently from fb38a57 to a95d1bd Compare December 2, 2024 14:52
@vikman90 vikman90 merged commit 64afb13 into master Dec 3, 2024
5 checks passed
@vikman90 vikman90 deleted the fix/365-make-libstdc++-static branch December 3, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants