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

Generate debug information packages #1583

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
9 changes: 9 additions & 0 deletions debs/SPECS/wazuh-agent/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,12 @@ Depends: ${shlibs:Depends}, libc6 (>= 2.7), lsb-release, debconf, adduser
Conflicts: ossec-hids-agent, wazuh-manager, ossec-hids, wazuh-api
Breaks: ossec-hids-agent, wazuh-manager, ossec-hids
Description: Wazuh helps you to gain security visibility into your infrastructure by monitoring hosts at an operating system and application level. It provides the following capabilities: log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring

Package: wazuh-agent-dbg
Architecture: any
Section: devel
Conflicts: wazuh-agent (<< ${binary:Version}), wazuh-agent (>> ${binary:Version})
Replaces: wazuh-agent-dbg
Description: Wazuh helps you to gain security visibility into your infrastructure by monitoring hosts at an operating system and application level. It provides the following capabilities: log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring.
.
This package contains files necessary for debugging the wazuh-agent with gdb.
11 changes: 8 additions & 3 deletions debs/SPECS/wazuh-agent/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export DH_VERBOSE=1
export DH_OPTIONS

export TARGET_DIR=${CURDIR}/debian/wazuh-agent
export TARGET_DIR_SYMS=${CURDIR}/debian/wazuh-agent-dbg

# Package build options
export INSTALLATION_DIR="/var/ossec"
Expand All @@ -40,7 +41,7 @@ override_dh_install:
rm -rf $(INSTALLATION_DIR)/

# Build the binaries
make -C src deps TARGET=agent
make -j$(JOBS) -C src deps TARGET=agent
make -j$(JOBS) -C src/ TARGET=agent USE_SELINUX=yes DEBUG=$(DEBUG_ENABLED)

USER_LANGUAGE="en" \
Expand All @@ -58,6 +59,7 @@ override_dh_install:
USER_AGENT_SERVER_IP="MANAGER_IP" \
USER_CA_STORE="/path/to/my_cert.pem" \
USER_AUTO_START="n" \
USER_DEBUG_SYMBOLS="y" \
./install.sh

# Copying init.d script
Expand Down Expand Up @@ -145,11 +147,14 @@ override_dh_install:
sed -i "s:WAZUH_HOME_TMP:${INSTALLATION_DIR}:g" src/init/templates/wazuh-agent.service
cp src/init/templates/wazuh-agent.service ${TARGET_DIR}/etc/systemd/system/

# Add debug symbols
mkdir -p ${TARGET_DIR_SYMS}/${INSTALLATION_DIR}
mv ${TARGET_DIR}/${INSTALLATION_DIR}/.symbols ${TARGET_DIR_SYMS}/${INSTALLATION_DIR}/.symbols

override_dh_auto_clean:
$(MAKE) -C src clean
$(MAKE) -j$(JOBS) -C src clean


override_dh_strip:
dh_strip --no-automatic-dbgsym

.PHONY: override_dh_install override_dh_strip override_dh_auto_clean override_dh_auto_build override_dh_auto_configure
9 changes: 9 additions & 0 deletions debs/SPECS/wazuh-manager/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,12 @@ Suggests: expect
Conflicts: ossec-hids-agent, wazuh-agent, ossec-hids, wazuh-api
Replaces: wazuh-api
Description: Wazuh helps you to gain security visibility into your infrastructure by monitoring hosts at an operating system and application level. It provides the following capabilities: log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring

Package: wazuh-manager-dbg
Architecture: any
Section: devel
Conflicts: wazuh-manager (<< ${binary:Version}), wazuh-manager (>> ${binary:Version})
Replaces: wazuh-manager-dbg
Description: Wazuh helps you to gain security visibility into your infrastructure by monitoring hosts at an operating system and application level. It provides the following capabilities: log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring.
.
This package contains files necessary for debugging the wazuh-manager with gdb.
8 changes: 7 additions & 1 deletion debs/SPECS/wazuh-manager/debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ export DH_VERBOSE=1
# This has to be exported to make some magic below work.
export DH_OPTIONS
export PKG_DIR=debian/wazuh-manager
export DBG_DIR=debian/wazuh-manager-dbg

export TARGET_DIR=${CURDIR}/${PKG_DIR}
export TARGET_DIR_SYMS=${CURDIR}/${DBG_DIR}

