Skip to content

Commit 15b9e3e

Browse files
jlebonopenshift-merge-robot
authored andcommitted
kola/cluster: add DropLabeledFile for SELinux relabeling
As a follow-up to the previous patch, SELinux labeling should be done before moving the file to its final location so that other apps don't try to access the file with its label incorrect.
1 parent 985d205 commit 15b9e3e

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

mantle/kola/cluster/cluster.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ func (t *TestCluster) ListNativeFunctions() []string {
9292
return t.NativeFuncs
9393
}
9494

95-
// DropFile places file from localPath to ~/ on every machine in cluster
96-
func DropFile(machines []platform.Machine, localPath string) error {
95+
// DropLabeledFile places file from localPath to ~/ on every machine in
96+
// cluster, potentially with a custom SELinux label.
97+
func DropLabeledFile(machines []platform.Machine, localPath, selabel string) error {
9798
in, err := os.Open(localPath)
9899
if err != nil {
99100
return err
@@ -111,13 +112,23 @@ func DropFile(machines []platform.Machine, localPath string) error {
111112
if err := platform.InstallFile(in, m, partial); err != nil {
112113
return err
113114
}
115+
if selabel != "" {
116+
if out, stderr, err := m.SSH(fmt.Sprintf("sudo chcon -t %s %s.partial", selabel, base)); err != nil {
117+
return errors.Wrapf(err, "running chcon on %s.partial: %s: %s", base, out, stderr)
118+
}
119+
}
114120
if out, stderr, err := m.SSH(fmt.Sprintf("mv %[1]s.partial %[1]s", base)); err != nil {
115121
return errors.Wrapf(err, "running mv %[1]s.partial %[1]s: %s: %s", base, out, stderr)
116122
}
117123
}
118124
return nil
119125
}
120126

127+
// DropFile places file from localPath to ~/ on every machine in cluster
128+
func DropFile(machines []platform.Machine, localPath string) error {
129+
return DropLabeledFile(machines, localPath, "")
130+
}
131+
121132
// SSH runs a ssh command on the given machine in the cluster. It differs from
122133
// Machine.SSH in that stderr is written to the test's output as a 'Log' line.
123134
// This ensures the output will be correctly accumulated under the correct

mantle/kola/harness.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -815,17 +815,9 @@ func scpKolet(machines []platform.Machine) error {
815815
} {
816816
kolet := filepath.Join(d, "kolet")
817817
if _, err := os.Stat(kolet); err == nil {
818-
if err := cluster.DropFile(machines, kolet); err != nil {
818+
if err := cluster.DropLabeledFile(machines, kolet, "bin_t"); err != nil {
819819
return errors.Wrapf(err, "dropping kolet binary")
820820
}
821-
// If in the future we want to care about machines without SELinux, let's
822-
// do basically test -d /sys/fs/selinux or run `getenforce`.
823-
for _, machine := range machines {
824-
out, stderr, err := machine.SSH("sudo chcon -t bin_t kolet")
825-
if err != nil {
826-
return errors.Wrapf(err, "running chcon on kolet: %s: %s", out, stderr)
827-
}
828-
}
829821
return nil
830822
}
831823
}

0 commit comments

Comments
 (0)