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

Indexer v1 package SPECs #1226

Merged
merged 58 commits into from
Feb 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
1d36ef5
Added first steps into wazuh-indexer package
okynos Dec 16, 2021
33c8355
Updated indexer RPM SPEC to include Elasticsearch migration
okynos Dec 20, 2021
8263dca
Added way to copy certs from relative or absolute path
okynos Dec 23, 2021
6c3eccf
Changed wazuh-indexer.spec to perform clean installation with certifi…
okynos Dec 28, 2021
7792311
Added last changes of service
okynos Dec 31, 2021
2020665
Applied fixes over RPM packages
okynos Jan 3, 2022
1f1bb5c
Added first iteration over Debian Indexer package
okynos Jan 3, 2022
86931db
Improved debian rules spec file
okynos Jan 4, 2022
d8b8f3e
Added improvements on debian package
okynos Jan 5, 2022
d5a7078
Add option to include local o remotly specs
fcaffieri Jan 7, 2022
cb77527
Add option to include local o remotly specs
fcaffieri Jan 7, 2022
f9aac8e
Removed unused md5sums file
okynos Jan 10, 2022
a343063
Changed service name
okynos Jan 10, 2022
054a142
Removed unused code, cleaned code and service call fix
okynos Jan 10, 2022
bc5e50e
Changed service name in RPM SPEC
okynos Jan 10, 2022
af189e1
Merge branch 'poc-indexer' of github.com:wazuh/wazuh-packages into po…
okynos Jan 10, 2022
5f1fbab
Moved files
okynos Jan 10, 2022
a80be29
Removed SPECs folder
okynos Jan 10, 2022
5424b5a
Added Wazuh tools to include into packages
okynos Jan 11, 2022
3b023f4
Minor improvements into the code, added Copyright
okynos Jan 11, 2022
83dc351
Added future and download SPECs option
okynos Jan 11, 2022
78b0632
Update debian SPECs and added better Copyright
okynos Jan 11, 2022
301c73d
Removed centos service
okynos Jan 12, 2022
f8e9a5a
Updated cert tool and added config files
okynos Jan 12, 2022
4a510a7
Added fixes on SPECs and copy of unattended tools
okynos Jan 12, 2022
7160961
Fix volume in RPM
okynos Jan 12, 2022
aa097ff
Changed docker image to ubuntu 16
okynos Jan 12, 2022
50c4004
Improved files copy and roles settings
okynos Jan 12, 2022
99bb339
Fixed minor things of lintian and updated Copyright
okynos Jan 12, 2022
94d95e8
Updated description and included certs download
okynos Jan 14, 2022
0343184
Removed testing comments
okynos Jan 14, 2022
f556144
Changed the way to get current version
okynos Jan 14, 2022
2308dc7
Fixed version calc on --reference option RPM
okynos Jan 14, 2022
064725a
Changed way to get version in DEB and added certs download
okynos Jan 14, 2022
5ab72b8
Added description and downgraded compat
okynos Jan 14, 2022
c55bced
Added preun to stop wazuh-indexer on removal and postun to remove all…
okynos Jan 14, 2022
96480b3
Updated copyright file Debian
okynos Jan 17, 2022
3602442
Unified Debian and RPM prerm and postrm SPECs
okynos Jan 17, 2022
5e59171
Improved postun and preun on RPM SPEC
okynos Jan 17, 2022
68abb6f
Added Fixes of ulimit into limits.conf
okynos Jan 19, 2022
d3f286d
Added restart on upgrade in RPM
okynos Jan 19, 2022
b00a65b
Fix post installation and removal
okynos Jan 24, 2022
415203e
Fixed Debian permissions and improved installation time on Debian and…
okynos Jan 26, 2022
af04e4f
Changed permissions on Debian, improved SPECs to support docker install
okynos Jan 28, 2022
759aff2
Fixed permissions, fixed purge on Debian
okynos Jan 28, 2022
e01205c
Fixed case when sysctl is not available
okynos Jan 31, 2022
0be33c9
Added message if lib directory exists
okynos Jan 31, 2022
1260d77
Fix empty dir case on installation
okynos Jan 31, 2022
32bffb2
Removed securityadmin call
okynos Feb 1, 2022
a22659d
Moved to stack folder
okynos Feb 1, 2022
1a7644c
Changed first release revision
okynos Feb 1, 2022
2ad2a4d
Removed indexer folder
okynos Feb 3, 2022
5950942
Fix comment in postinst
okynos Feb 3, 2022
ea35c66
Fix comment in postinst L40
okynos Feb 3, 2022
e7e9888
Removed CentOS 6 configuration fix
okynos Feb 3, 2022
cfb4b3e
Fixed capital letters
okynos Feb 3, 2022
0d74a75
Fix comment in rules L68
okynos Feb 3, 2022
1fcd99d
Fix RPM SPEC header
okynos Feb 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions stack/indexer/deb/build_package.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/bash