# Package build options
export INSTALLATION_DIR="/var/ossec"
Expand Down Expand Up @@ -64,6 +66,7 @@ override_dh_install:
USER_GENERATE_AUTHD_CERT="y" \
USER_AUTO_START="n" \
USER_CREATE_SSL_CERT="n" \
USER_DEBUG_SYMBOLS="y" \
./install.sh

# Copying init.d script
Expand Down Expand Up @@ -199,6 +202,10 @@ override_dh_install:
cp etc/templates/config/ubuntu/20/04/sca.files ${TARGET_DIR}$(INSTALLATION_SCRIPTS_DIR)/sca/ubuntu/20/04
cp etc/templates/config/ubuntu/22/04/sca.files ${TARGET_DIR}$(INSTALLATION_SCRIPTS_DIR)/sca/ubuntu/22/04

# Add debug symbols
mkdir -p ${TARGET_DIR_SYMS}/${INSTALLATION_DIR}
mv ${TARGET_DIR}/${INSTALLATION_DIR}/.symbols ${TARGET_DIR_SYMS}/${INSTALLATION_DIR}/.symbols

override_dh_fixperms:
dh_fixperms
# Fix Python permissions
Expand All @@ -213,6 +220,5 @@ override_dh_auto_clean:
$(MAKE) -C src clean

override_dh_strip:
dh_strip --no-automatic-dbgsym --exclude=dh_strip --no-automatic-dbgsym --exclude=${PKG_DIR}${INSTALLATION_DIR}/framework/python

.PHONY: override_dh_install override_dh_strip override_dh_auto_clean override_dh_auto_build override_dh_auto_configure override_dh_fixperms
9 changes: 5 additions & 4 deletions debs/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,6 @@ if [ "${build_target}" == "api" ]; then
fi
fi

if [[ "${debug}" == "yes" ]]; then
sed -i "s:dh_strip --no-automatic-dbgsym::g" ${sources_dir}/debian/rules
fi

# Installing build dependencies
cd ${sources_dir}
mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y"
Expand All @@ -114,14 +110,19 @@ else
fi

deb_file="wazuh-${build_target}_${wazuh_version}-${package_release}"
dbg_file="wazuh-${build_target}-dbg_${wazuh_version}-${package_release}"
if [[ "${architecture_target}" == "ppc64le" ]]; then
deb_file="${deb_file}_ppc64el.deb"
dbg_file="${dbg_file}_ppc64el.deb"
else
deb_file="${deb_file}_${architecture_target}.deb"
dbg_file="${dbg_file}_${architecture_target}.deb"
fi
pkg_path="${build_dir}/${build_target}"

if [[ "${checksum}" == "yes" ]]; then
cd ${pkg_path} && sha512sum ${deb_file} > /var/local/checksum/${deb_file}.sha512
fi
mv ${pkg_path}/${deb_file} /var/local/wazuh
mv ${pkg_path}/${dbg_file} /var/local/wazuh

