Bug 291040 - security/wazuh-manager: agent-manager connection doesn't work over TCP
Summary: security/wazuh-manager: agent-manager connection doesn't work over TCP
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Jose Alonso Cardenas Marquez
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-11-16 11:43 UTC by Paweł Krawczyk
Modified: 2026-01-11 10:28 UTC (History)
0 users

See Also:
bugzilla: maintainer-feedback? (acm)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paweł Krawczyk 2025-11-16 11:43:27 UTC
With wazuh-manager 4.12.0 and wazuh-agent 4.12.0 installed on the same network, the agent is unable to obtain a working connection to the manager over TCP, remaining always in the HC_STARTUP state. 

Changing the client-server connection type to <protocol>udp</protocol> magically solves the problem.

This is happening on FreeBSD 14.3, but exactly the same issue had been previously documented on FreeBSD 13.1 with Wazuh 4.3.7:

https://groups.google.com/g/wazuh/c/t0iSFb5ad9Q

I've spent significant amount of time debugging the TCP issues on both machines, excluding possibility of any network or firewall problems, so it seems like there's some nuanced OS-specific bug in Wazuh that prevents TCP connections from working on FreeBSD.
Comment 1 Paweł Krawczyk 2025-11-16 14:43:16 UTC
The root cause seem to be that the os_delwait() function doesn't seem to be working on FreeBSD for either TCP or UDP connections:

https://github.com/wazuh/wazuh/blob/d14109a8dad7da9bb73231c1be656c7675cccfd7/src/shared/wait_op.c#L36

