blob: c11a94007f09948fbcca9f477bfc20c71177837f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
|
umask 0022
sentinel_name="sentinelone"
group_name="${sentinel_name}"
user_name="${group_name}"
agent_directory="/opt/sentinelone"
binaries_directory=${agent_directory}/bin
home_directory=${agent_directory}/home
configuration_directory=${agent_directory}/configuration
crash_dumps_directory=${agent_directory}/crash_dumps
current_crash_dumps_directory=${crash_dumps_directory}/.current
tracefs_path=${agent_directory}/mount
cgroups_directory=${agent_directory}/cgroups/memory
agent_binary="sentinelone-agent"
default_no_login_location="/usr/sbin/nologin"
installation_persistent_configuration=${configuration_directory}/install_config
installation_persistent_configuration_post_uninst="/tmp/install_config"
s1_agent_management_proxy="undefined"
s1_agent_management_url="undefined"
s1_agent_dv_proxy="undefined"
s1_agent_management_token="undefined"
s1_agent_device_type="undefined"
s1_agent_auto_start="undefined"
s1_agent_customer_id="undefined"
s1_agent_package_was_repacked="undefined"
s1_agent_create_user="undefined"
s1_agent_custom_install_path="undefined"
s1_agent_should_register_service="undefined"
s1_agent_fips_enabled="undefined"
shell_rc_files=(".profile" ".login" ".shrc" ".bashrc" ".zshrc" ".tcshrc" ".kshrc")
root_files_folders=("home" "bin" "lib" "configuration/sentineld" "configuration/sentinelone.service" "ebpfs")
register_service() {
service_type="systemd"
"${binaries_directory}/sentinelctl" control set-service-type ${service_type}
}
assert_user_access() {
command -v setpriv > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
return
fi
uid=`id --user $1`
gid=`id --group $1`
setpriv --reuid $uid --regid $gid --clear-groups /bin/sh -c exit 0 > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
return
fi
setpriv --reuid $uid --regid $gid --clear-groups ls $2 > /dev/null 2>&1
if [[ $? -ne 0 ]]; then
exit 110
fi
}
read_env_var() {
ret_value="undefined"
if [[ $# -ne 1 ]] ; then
return
fi
env_var_name=${1}
s1_var="${!env_var_name}"
if [[ ! -z ${s1_var} ]]; then
ret_value="${s1_var}"
fi
}
read_config_from_file() {
ret_value="undefined"
if [[ $# -ne 2 ]] ; then
return
fi
if [[ -f "${2}" ]]; then
result=$(grep "${1}" "${2}")
value=$(echo "$result" | tail -1 | cut -d= -f2-)
if [[ $value != "" ]]; then
ret_value=$value
fi
fi
}
read_configs(){
if [[ $# -ne 2 && $# -ne 1 ]]; then
return
fi
if [[ "${1}" == "config_file" ]]; then
if [[ $# -ne 2 ]] ; then
return
fi
read_config_from_file "S1_AGENT_MANAGEMENT_PROXY" "${2}"
s1_agent_management_proxy=$ret_value
read_config_from_file "S1_AGENT_DV_PROXY" "${2}"
s1_agent_dv_proxy=$ret_value
read_config_from_file "S1_AGENT_MANAGEMENT_URL" "${2}"
s1_agent_management_url=$ret_value
read_config_from_file "S1_AGENT_MANAGEMENT_TOKEN" "${2}"
s1_agent_management_token=$ret_value
read_config_from_file "S1_AGENT_DEVICE_TYPE" "${2}"
s1_agent_device_type=$ret_value
read_config_from_file "S1_AGENT_AUTO_START" "${2}"
s1_agent_auto_start=$ret_value
read_config_from_file "S1_AGENT_CUSTOMER_ID" "${2}"
s1_agent_customer_id=$ret_value
read_config_from_file "S1_AGENT_CREATE_USER" "${2}"
s1_agent_create_user=$ret_value
read_config_from_file "S1_AGENT_CUSTOM_INSTALL_PATH" "${2}"
s1_agent_custom_install_path=$ret_value
read_config_from_file "S1_AGENT_SHOULD_REGISTER_SERVICE" "${2}"
s1_agent_should_register_service=$ret_value
read_config_from_file "S1_AGENT_FIPS_ENABLED" "${2}"
s1_agent_fips_enabled=$ret_value
else
read_env_var "S1_AGENT_MANAGEMENT_PROXY"
s1_agent_management_proxy=$ret_value
read_env_var "S1_AGENT_DV_PROXY"
s1_agent_dv_proxy=$ret_value
read_env_var "S1_AGENT_MANAGEMENT_URL"
s1_agent_management_url=$ret_value
read_env_var "S1_AGENT_MANAGEMENT_TOKEN"
s1_agent_management_token=$ret_value
read_env_var "S1_AGENT_DEVICE_TYPE"
s1_agent_device_type=$ret_value
read_env_var "S1_AGENT_AUTO_START"
s1_agent_auto_start=$ret_value
read_env_var "S1_AGENT_CUSTOMER_ID"
s1_agent_customer_id=$ret_value
read_env_var "S1_AGENT_CREATE_USER"
s1_agent_create_user=$ret_value
read_env_var "S1_AGENT_CUSTOM_INSTALL_PATH"
s1_agent_custom_install_path=$ret_value
read_env_var "S1_AGENT_SHOULD_REGISTER_SERVICE"
s1_agent_should_register_service=$ret_value
read_env_var "S1_AGENT_FIPS_ENABLED"
s1_agent_fips_enabled=$ret_value
fi
s1_agent_auto_start=$(echo -n "$s1_agent_auto_start" | tr -d '[:space:]')
s1_agent_should_register_service=$(echo -n "$s1_agent_should_register_service" | tr -d '[:space:]')
s1_agent_fips_enabled=$(echo -n "$s1_agent_fips_enabled" | tr -d '[:space:]')
}
__read_configs()
{
if [[ ! -z "${S1_AGENT_INSTALL_CONFIG_PATH}" ]]; then
if [[ -f "${S1_AGENT_INSTALL_CONFIG_PATH}" ]]; then
read_configs "config_file" "${S1_AGENT_INSTALL_CONFIG_PATH}"
fi
else
read_configs "env_var"
fi
}
write_config_to_file () {
if [[ $# -ne 3 ]]; then
return
fi
if [[ "${1}" != "undefined" && "${1}" != "" ]]; then
echo "${2}=${1}" >> ${3}
fi
}
write_configs (){
echo "" > ${installation_persistent_configuration}
write_config_to_file ${s1_agent_management_proxy} "S1_AGENT_MANAGEMENT_PROXY" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_dv_proxy} "S1_AGENT_DV_PROXY" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_management_url} "S1_AGENT_MANAGEMENT_URL" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_management_token} "S1_AGENT_MANAGEMENT_TOKEN" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_device_type} "S1_AGENT_DEVICE_TYPE" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_auto_start} "S1_AGENT_AUTO_START" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_customer_id} "S1_AGENT_CUSTOMER_ID" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_create_user} "S1_AGENT_CREATE_USER" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_custom_install_path} "S1_AGENT_CUSTOM_INSTALL_PATH" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_should_register_service} "S1_AGENT_SHOULD_REGISTER_SERVICE" ${installation_persistent_configuration}
write_config_to_file ${s1_agent_fips_enabled} "S1_AGENT_FIPS_ENABLED" ${installation_persistent_configuration}
}
get_nologin() {
if command -v which > /dev/null 2>&1; then
no_login=$(which nologin)
else
no_login="$default_no_login_location"
fi
}
create_user() {
get_nologin
id -u $user_name &>/dev/null || useradd -r -U -d "${home_directory}" -s "${no_login}" "${user_name}"
getent group ${group_name} &> /dev/null || groupadd ${group_name}
}
create_symlink() {
if [ ! -d "$1" ]; then
mkdir -p "$1"
fi
base_dir="${agent_directory%/*}"
if [ ! -d "$base_dir" ]; then
mkdir -p "$base_dir"
fi
assert_user_access ${user_name} "$1"
ln -s "$1" "$agent_directory"
}
pre_install() {
__read_configs
apply_config_on_agent
create_user
}
apply_config_on_agent() {
if [[ "${s1_agent_custom_install_path}" != "undefined" ]]; then
create_symlink "${s1_agent_custom_install_path}"
fi
}
pre_upgrade() {
read_configs "config_file" "${installation_persistent_configuration}"
umount "${agent_directory}/mount" > /dev/null 2> /dev/null
umount "${agent_directory}/rpm_mount" > /dev/null 2> /dev/null
create_user
}
apply_config_on_agent_post() {
if [[ "${s1_agent_management_proxy}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management proxy set "${s1_agent_management_proxy}"
fi
if [[ "${s1_agent_dv_proxy}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management dv proxy set "${s1_agent_dv_proxy}"
fi
if [[ "${s1_agent_management_token}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management token set "${s1_agent_management_token}"
fi
if [[ "${s1_agent_management_url}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management url set "${s1_agent_management_url}"
fi
if [[ "${s1_agent_device_type}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management type set "${s1_agent_device_type}"
fi
if [[ "${s1_agent_customer_id}" != "undefined" ]]; then
"${binaries_directory}/sentinelctl" management customer_id set "${s1_agent_customer_id}"
fi
if [[ "${s1_agent_fips_enabled}" == "true" ]]; then
"${binaries_directory}/sentinelctl" fips enable
fi
if [[ "${s1_agent_auto_start}" == "true" ]]; then
"${binaries_directory}/sentinelctl" control start
fi
}
post_install() {
__read_configs
write_configs
disable_account_login
register_service
fix_root_owner
create_folders
validate_desktop
apply_config_on_agent_post
systemctl enable --now sentinelone
}
create_folders(){
mkdir ${cgroups_directory} -p
mkdir ${current_crash_dumps_directory} -p
mkdir ${tracefs_path} -p
}
post_upgrade() {
read_configs "config_file" "${installation_persistent_configuration}"
create_folders
disable_account_login
register_service
fix_root_owner
systemctl enable --now sentinelone
}
enable_crash_dumps() {
chmod g+r+x "${binaries_directory}"
chmod g+r "${binaries_directory}/${agent_binary}"
}
fix_root_owner() {
chown ${user_name}:${group_name} "${agent_directory}/" -R
for ((i = 0; i<${#root_files_folders[@]}; i++)); do
chown -R root:root "${agent_directory}/${root_files_folders[$i]}"
done
enable_crash_dumps
}
disable_account_login() {
for ((i = 0; i<${#shell_rc_files[@]}; i++)); do
rm -f "${home_directory}/${shell_rc_files[$i]}"
ln -s "${home_directory}/login.sh" "${home_directory}/${shell_rc_files[$i]}"
done
}
validate_desktop() {
if [ -f "/etc/os-release" ]; then
if grep -q -i "desktop" "/etc/os-release"; then
"${binaries_directory}"/sentinelctl management type set desktop > /dev/null 2>&1
fi
if grep -q -i "workstation" "/etc/os-release"; then
"${binaries_directory}"/sentinelctl management type set desktop > /dev/null 2>&1
fi
fi
}
remove_kprobes() {
kprobe_names=(
"s1chdirenter"
"s1dsoenter"
"s1fcreate"
"s1unlinkenter"
"s1unlinkatenter"
"s1dounlinkatenter"
"s1dounlinkatexit"
"s1renameenter"
"s1renameatenter"
"s1renameat2enter"
"s1dorenameat2enter"
"s1dorenameat2exit"
"s1execve_enter"
"s1execve_exit"
"s1compatexecve_enter"
"s1compatexecve_exit"
"s1_tcp_connect_enter"
"s1_tcp_connect_exit"
"s1_inet_csk_accept_exit"
"s1chmodenter"
"s1fchmodatenter"
"s1dofchmodatenter"
"s1dofchmodatexit"
"s1umount_exit"
"s1dofilpopen_enter"
"s1readdir_enter"
"s1dofilpopen_exit"
"s1dsoexit"
"s1pivotroot_enter"
"s1mount_exit"
"s1readdir_exit"
"s1pivotroot_exit"
"s1imafilefree"
"s1fchdir_enter"
"s1mount_enter"
"s1doaddmount_enter"
"s1umount_enter"
)
fs_type="$(cat /proc/self/mounts | grep sentitrace | cut -d' ' -f3)"
if [ -z "$fs_type" ]; then
return
elif [ "$fs_type" == "debugfs" ]; then
tracefs_path="$tracefs_path/tracing"
fi
for kprobe in ${kprobe_names[@]}; do
current_path="$tracefs_path/events/kprobes/$kprobe"
if [ ! -d "$current_path" ]; then
continue
fi
echo 0 > "$current_path/enable"
done
for kprobe in ${kprobe_names[@]}; do
current_path="$tracefs_path/events/kprobes/$kprobe"
if [ ! -d "$current_path" ]; then
continue
fi
echo "-:$kprobe" > "$tracefs_path/kprobe_events" 2>/dev/null
done
}
pre_remove(){
systemctl disable --now sentinelone
remove_kprobes
umount_mountpoint
umount_rpm
umount_bpffs
remove_user
}
post_remove() {
read_configs "config_file" "${installation_persistent_configuration_post_uninst}"
rm ${agent_directory} -R
}
remove_user() {
userdel "${user_name}"
if [ $(getent group ${group_name}) ]; then
groupdel "${group_name}"
fi
}
umount_mountpoint_impl() {
mount_dir="${agent_directory}/$1"
umount "${mount_dir}" >/dev/null 2>/dev/null
}
umount_mountpoint() {
umount_mountpoint_impl "mount"
}
umount_rpm() {
umount_mountpoint_impl "rpm_mount"
}
umount_bpffs() {
umount_mountpoint_impl "ebpfs/bpf_mount"
}
|