4 changes: 2 additions & 2 deletions debs/generate_debian_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ build_deb() {
${CHECKSUM} ${PACKAGES_BRANCH} ${USE_LOCAL_SPECS} \
${USE_LOCAL_SOURCE_CODE} ${FUTURE}|| return 1

echo "Package $(ls -Art ${OUTDIR} | tail -n 1) added to ${OUTDIR}."
echo "Package $(ls -Art ${OUTDIR} | tail -n 2) added to ${OUTDIR}."

return 0
}
Expand Down Expand Up @@ -149,7 +149,7 @@ help() {
echo " -r, --revision <rev> [Optional] Package revision. By default: 1."
echo " -s, --store <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -p, --path <path> [Optional] Installation path for the package. By default: /var/ossec."
echo " -d, --debug [Optional] Build the binaries with debug symbols. By default: no."
echo " -d, --debug [Optional] Build the binaries without optimizations. By default: no."
echo " -c, --checksum <path> [Optional] Generate checksum on the desired path (by default, if no path is specified it will be generated on the same directory than the package)."
echo " --dont-build-docker [Optional] Locally built docker image will be used instead of generating a new one."
echo " --sources <path> [Optional] Absolute path containing wazuh source code. This option will use local source code instead of downloading it from GitHub."
Expand Down
1 change: 1 addition & 0 deletions macos/generate_wazuh_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ function build_package() {
mkdir -p ${CHECKSUMDIR}
cd ${DESTINATION} && shasum -a512 "${pkg_name}" > "${CHECKSUMDIR}/${pkg_name}.sha512"
fi
tar -C ${WAZUH_PATH}/src/symbols -czf ${DESTINATION}wazuh-agent-macos-amd64-debug-info-${VERSION}-${REVISION}.tar.gz .
clean_and_exit 0
else
echo "ERROR: something went wrong while building the package."
Expand Down
1 change: 1 addition & 0 deletions macos/package_files/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function configure() {
echo USER_ENABLE_CISCAT="n" >> ${CONFIG}
echo USER_ENABLE_ACTIVE_RESPONSE="y" >> ${CONFIG}
echo USER_CA_STORE="n" >> ${CONFIG}
echo USER_DEBUG_SYMBOLS="y" >> ${CONFIG}
}

function build() {
Expand Down
31 changes: 21 additions & 10 deletions rpms/SPECS/wazuh-agent.spec
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ Wazuh helps you to gain security visibility into your infrastructure by monitori
hosts at an operating system and application level. It provides the following capabilities:
log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring

%package -n wazuh-agent-debuginfo
Summary: Debug info for Wazuh
Group: Development/Libraries
Requires: wazuh-agent = %{version}-%{release}

%description -n wazuh-agent-debuginfo
This package contains files necessary for debugging the wazuh-agent with gdb.

%prep
%setup -q

Expand All @@ -40,14 +48,14 @@ pushd src
make clean

%if 0%{?el} >= 6 || 0%{?rhel} >= 6
make deps TARGET=agent
make -j%{_threads} deps TARGET=agent
make -j%{_threads} TARGET=agent USE_SELINUX=yes DEBUG=%{_debugenabled}
%else
%ifnarch x86_64
MSGPACK="USE_MSGPACK_OPT=no"
%endif
deps_version=`cat Makefile | grep "DEPS_VERSION =" | cut -d " " -f 3`
make deps RESOURCES_URL=http://packages.wazuh.com/deps/${deps_version} TARGET=agent
make -j%{_threads} deps RESOURCES_URL=http://packages.wazuh.com/deps/${deps_version} TARGET=agent
make -j%{_threads} TARGET=agent USE_AUDIT=no USE_SELINUX=yes USE_EXEC_ENVIRON=no DEBUG=%{_debugenabled} ${MSGPACK}

%endif
Expand All @@ -73,6 +81,7 @@ echo 'USER_UPDATE="n"' >> ./etc/preloaded-vars.conf
echo 'USER_AGENT_SERVER_IP="MANAGER_IP"' >> ./etc/preloaded-vars.conf
echo 'USER_CA_STORE="/path/to/my_cert.pem"' >> ./etc/preloaded-vars.conf
echo 'USER_AUTO_START="n"' >> ./etc/preloaded-vars.conf
echo 'USER_DEBUG_SYMBOLS="y"' >> ./etc/preloaded-vars.conf
./install.sh

%if 0%{?el} < 6 || 0%{?rhel} < 6
Expand Down Expand Up @@ -171,9 +180,10 @@ install -m 0640 src/init/*.sh ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/
cp src/VERSION ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/agent_installation_scripts/src/
cp src/REVISION ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/agent_installation_scripts/src/

if [ %{_debugenabled} = "yes" ]; then
%{_rpmconfigdir}/find-debuginfo.sh
fi
# Add debug symbols
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/.symbols
cp src/symbols/* ${RPM_BUILD_ROOT}%{_localstatedir}/.symbols

exit 0

%pre
Expand Down Expand Up @@ -500,8 +510,10 @@ rm -fr %{buildroot}
%dir %attr(750, root, wazuh) %{_localstatedir}/active-response
%dir %attr(750, root, wazuh) %{_localstatedir}/active-response/bin
%attr(750, root, wazuh) %{_localstatedir}/active-response/bin/*
%attr(750, root, root) %{_localstatedir}/active-response/bin/.debug
%dir %attr(750, root, root) %{_localstatedir}/bin
%attr(750, root, root) %{_localstatedir}/bin/*
%attr(750, root, root) %{_localstatedir}/bin/.debug
%dir %attr(750, root, wazuh) %{_localstatedir}/backup
%dir %attr(770, wazuh, wazuh) %{_localstatedir}/etc
%attr(640, root, wazuh) %config(noreplace) %{_localstatedir}/etc/client.keys
Expand All @@ -514,6 +526,7 @@ rm -fr %{buildroot}
%attr(660, root, wazuh) %config(missingok,noreplace) %{_localstatedir}/etc/shared/*
%dir %attr(750, root, wazuh) %{_localstatedir}/lib
%attr(750, root, wazuh) %{_localstatedir}/lib/*
%attr(750, root, root) %{_localstatedir}/lib/.debug
%dir %attr(770, wazuh, wazuh) %{_localstatedir}/logs
%attr(660, wazuh, wazuh) %ghost %{_localstatedir}/logs/active-responses.log
%attr(660, root, wazuh) %ghost %{_localstatedir}/logs/ossec.log
Expand Down Expand Up @@ -612,11 +625,9 @@ rm -fr %{buildroot}
%dir %attr(750, root, wazuh) %{_localstatedir}/wodles/gcloud
%attr(750, root, wazuh) %{_localstatedir}/wodles/gcloud/*

%if %{_debugenabled} == "yes"
/usr/lib/debug/%{_localstatedir}/*
/usr/src/debug/%{name}-%{version}/*
%endif

%files -n wazuh-agent-debuginfo
%dir %attr(750, root, root) %{_localstatedir}/.symbols
%attr(640, root, root) %{_localstatedir}/.symbols/*

%changelog
* Fri May 05 2023 support <[email protected]> - 4.5.0
Expand Down
28 changes: 20 additions & 8 deletions rpms/SPECS/wazuh-manager.spec
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ Wazuh helps you to gain security visibility into your infrastructure by monitori
hosts at an operating system and application level. It provides the following capabilities:
log analysis, file integrity monitoring, intrusions detection and policy and compliance monitoring

%package -n wazuh-manager-debuginfo
Summary: Debug info for Wazuh
Group: Development/Libraries
Requires: wazuh-manager = %{version}-%{release}

%description -n wazuh-manager-debuginfo
This package contains files necessary for debugging the wazuh-manager with gdb.

%prep
%setup -q

Expand All @@ -37,7 +45,7 @@ pushd src
make clean

# Build Wazuh sources
make deps TARGET=server
make -j%{_threads} deps TARGET=server
make -j%{_threads} TARGET=server USE_SELINUX=yes DEBUG=%{_debugenabled}

popd
Expand Down Expand Up @@ -67,6 +75,7 @@ echo 'USER_CA_STORE="/path/to/my_cert.pem"' >> ./etc/preloaded-vars.conf
echo 'USER_GENERATE_AUTHD_CERT="y"' >> ./etc/preloaded-vars.conf
echo 'USER_AUTO_START="n"' >> ./etc/preloaded-vars.conf
echo 'USER_CREATE_SSL_CERT="n"' >> ./etc/preloaded-vars.conf
echo 'USER_DEBUG_SYMBOLS="y"' >> ./etc/preloaded-vars.conf
./install.sh

# Create directories
Expand Down Expand Up @@ -166,9 +175,10 @@ install -m 0640 src/init/*.sh ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/
cp src/VERSION ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/manager_installation_scripts/src/
cp src/REVISION ${RPM_BUILD_ROOT}%{_localstatedir}/packages_files/manager_installation_scripts/src/

if [ %{_debugenabled} = "yes" ]; then
%{_rpmconfigdir}/find-debuginfo.sh
fi
# Add debug symbols
mkdir -p ${RPM_BUILD_ROOT}%{_localstatedir}/.symbols
cp src/symbols/* ${RPM_BUILD_ROOT}%{_localstatedir}/.symbols

exit 0

%pre
Expand Down Expand Up @@ -585,6 +595,7 @@ rm -fr %{buildroot}
%dir %attr(750, root, wazuh) %{_localstatedir}/active-response
%dir %attr(750, root, wazuh) %{_localstatedir}/active-response/bin
%attr(750, root, wazuh) %{_localstatedir}/active-response/bin/*
%attr(750, root, root) %{_localstatedir}/active-response/bin/.debug
%dir %attr(750, root, wazuh) %{_localstatedir}/api
%dir %attr(770, root, wazuh) %{_localstatedir}/api/configuration
%attr(660, root, wazuh) %config(noreplace) %{_localstatedir}/api/configuration/api.yaml
Expand Down Expand Up @@ -625,6 +636,7 @@ rm -fr %{buildroot}
%attr(750, root, wazuh) %{_localstatedir}/bin/wazuh-clusterd
%attr(750, root, root) %{_localstatedir}/bin/wazuh-db
%attr(750, root, root) %{_localstatedir}/bin/wazuh-modulesd
%attr(750, root, root) %{_localstatedir}/bin/.debug
%dir %attr(770, wazuh, wazuh) %{_localstatedir}/etc
%attr(660, root, wazuh) %config(noreplace) %{_localstatedir}/etc/ossec.conf
%attr(640, root, wazuh) %config(noreplace) %{_localstatedir}/etc/client.keys
Expand Down Expand Up @@ -661,6 +673,7 @@ rm -fr %{buildroot}
%dir %attr(750, root, wazuh) %{_localstatedir}/integrations
%attr(750, root, wazuh) %{_localstatedir}/integrations/*
%dir %attr(750, root, wazuh) %{_localstatedir}/lib
%attr(750, root, root) %{_localstatedir}/lib/.debug
%attr(750, root, wazuh) %{_localstatedir}/lib/libwazuhext.so
%attr(750, root, wazuh) %{_localstatedir}/lib/libwazuhshared.so
%attr(750, root, wazuh) %{_localstatedir}/lib/libdbsync.so
Expand Down Expand Up @@ -828,10 +841,9 @@ rm -fr %{buildroot}
%dir %attr(750, root, wazuh) %{_localstatedir}/wodles/gcloud
%attr(750, root, wazuh) %{_localstatedir}/wodles/gcloud/*

%if %{_debugenabled} == "yes"
/usr/lib/debug/%{_localstatedir}/*
/usr/src/debug/%{name}-%{version}/*
%endif
%files -n wazuh-manager-debuginfo
%dir %attr(750, root, root) %{_localstatedir}/.symbols
%attr(640, root, root) %{_localstatedir}/.symbols/*


%changelog
Expand Down
3 changes: 3 additions & 0 deletions rpms/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ fi
build_dir=/build_wazuh
rpm_build_dir=${build_dir}/rpmbuild
file_name="wazuh-${build_target}-${wazuh_version}-${package_release}"
dbg_file="wazuh-${build_target}-debuginfo-${wazuh_version}-${package_release}"
rpm_file="${file_name}.${architecture_target}.rpm"
src_file="${file_name}.src.rpm"
pkg_path="${rpm_build_dir}/RPMS/${architecture_target}"
Expand Down Expand Up @@ -80,6 +81,7 @@ if [[ "${future}" == "yes" ]]; then
MINOR=$(echo $base_version | cut -d. -f2)
wazuh_version="${MAJOR}.30.0"
file_name="wazuh-${build_target}-${wazuh_version}-${package_release}"
dbg_file="wazuh-${build_target}-debuginfo-${wazuh_version}-${package_release}"
old_name="wazuh-${build_target}-${base_version}-${package_release}"
package_name=wazuh-${build_target}-${wazuh_version}
old_package_name=wazuh-${build_target}-${base_version}
Expand Down Expand Up @@ -129,3 +131,4 @@ if [[ "${src}" == "yes" ]]; then
fi

find ${extract_path} -maxdepth 3 -type f -name "${file_name}*" -exec mv {} /var/local/wazuh \;
find ${extract_path} -maxdepth 3 -type f -name "${dbg_file}*" -exec mv {} /var/local/wazuh \;
4 changes: 2 additions & 2 deletions rpms/generate_rpm_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ build_rpm() {
${CHECKSUM} ${PACKAGES_BRANCH} ${USE_LOCAL_SPECS} ${SRC} \
${LEGACY} ${USE_LOCAL_SOURCE_CODE} ${FUTURE}|| return 1

echo "Package $(ls -Art ${OUTDIR} | tail -n 1) added to ${OUTDIR}."
echo "Package $(ls -Art ${OUTDIR} | tail -n 2) added to ${OUTDIR}."

return 0
}
Expand Down Expand Up @@ -178,7 +178,7 @@ help() {
echo " -s, --store <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -j, --jobs <number> [Optional] Number of parallel jobs when compiling."
echo " -p, --path <path> [Optional] Installation path for the package. By default: /var/ossec."
echo " -d, --debug [Optional] Build the binaries with debug symbols and create debuginfo packages. By default: no."
echo " -d, --debug [Optional] Build the binaries without optimizations. By default: no."
echo " -c, --checksum <path> [Optional] Generate checksum on the desired path (by default, if no path is specified it will be generated on the same directory than the package)."
echo " --dont-build-docker [Optional] Locally built docker image will be used instead of generating a new one."
echo " --sources <path> [Optional] Absolute path containing wazuh source code. This option will use local source code instead of downloading it from GitHub."
Expand Down
Loading