The function's operations is trivial - it just deletes a lock file /var/ossec/queue/sockets/.wait after agent is connected, but until that happens wazuh-agentd doesn't "see" the agent as connected and it forever remains in pending state. After I manually delete the lock file (rm /var/ossec/queue/sockets/.wait) everything suddenly starts working.
Comment 2 Paweł Krawczyk 2025-11-16 17:10:35 UTC
Also reported upstream https://github.com/wazuh/wazuh/issues/33176
Comment 3 Jose Alonso Cardenas Marquez freebsd_committer freebsd_triage 2025-11-17 15:15:51 UTC
(In reply to Paweł Krawczyk from comment #1)

Hello Pawel, did you erase .wait file from manager or agent? I think os_delwait() function is an agent function. I was trying solve this issue from some weeks ago because I have a wazuh-4.14.1 update ready (I'm waiting for 15-RELEASE) and It seems like a manager pthread/mutex issues. Manager is not returning an answer to HC_STARTUP from agent and it could be because a thread is locked in the manager. Try with a wazuh-agent freebsd-based to an manager in other SO like rockylinux for example.
Comment 4 Paweł Krawczyk 2025-11-17 17:23:29 UTC
(In reply to Jose Alonso Cardenas Marquez from comment #3)

Surprisingly, I had to delete the .wait lock on Manager side - the agent was sending the hello messages but manager simply ignored them. After removing .wait lock it suddenly "saw" the agent and communications continued as usual.

Maybe it would be worth adding some debugging messages around all the unlink() syscalls in wait_op.c so see what exactly is causing them to fail? Right now the return is completely ignored.

I suspect some esoteric difference in filesystem unlink() semantics between OSes, maybe related to use of chroot()? I have noticed one more issue in ossec.log on the manager side:

2025/11/17 00:02:19 wazuh-modulesd: CRITICAL: At pthread_mutex_destroy(): Invalid argument

But this one doesn't seem to have any visible impact on Wazuh operations.
Comment 5 Paweł Krawczyk 2025-11-17 17:25:41 UTC
The usage pattern of pthread_mutex_destroy() is also interesting -  there's an error-checking wrapper, but there's also many usages that ignore any errors in that call:

https://github.com/search?q=repo%3Awazuh%2Fwazuh%20pthread_mutex_destroy&type=code
Comment 6 commit-hook freebsd_committer freebsd_triage 2025-12-16 21:00:41 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=e39ac10bca3ca63d6d164f62f9c37547622df938

commit e39ac10bca3ca63d6d164f62f9c37547622df938
Author:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
AuthorDate: 2025-12-16 20:51:35 +0000
Commit:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
CommitDate: 2025-12-16 20:51:35 +0000

    security/wazuh: Update to 4.14.1

    - Python bundle update to 3.11.4
    - wazuh-agent and wazuh-manager : Add support for 15-RELEASE and 16-CURRENT
    - wazuh-agent and wazuh-manager : Improve FreeBSD system information functions
    - wazuh-dashboards : Update version of opensearch to 2.19.3
    - wazuh-manager: Update pkg-message with entries about vulnerability detector
      and indexer connector configuration

    ChangeLog at:   https://documentation.wazuh.com/current/release-notes/release-4-14-1.html
    PR:             290771 290782 291040

 security/wazuh-agent/Makefile                      |   10 +-
 security/wazuh-agent/distinfo                      |   82 +-
 security/wazuh-agent/files/patch-src-Makefile      |   54 +-
 .../patch-src-data_provider-src_sysInfoFreeBSD.cpp |  198 +-
 .../patch-src-shared_modules-utils_stringHelper.h  |   40 +-
 security/wazuh-agent/pkg-plist                     |   15 +
 security/wazuh-dashboard/Makefile                  |    5 +-
 security/wazuh-dashboard/distinfo                  |   10 +-
 security/wazuh-dashboard/pkg-plist                 |  578 +-----
 security/wazuh-indexer/Makefile                    |    3 +-
 security/wazuh-indexer/distinfo                    |    6 +-
 security/wazuh-manager/Makefile                    |   46 +-
 security/wazuh-manager/distinfo                    |  152 +-
 .../files/patch-etc_ossec-server.conf              |   47 +-
 .../patch-src-data_provider-src_sysInfoFreeBSD.cpp |  198 +-
 .../patch-src-shared_modules-utils_stringHelper.h  |   26 +-
 security/wazuh-manager/files/patch-src_Makefile    |   54 +-
 .../files/patch-src_analysisd_analysisd.c (new)    |   79 +
 .../patch-src_external_cpython_Makefile.pre.in     |    8 +-
 .../files/patch-src_headers_pthreads_op.h (new)    |   40 +
 .../files/patch-src_headers_shared.h (new)         |   10 +
 .../files/patch-src_remoted_manager.c (new)        |   16 +
 ...patch-src_shared__modules_router_CMakeLists.txt |   10 +-
 ...tch-src_shared__modules_utils_socketWrapper.hpp |   10 +-
 security/wazuh-manager/files/pkg-message.in        |   34 +-
 .../wazuh-manager/files/pthreads_portable.c (new)  |   91 +
 .../wazuh-manager/files/pthreads_portable.h (new)  |   50 +
 security/wazuh-manager/pkg-plist                   | 2098 +++++++-------------
 security/wazuh-server/Makefile                     |    3 +-
 security/wazuh-server/distinfo                     |   18 +-
 30 files changed, 1750 insertions(+), 2241 deletions(-)
Comment 7 Paweł Krawczyk 2025-12-20 07:53:46 UTC
Fantastic, thank you!
Comment 8 commit-hook freebsd_committer freebsd_triage 2026-01-11 09:03:55 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=055d5c96c56d8cc876451ccb9b0eb80bcac8d72a

commit 055d5c96c56d8cc876451ccb9b0eb80bcac8d72a
Author:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
AuthorDate: 2026-01-11 08:51:51 +0000
Commit:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
CommitDate: 2026-01-11 09:02:57 +0000

    security/wazuh-manager: Improve port

    - Fix issue when agent/manager connection use TCP instead of UDP.
      (Thanks to dtxdf) [1]
    - wazuh-manager settings use TCP by default
    - FreeBSD sca,decoders and rules files were updated to fix some conflict
      issues.
    - Bump PORTREVISION

    PR:             291040
    Reported by:    Paweł Krawczyk <p+freebsd at krvtz.net> [1]

 security/wazuh-manager/Makefile                    |  8 ++---
 security/wazuh-manager/distinfo                    |  4 +--
 .../files/patch-etc_ossec-server.conf              | 10 +++----
 .../files/patch-src-headers_notify_op.h (new)      | 29 ++++++++++++++++++
 .../files/patch-src-shared_notify_op.c (new)       | 29 ++++++++++++++++++
 security/wazuh-manager/files/patch-src_Makefile    | 34 +++++++++++-----------
 .../patch-src_syscheckd_src_db_CMakeLists.txt      | 14 +++++++--
 7 files changed, 96 insertions(+), 32 deletions(-)
Comment 9 commit-hook freebsd_committer freebsd_triage 2026-01-11 09:27:59 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=508a8c8d4b9b836cc1effee7b5f462a53c644501

commit 508a8c8d4b9b836cc1effee7b5f462a53c644501
Author:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
AuthorDate: 2026-01-11 09:25:28 +0000
Commit:     Jose Alonso Cardenas Marquez <acm@FreeBSD.org>
CommitDate: 2026-01-11 09:27:03 +0000

    security/wazuh-agent: Improve port

    - Now wazuh-agent use TCP connection by default
    - FreeBSD sca,decoders and rules files were updated to fix some conflict
      issues.
    - Bump PORTREVISION

    PR:             291040

 security/wazuh-agent/Makefile                         | 4 ++--
 security/wazuh-agent/distinfo                         | 6 +++---
 security/wazuh-agent/files/patch-etc_ossec-agent.conf | 6 +++---
 3 files changed, 8 insertions(+), 8 deletions(-)
Comment 10 Jose Alonso Cardenas Marquez freebsd_committer freebsd_triage 2026-01-11 09:29:37 UTC
Hello Pawel, please try the latest update of wazuh. This fixed TCP connection issue. Thank you for your PR.
Comment 11 Paweł Krawczyk 2026-01-11 10:28:12 UTC
Thank you Jose Alonso, will test it!