Skip to content

Commit d2bdf68

Browse files
f-gallandAlexRuiz7
authored andcommitted
Add wazuh-template.json to packages (#116)
* Download wazuh-template.json from wazuh/wazuh repo * Add wazuh-template.json to RPM package spec * Setting wazuh-template.json attributes to 660 * Change wazuh-template.json attributes in debmake_install.sh * Put template download command within a function * Small fixes and format * Apply correct file permissions to the wazuh-template.json --------- Co-authored-by: Álex Ruiz <[email protected]>
1 parent 0d4e6a0 commit d2bdf68

File tree

4 files changed

+76
-56
lines changed

4 files changed

+76
-56
lines changed

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ testfixtures_shared/
6565
.ci/jobs/
6666

6767
# build files generated
68-
doc-tools/missing-doclet/bin/
68+
doc-tools/missing-doclet/bin/
69+
70+
# Wazuh template (currently downloaded from the wazuh/wazuh repo directly)
71+
distribution/src/config/wazuh-template.json

distribution/packages/src/deb/debmake_install.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fi
1818

1919
curdir=$1
2020
product_dir=/usr/share/wazuh-indexer
21-
# config_dir=/etc/wazuh-indexer
21+
config_dir=/etc/wazuh-indexer
2222
data_dir=/var/lib/wazuh-indexer
2323
log_dir=/var/log/wazuh-indexer
2424
pid_dir=/run/wazuh-indexer
@@ -38,5 +38,6 @@ fi
3838

3939
# Change Permissions
4040
chmod -Rf a+rX,u+w,g-w,o-w "${buildroot}"/*
41+
chmod -c 660 "${buildroot}${config_dir}"/wazuh-template.json
4142

4243
exit 0

distribution/packages/src/rpm/wazuh-indexer.rpm.spec

+4-5
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ mkdir -p %{buildroot}%{pid_dir}
6464
mkdir -p %{buildroot}%{product_dir}/plugins
6565
# Install directories/files
6666
cp -a etc usr var %{buildroot}
67-
chmod 0755 %{buildroot}%{product_dir}/bin/*
67+
chmod 0750 %{buildroot}%{product_dir}/bin/*
6868
if [ -d %{buildroot}%{product_dir}/plugins/opensearch-security ]; then
69-
chmod 0755 %{buildroot}%{product_dir}/plugins/opensearch-security/tools/*
69+
chmod 0640 %{buildroot}%{product_dir}/plugins/opensearch-security/tools/*
70+
chmod 0740 %{buildroot}%{product_dir}/plugins/opensearch-security/tools/*.sh
7071
fi
7172
# Pre-populate the folders to ensure rpm build success even without all plugins
7273
mkdir -p %{buildroot}%{config_dir}/opensearch-observability
@@ -192,9 +193,7 @@ exit 0
192193

193194
# Wazuh additional files
194195
%attr(440, %{name}, %{name}) %{product_dir}/VERSION
195-
%attr(750, %{name}, %{name}) %{product_dir}/bin/indexer-security-init.sh
196-
%attr(750, %{name}, %{name}) %{product_dir}/bin/indexer-ism-init.sh
197-
%attr(750, %{name}, %{name}) %{product_dir}/bin/indexer-init.sh
196+
%attr(660, %{name}, %{name}) %{config_dir}/wazuh-template.json
198197

199198
%changelog
200199
* Thu Mar 28 2024 support <[email protected]> - 4.9.0

scripts/build.sh

+66-49
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,48 @@ function usage() {
2424
echo -e "-h help"
2525
}
2626

27-
while getopts ":h:v:q:s:o:p:a:d:r:" arg; do
27+
while getopts ":h:v:q:s:o:p:a:d:r:b:" arg; do
2828
case $arg in
29-
h)
30-
usage
31-
exit 1
32-
;;
33-
v)
34-
VERSION=$OPTARG
35-
;;
36-
q)
37-
QUALIFIER=$OPTARG
38-
;;
39-
s)
40-
SNAPSHOT=$OPTARG
41-
;;
42-
o)
43-
OUTPUT=$OPTARG
44-
;;
45-
p)
46-
PLATFORM=$OPTARG
47-
;;
48-
a)
49-
ARCHITECTURE=$OPTARG
50-
;;
51-
d)
52-
DISTRIBUTION=$OPTARG
53-
;;
54-
r)
55-
REVISION=$OPTARG
56-
;;
57-
:)
58-
echo "Error: -${OPTARG} requires an argument"
59-
usage
60-
exit 1
61-
;;
62-
?)
63-
echo "Invalid option: -${arg}"
64-
exit 1
65-
;;
29+
h)
30+
usage
31+
exit 1
32+
;;
33+
v)
34+
VERSION=$OPTARG
35+
;;
36+
q)
37+
QUALIFIER=$OPTARG
38+
;;
39+
s)
40+
SNAPSHOT=$OPTARG
41+
;;
42+
o)
43+
OUTPUT=$OPTARG
44+
;;
45+
p)
46+
PLATFORM=$OPTARG
47+
;;
48+
a)
49+
ARCHITECTURE=$OPTARG
50+
;;
51+
d)
52+
DISTRIBUTION=$OPTARG
53+
;;
54+
r)
55+
REVISION=$OPTARG
56+
;;
57+
b)
58+
BRANCH=$OPTARG
59+
;;
60+
:)
61+
echo "Error: -${OPTARG} requires an argument"
62+
usage
63+
exit 1
64+
;;
65+
?)
66+
echo "Invalid option: -${arg}"
67+
exit 1
68+
;;
6669
esac
6770
done
6871

@@ -96,16 +99,33 @@ cp -r ./build/local-test-repo/org/opensearch "${OUTPUT}"/maven/org
9699
[ -z "$ARCHITECTURE" ] && ARCHITECTURE=$(uname -m)
97100
[ -z "$DISTRIBUTION" ] && DISTRIBUTION="tar"
98101
[ -z "$REVISION" ] && REVISION="1"
102+
[ -z "$BRANCH" ] && BRANCH="master"
103+
104+
# ====
105+
# Function to download the alerts template
106+
# ====
107+
function download_template() {
108+
echo "Downloading wazuh-template.json"
109+
local download_url="https://raw.githubusercontent.com/wazuh/wazuh/${BRANCH}/extensions/elasticsearch/7.x/wazuh-template.json"
110+
111+
if ! curl -s "${download_url}" -o distribution/src/config/wazuh-template.json; then
112+
echo "Unable to download wazuh-template.json"
113+
return 1
114+
fi
115+
116+
echo "Successfully downloaded wazuh-template.json"
117+
return 0
118+
}
99119

100120
case $PLATFORM-$DISTRIBUTION-$ARCHITECTURE in
101-
linux-tar-x64|darwin-tar-x64)
121+
linux-tar-x64 | darwin-tar-x64)
102122
PACKAGE="tar"
103123
EXT="tar.gz"
104124
TYPE="archives"
105125
TARGET="$PLATFORM-$PACKAGE"
106126
SUFFIX="$PLATFORM-x64"
107127
;;
108-
linux-tar-arm64|darwin-tar-arm64)
128+
linux-tar-arm64 | darwin-tar-arm64)
109129
PACKAGE="tar"
110130
EXT="tar.gz"
111131
TYPE="archives"
@@ -162,25 +182,22 @@ esac
162182

163183
echo "Building OpenSearch for $PLATFORM-$DISTRIBUTION-$ARCHITECTURE"
164184

185+
if ! download_template; then
186+
exit 1
187+
fi
188+
165189
./gradlew ":distribution:$TYPE:$TARGET:assemble" -Dbuild.snapshot="$SNAPSHOT" -Dbuild.version_qualifier="$QUALIFIER"
166190

167191
# Copy artifact to dist folder in bundle build output
168192
echo "Copying artifact to ${OUTPUT}/dist"
169-
# [[ "$SNAPSHOT" == "true" ]] && IDENTIFIER="-SNAPSHOT"
170-
171193

172194
ARTIFACT_BUILD_NAME=$(ls "distribution/$TYPE/$TARGET/build/distributions/" | grep "wazuh-indexer-min.*$SUFFIX.$EXT")
173-
174195
GIT_COMMIT=$(git rev-parse --short HEAD)
175-
176196
WI_VERSION=$(<VERSION)
177-
178-
179197
ARTIFACT_PACKAGE_NAME=wazuh-indexer-min_"$WI_VERSION"-"$REVISION"_"$SUFFIX"_"$GIT_COMMIT"."$EXT"
180198

181-
# [WAZUH] Used by the GH workflow to upload the artifact
182-
183-
echo "$ARTIFACT_PACKAGE_NAME" > "$OUTPUT/artifact_min_name.txt"
199+
# Used by the GH workflow to upload the artifact
200+
echo "$ARTIFACT_PACKAGE_NAME" >"$OUTPUT/artifact_min_name.txt"
184201

185202
mkdir -p "${OUTPUT}/dist"
186203
cp "distribution/$TYPE/$TARGET/build/distributions/$ARTIFACT_BUILD_NAME" "${OUTPUT}/dist/$ARTIFACT_PACKAGE_NAME"

0 commit comments

Comments
 (0)