# Wazuh package generator
# Copyright (C) 2015-2021, Wazuh Inc.
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.

CURRENT_PATH="$( cd $(dirname $0) ; pwd -P )"
ARCHITECTURE="amd64"
OUTDIR="${CURRENT_PATH}/output"
REVISION="1"
BUILD_DOCKER="yes"
DEB_AMD64_BUILDER="deb_indexer_builder_amd64"
DEB_BUILDER_DOCKERFILE="${CURRENT_PATH}/docker"
FUTURE="no"

trap ctrl_c INT

clean() {
exit_code=$1

# Clean the files
rm -rf ${DOCKERFILE_PATH}/{*.sh,*.tar.gz,wazuh-*}

exit ${exit_code}
}

ctrl_c() {
clean 1
}

build_deb() {
CONTAINER_NAME="$1"
DOCKERFILE_PATH="$2"

# Copy the necessary files
cp ${CURRENT_PATH}/builder.sh ${DOCKERFILE_PATH}

# Build the Docker image
if [[ ${BUILD_DOCKER} == "yes" ]]; then
docker build -t ${CONTAINER_NAME} ${DOCKERFILE_PATH} || return 1
fi


# Build the Debian package with a Docker container
if [ "${REFERENCE}" ];then
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
${CONTAINER_NAME} ${ARCHITECTURE} ${REVISION} \
${FUTURE} ${REFERENCE} || return 1
else
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
-v ${CURRENT_PATH}/../../..:/root:Z \
${CONTAINER_NAME} ${ARCHITECTURE} \
${REVISION} ${FUTURE} || return 1
fi

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

return 0
}

build() {
BUILD_NAME=""
FILE_PATH=""
if [ "${ARCHITECTURE}" = "x86_64" ] || [ "${ARCHITECTURE}" = "amd64" ]; then
ARCHITECTURE="amd64"
BUILD_NAME="${DEB_AMD64_BUILDER}"
FILE_PATH="${DEB_BUILDER_DOCKERFILE}/${ARCHITECTURE}"
else
echo "Invalid architecture. Choose: amd64 (x86_64 is accepted too)"
return 1
fi
build_deb ${BUILD_NAME} ${FILE_PATH} || return 1

return 0
}

help() {
echo
echo "Usage: $0 [OPTIONS]"
echo
echo " -a, --architecture <arch> [Optional] Target architecture of the package [amd64]."
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 " --reference <ref> [Optional] wazuh-packages branch to download SPECs, not used by default."
echo " --dont-build-docker [Optional] Locally built docker image will be used instead of generating a new one."
echo " --future [Optional] Build test future package x.30.0 Used for development purposes."
echo " -h, --help Show this help."
echo
exit $1
}


main() {
while [ -n "$1" ]
do
case "$1" in
"-h"|"--help")
help 0
;;
"-a"|"--architecture")
if [ -n "$2" ]; then
ARCHITECTURE="$2"
shift 2
else
help 1
fi
;;
"-r"|"--revision")
if [ -n "$2" ]; then
REVISION="$2"
shift 2
else
help 1
fi
;;
"--reference")
if [ -n "$2" ]; then
REFERENCE="$2"
shift 2
else
help 1
fi
;;
"--dont-build-docker")
BUILD_DOCKER="no"
shift 1
;;
"--future")
FUTURE="yes"
shift 1
;;
"-s"|"--store")
if [ -n "$2" ]; then
OUTDIR="$2"
shift 2
else
help 1
fi
;;
*)
help 1
esac
done

build || clean 1

clean 0
}

main "$@"
70 changes: 70 additions & 0 deletions stack/indexer/deb/builder.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

# Wazuh package builder
# Copyright (C) 2015-2022, Wazuh Inc.
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.

