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}
0 commit comments