Skip to content

Commit 1ac13b0

Browse files
dveedenxhebox
authored andcommitted
cluster: check both SELinux status and config
1 parent 73f2c7a commit 1ac13b0

File tree

3 files changed

+35
-9
lines changed

3 files changed

+35
-9
lines changed

pkg/cluster/manager/check.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ func fixFailedChecks(host string, res *operator.CheckResult, t *task.Builder, sy
673673
}
674674
t.Limit(host, fields[0], fields[1], fields[2], fields[3], sudo)
675675
msg = fmt.Sprintf("will try to set '%s'", color.HiBlueString(res.Msg))
676-
case operator.CheckNameSELinux:
676+
case operator.CheckNameSELinuxConf, operator.CheckNameSELinuxStatus:
677677
t.Shell(host,
678678
fmt.Sprintf(
679679
"sed -i 's/^[[:blank:]]*SELINUX=enforcing/SELINUX=disabled/g' %s && %s",

pkg/cluster/operation/check.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ var (
5959
CheckNameNet = "network"
6060
CheckNameLimits = "limits"
6161
CheckNameSysService = "service"
62-
CheckNameSELinux = "selinux"
62+
CheckNameSELinuxConf = "selinux_conf"
63+
CheckNameSELinuxStatus = "selinux_status"
6364
CheckNameCommand = "command"
6465
CheckNameFio = "fio"
6566
CheckNameTHP = "thp"
@@ -567,10 +568,10 @@ func CheckServices(ctx context.Context, e ctxt.Executor, host, service string, d
567568
return result
568569
}
569570

570-
// CheckSELinux checks if SELinux is enabled on the host
571-
func CheckSELinux(ctx context.Context, e ctxt.Executor, sudo bool) *CheckResult {
571+
// CheckSELinuxConf checks if SELinux is enabled on the host
572+
func CheckSELinuxConf(ctx context.Context, e ctxt.Executor, sudo bool) *CheckResult {
572573
result := &CheckResult{
573-
Name: CheckNameSELinux,
574+
Name: CheckNameSELinuxConf,
574575
}
575576
m := module.NewShellModule(module.ShellModuleConfig{
576577
// ignore grep errors, the file may not exist for some systems
@@ -591,9 +592,33 @@ func CheckSELinux(ctx context.Context, e ctxt.Executor, sudo bool) *CheckResult
591592
}
592593

593594
if lines > 0 {
594-
result.Err = fmt.Errorf("SELinux is not disabled")
595-
} else {
596-
result.Msg = "SELinux is disabled"
595+
result.Err = fmt.Errorf("SELinux is not configured to be disabled")
596+
return result
597+
}
598+
result.Msg = "SELinux is disabled in configuration"
599+
return result
600+
}
601+
602+
// CheckSELinuxStatus checks if SELinux is enabled on the host
603+
func CheckSELinuxStatus(ctx context.Context, e ctxt.Executor, sudo bool) *CheckResult {
604+
result := &CheckResult{
605+
Name: CheckNameSELinuxStatus,
606+
}
607+
m := module.NewShellModule(module.ShellModuleConfig{
608+
Command: "getenforce",
609+
Sudo: sudo,
610+
})
611+
stdout, stderr, err := m.Execute(ctx, e)
612+
if err != nil {
613+
result.Err = fmt.Errorf("%w %s", err, stderr)
614+
return result
615+
}
616+
out := strings.Trim(string(stdout), "\n")
617+
if out == "Enforcing" {
618+
result.Err = fmt.Errorf("SELinux is in Enforcing mode, Update the configuration and reboot")
619+
} else if out == "Permissive" {
620+
result.Err = fmt.Errorf("SELinux is in Permissive mode, disabling is recommended")
621+
result.Warn = true
597622
}
598623
return result
599624
}

pkg/cluster/task/check.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ func (c *CheckSys) Execute(ctx context.Context) error {
8282
}
8383
results = append(
8484
results,
85-
operator.CheckSELinux(ctx, e, sudo),
85+
operator.CheckSELinuxConf(ctx, e, sudo),
86+
operator.CheckSELinuxStatus(ctx, e, sudo),
8687
operator.CheckTHP(ctx, e, sudo),
8788
)
8889
storeResults(ctx, c.host, results)

0 commit comments

Comments
 (0)