set -ex
# Script parameters to build the package
target="wazuh-indexer"
architecture=$1
release=$2
future=$3
spec_reference=$4
directory_base="/usr/share/wazuh-indexer"

if [ -z "${release}" ]; then
release="1"
fi

if [ "${future}" = "yes" ];then
version="99.99.0"
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
else
if [ "${spec_reference}" ];then
version=$(curl -sL https://raw.githubusercontent.com/wazuh/wazuh-packages/${spec_reference}/VERSION | cat)
else
version=$(cat /root/VERSION)
fi
fi

# Build directories
build_dir=/build
pkg_name="${target}-${version}"
pkg_path="${build_dir}/${target}"
sources_dir="${pkg_path}/${pkg_name}"

mkdir -p ${sources_dir}/debian

# Including spec file
if [ "${spec_reference}" ];then
curl -sL https://github.com/wazuh/wazuh-packages/tarball/${spec_reference} | tar zx
cp -r ./wazuh*/stack/indexer/deb/debian/* ${sources_dir}/debian/
cp -r ./wazuh*/* /root/
else
cp -r /root/stack/indexer/deb/debian/* ${sources_dir}/debian/
fi

# Generating directory structure to build the .deb package
cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}"

# Configure the package with the different parameters
sed -i "s:VERSION:${version}:g" ${sources_dir}/debian/changelog
sed -i "s:RELEASE:${release}:g" ${sources_dir}/debian/changelog
sed -i "s:export INSTALLATION_DIR=.*:export INSTALLATION_DIR=${directory_base}:g" ${sources_dir}/debian/rules

# Installing build dependencies
cd ${sources_dir}
mk-build-deps -ir -t "apt-get -o Debug::pkgProblemResolver=yes -y"

# Build package
debuild -b -uc -us

deb_file="${target}_${version}-${release}_${architecture}.deb"

cd ${pkg_path} && sha512sum ${deb_file} > /tmp/${deb_file}.sha512

mv ${pkg_path}/${deb_file} /tmp/
11 changes: 11 additions & 0 deletions stack/indexer/deb/debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
wazuh-indexer (VERSION-RELEASE) unstable; urgency=low

* More info: https://documentation.wazuh.com/current/release-notes/

-- Wazuh, Inc <[email protected]> Wed, 5 Jan 2022 10:00:00 +0000

wazuh-indexer (4.2.5-1) UNRELEASED; urgency=low

* More info: https://documentation.wazuh.com/current/release-notes/

-- Wazuh, Inc <[email protected]> Mon, 15 Nov 2021 16:47:07 +0000
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions stack/indexer/deb/debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8
15 changes: 15 additions & 0 deletions stack/indexer/deb/debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Source: wazuh-indexer
Section: admin
Priority: extra
Maintainer: Wazuh, Inc <[email protected]>
Build-Depends: debhelper (>=9)
Standards-Version: 4.0.0
Homepage: https://www.wazuh.com

Package: wazuh-indexer
Architecture: any
Depends: ${shlibs:Depends}, debconf, adduser, procps
Description: Wazuh indexer is a near real-time full-text search and analytics engine that gathers security-related data into one platform.
This Wazuh central component indexes and stores alerts generated by the Wazuh server.
Wazuh indexer can be configured as a single-node or multi-node cluster, providing scalability and high availability.
Documentation can be found at https://documentation.wazuh.com/current/getting-started/components/wazuh-indexer.html
22 changes: 22 additions & 0 deletions stack/indexer/deb/debian/copyright
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
This work was packaged for Debian by:

Wazuh, Inc <[email protected]> on Fri, 14 Jan 2022 10:00:00 +0000

It was downloaded from:

https://www.wazuh.com

Copyright:

GNU General Public License version 2.

License:

GNU General Public License version 2.

The Debian packaging is:

Copyright (C) 2015-2022 Wazuh, Inc <[email protected]>
alberpilot marked this conversation as resolved.
Show resolved Hide resolved

and is licensed under the GPL version 2,
see "/usr/share/common-licenses/GPL-2".
105 changes: 105 additions & 0 deletions stack/indexer/deb/debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#!/bin/sh
# postinst script for Wazuh-indexer
# Copyright (C) 2015, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
# License (version 2) as published by the FSF - Free Software
# Foundation.

#DEBHELPER#

export NAME=wazuh-indexer
export USER=${NAME}
export GROUP=${NAME}
export CONFIG_DIR=/etc/${NAME}
export INSTALLATION_DIR=/usr/share/${NAME}
export LOG_DIR=/var/log/${NAME}
export PID_DIR=/run/${NAME}
export LIB_DIR=/var/lib/${NAME}
export SYS_DIR=/usr/lib

set -e

#
# This script is executed in the post-installation phase
#
# On Debian,
# $1=configure : is set to 'configure' and if $2 is set, it is an upgrade

# Source the default env file
if [ -f "/etc/default/wazuh-indexer" ]; then
. "/etc/default/wazuh-indexer"
fi

# to pick up /usr/lib/sysctl.d/wazuh-indexer.conf
if command -v systemctl > /dev/null 2>&1; then
systemctl restart systemd-sysctl.service > /dev/null 2>&1 || true
fi

# The codeblock below is using the fact that postinst script is called with the most-recently configured version.
# In other words, a fresh installed will be called like "postinst configure" with no previous version ($2 is null)
if [ -z "$2" ]; then
# If $2 is null, this is an install

# Setting owner and group
chown -R ${USER}:${GROUP} ${CONFIG_DIR}
chown -R ${USER}:${GROUP} ${INSTALLATION_DIR}
chown -R ${USER}:${GROUP} ${LOG_DIR}

# Prepare the RCA reader process for execution
mkdir -p "/var/lib/wazuh-indexer"
echo 'true' > ${LIB_DIR}/performance_analyzer_enabled.conf
echo 'true' > ${LIB_DIR}/rca_enabled.conf
# This is needed by the performance-analyzer service
echo 'false' > ${LIB_DIR}/batch_metrics_enabled.conf
chown ${USER}:${GROUP} ${LIB_DIR}/performance_analyzer_enabled.conf
chown ${USER}:${GROUP} ${LIB_DIR}/rca_enabled.conf
chown ${USER}:${GROUP} ${LIB_DIR}/batch_metrics_enabled.conf
chown ${USER}:${GROUP} ${LIB_DIR}

# ---------------------------------------------------------------------------

# Setting performance analyzer options
CLK_TCK=$(getconf CLK_TCK)
echo >> /etc/wazuh-indexer/jvm.options
echo '## OpenDistro Performance Analyzer' >> /etc/wazuh-indexer/jvm.options
echo "-Dclk.tck=$CLK_TCK" >> /etc/wazuh-indexer/jvm.options
echo "-Djdk.attach.allowAttachSelf=true" >> /etc/wazuh-indexer/jvm.options
echo "-Djava.security.policy=file:///usr/share/wazuh-indexer/plugins/opendistro-performance-analyzer/pa_config/es_security.policy" >> /etc/wazuh-indexer/jvm.options

# ---------------------------------------------------------------------------

# Setting Indexer default configuration
echo "${USER} hard nproc 4096" >> /etc/security/limits.conf
echo "${USER} soft nproc 4096" >> /etc/security/limits.conf
echo "${USER} hard nofile 65535" >> /etc/security/limits.conf
echo "${USER} soft nofile 65535" >> /etc/security/limits.conf

else
# Otherwise it is an upgrade
echo -n "Restarting wazuh-indexer service..."
if command -v systemctl > /dev/null 2>&1 && systemctl is-active --quiet wazuh-indexer > /dev/null 2>&1; then
systemctl daemon-reload > /dev/null 2>&1
systemctl restart wazuh-indexer.service > /dev/null 2>&1

# Check for SysV
elif command -v service > /dev/null 2>&1; then
service wazuh-indexer restart > /dev/null 2>&1

elif [ -x /etc/init.d/wazuh-indexer ]; then
if command -v invoke-rc.d >/dev/null; then
invoke-rc.d wazuh-indexer restart > /dev/null 2>&1
else
/etc/init.d/wazuh-indexer restart > /dev/null 2>&1
fi

# Older Suse linux distributions do not ship with systemd
# but do not have an /etc/init.d/ directory
# this tries to stop the wazuh-indexer service on these
# as well without failing this script
elif [ -x /etc/rc.d/init.d/wazuh-indexer ]; then
/etc/rc.d/init.d/wazuh-indexer restart > /dev/null 2>&1
alberpilot marked this conversation as resolved.
Show resolved Hide resolved
fi
echo " OK"
fi
Loading