@@ -186,6 +186,40 @@ spec:
186
186
else
187
187
echo "Filesystem is not XFS (detected: $fstype). Skipping xfs_info."
188
188
fi
189
+ - run :
190
+ collectorName : " selinux-labels"
191
+ command : " sh"
192
+ args :
193
+ - -c
194
+ - |
195
+ data_dir="{{ .DataDir }}"
196
+ bin_dir=$data_dir/bin
197
+ # only run our checks if getenforce is available
198
+ if ! $(command -v getenforce); then
199
+ echo "no selinux"
200
+ exit 0
201
+ fi
202
+ # check if selinux is in enforcing mode
203
+ selinux_status=$(getenforce | tr -d '\n')
204
+ if [ "$selinux_status" != "Enforcing" ]; then
205
+ echo "selinux not enforcing"
206
+ exit 0
207
+ fi
208
+ # check user label of data-dir
209
+ data_dir_user_label=$(secon --file $data_dir --user)
210
+ if [ ! "$data_dir_user_label" = "system_u" ]; then
211
+ echo "data_dir_user_label $data_dir_user_label"
212
+ fi
213
+ # check user label of bin dir
214
+ bin_dir_user_label=$(secon --file $bin_dir --user)
215
+ if [ ! "$bin_dir_user_label" = "system_u" ]; then
216
+ echo "bin_dir_user_label $bin_dir_user_label"
217
+ fi
218
+ # check type label of bin dir
219
+ bin_dir_type_label=$(secon --file $bin_dir --type)
220
+ if [ ! "$bin_dir_type_label" = "bin_t" ]; then
221
+ echo "bin_dir_type_label $bin_dir_type_label"
222
+ fi
189
223
analyzers :
190
224
- cpu :
191
225
checkName : CPU
@@ -1202,3 +1236,39 @@ spec:
1202
1236
- pass :
1203
1237
when : " false"
1204
1238
message : " The filesystem at {{ .DataDir }} is either not XFS or is XFS with ftype=1."
1239
+ - textAnalyze :
1240
+ checkName : " Selinux data-dir user label"
1241
+ fileName : host-collectors/run-host/selinux-labels.txt
1242
+ regex : " data_dir_user_label"
1243
+ outcomes :
1244
+ - fail :
1245
+ when : " true"
1246
+ message : |
1247
+ The selinux user context label for {{ .DataDir }} is incorrect.
1248
+ try running : sudo restorecon -RvF {{ .DataDir }}
1249
+ - pass :
1250
+ when : " false"
1251
+ - textAnalyze :
1252
+ checkName : " Selinux bin dir user label"
1253
+ fileName : host-collectors/run-host/selinux-labels.txt
1254
+ regex : " bin_dir_user_label"
1255
+ outcomes :
1256
+ - fail :
1257
+ when : " true"
1258
+ message : |
1259
+ The selinux user context label for {{ .DataDir }}/bin is incorrect.
1260
+ Try running: sudo semanage fcontext -a -t bin_t "{{ .DataDir }}/bin(/.*)?" && sudo restorecon -RvF {{ .DataDir }}
1261
+ - pass :
1262
+ when : " false"
1263
+ - textAnalyze :
1264
+ checkName : " Selinux bin dir type label"
1265
+ fileName : host-collectors/run-host/selinux-labels.txt
1266
+ regex : " bin_dir_type_label"
1267
+ outcomes :
1268
+ - fail :
1269
+ when : " true"
1270
+ message : |
1271
+ The selinux type context label for the embedded cluster binary directory are incorrect.
1272
+ Try running : sudo restorecon -RvF {{ .DataDir }}
1273
+ - pass :
1274
+ when : " false"
0 commit comments