Skip to content

Commit 9dee4e6

Browse files
committed
kola: Enable SELinux as early as possible
We never really tested SELinux because we enabled it after boot while normally it would be permanently enabled even during (re)boot. We need to enable it via Ignition. Since this won't work with old releases due to policy problems, introduce a flag that the old scripts branches can pass. Note: If tests differ between early and non-early enabling I would rather disable SELinux for those cases and add a comment if and under what future conditions it can be reenabled. The alternative would be to only make them run with the new early mode but this means we reduce test coverage for Stable which is not a good idea.
1 parent ccdd746 commit 9dee4e6

File tree

6 files changed

+15
-2
lines changed

6 files changed

+15
-2
lines changed

Diff for: cmd/kola/options.go

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ func init() {
8181
root.PersistentFlags().StringVarP(&kolaOffering, "offering", "", "basic", "Offering: "+strings.Join(kolaOfferings, ", "))
8282
root.PersistentFlags().StringVarP(&kola.Options.Distribution, "distro", "b", "cl", "Distribution: "+strings.Join(kolaDistros, ", "))
8383
root.PersistentFlags().IntVarP(&kola.TestParallelism, "parallel", "j", 1, "number of tests to run in parallel")
84+
bv(&kola.LateSelinux, "late-selinux", false, "Enable SELinux only after bootup")
8485
sv(&kola.TAPFile, "tapfile", "", "file to write TAP results to")
8586
sv(&kola.Options.BaseName, "basename", "kola", "Cluster name prefix")
8687
ss("debug-systemd-unit", []string{}, "full-unit-name.service to enable SYSTEMD_LOG_LEVEL=debug on. Specify multiple times for multiple units.")

Diff for: kola/harness.go

+2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ var (
7979
TestParallelism int //glue var to set test parallelism from main
8080
TAPFile string // if not "", write TAP results here
8181
TorcxManifestFile string // torcx manifest to expose to tests, if set
82+
LateSelinux bool // delay the switching of SELinux to enforce mode
8283
DevcontainerURL string // dev container to expose to tests, if set
8384
DevcontainerBinhostURL string // dev container binhost URL to use in the devcontainer test
8485
DevcontainerFile string // dev container path to expose to tests, if set
@@ -574,6 +575,7 @@ func runTest(h *harness.H, t *register.Test, pltfrm string, flight platform.Flig
574575
SSHRetries: Options.SSHRetries,
575576
SSHTimeout: Options.SSHTimeout,
576577
DefaultUser: t.DefaultUser,
578+
LateSelinux: LateSelinux,
577579
}
578580
c, err := flight.NewCluster(rconf)
579581
if err != nil {

Diff for: kola/register/register.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const (
3030
NoSSHKeyInUserData Flag = iota // don't inject SSH key into Ignition/cloud-config
3131
NoSSHKeyInMetadata // don't add SSH key to platform metadata
3232
NoEmergencyShellCheck // don't check console output for emergency shell invocation
33-
NoEnableSelinux // don't enable selinux when starting or rebooting a machine
33+
NoEnableSelinux // don't enable selinux
3434
NoKernelPanicCheck // don't check console output for kernel panic
3535
NoVerityCorruptionCheck // don't check console output for verity corruption
3636
NoDisableUpdates // don't disable usage of the public update server

Diff for: platform/cluster.go

+9
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ func (bc *BaseCluster) RenderUserData(userdata *conf.UserData, ignitionVars map[
191191
conf.CopyKeys(keys)
192192
}
193193

194+
if !bc.rconf.NoEnableSelinux && !bc.rconf.LateSelinux {
195+
conf.AddFile("/etc/flatcar/update.conf", "root", `SELINUX=enforcing
196+
SELINUXTYPE=mcs
197+
`, 0644)
198+
// These files used to be deleted but empty files should work, too
199+
conf.AddFile("/etc/audit/rules.d/80-selinux.rules", "root", ``, 0644)
200+
conf.AddFile("/etc/audit/rules.d/99-default.rules", "root", ``, 0644)
201+
}
202+
194203
// disable the public update server by default
195204
if !bc.rconf.NoDisableUpdates {
196205
conf.AddFile("/etc/flatcar/update.conf", "root", `SERVER=disabled

Diff for: platform/platform.go

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ type RuntimeConfig struct {
182182
AllowFailedUnits bool // don't fail CheckMachine if a systemd unit has failed
183183
SSHRetries int // see SSHRetries field in Options
184184
SSHTimeout time.Duration // see SSHTimeout field in Options
185+
LateSelinux bool // see LateSelinux field in Options
185186

186187
// DefaultUser is the user used for SSH connection, it will be created via Ignition when possible.
187188
DefaultUser string

Diff for: platform/util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func StartMachine(m Machine, j *Journal) error {
129129
if err := CheckMachine(context.TODO(), m); err != nil {
130130
return fmt.Errorf("machine %q failed basic checks: %v", m.ID(), err)
131131
}
132-
if !m.RuntimeConf().NoEnableSelinux {
132+
if !m.RuntimeConf().NoEnableSelinux && m.RuntimeConf().LateSelinux {
133133
if err := EnableSelinux(m); err != nil {
134134
return fmt.Errorf("machine %q failed to enable selinux: %v", m.ID(), err)
135135
}

0 commit comments

Comments
 (0)