Skip to content

Commit

Permalink
security : check for unconfined processes
Browse files Browse the repository at this point in the history
Signed-off-by: Shahriyar Jalayeri <[email protected]>
  • Loading branch information
shjala committed Nov 9, 2023
1 parent 8ef9d2d commit 0f7de85
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions tests/sec/sec_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package sec_test

import (
"encoding/json"
"fmt"
"os"
"strings"
Expand Down Expand Up @@ -90,6 +91,53 @@ func TestMain(m *testing.M) {
os.Exit(res)
}

func TestUnconfinedProcesses(t *testing.T) {
log.Println("TestUnconfinedProcesses started")
defer log.Println("TestUnconfinedProcesses finished")

edgeNode := tc.GetEdgeNode(tc.WithTest(t))
tc.WaitForState(edgeNode, 60)

// check if there are any processes with capablities

Check failure on line 101 in tests/sec/sec_test.go

View workflow job for this annotation

GitHub Actions / yetus

codespell: capablities ==> capabilities
command := `ps -eZ | awk '
BEGIN { print " [ "}
/LABEL/ {next}
{
printf " %s {\"label\": \"%s\", \"cmd\": \"%s\"}", separator, $1, $5;
separator = ",";
}
END { print " ] " }
'`

out, err := rnode.runCommand(command)
if err != nil {
t.Fatal(err)
}

processes := []struct {
Label string `json:"label"`
Cmd string `json:"cmd"`
}{}

err = json.Unmarshal(out, &processes)
if err != nil {
t.Fatal(err)
}

fail := false
for _, process := range processes {
if process.Label == "unconfined" {
t.Logf("Unconfined process found: %s", process.Cmd)
fail = true
}
}

if fail {
// TODO : this not a proper way to check, but good for now

Check failure on line 136 in tests/sec/sec_test.go

View workflow job for this annotation

GitHub Actions / yetus

golangcilint: tests/sec/sec_test.go:136: Line contains TODO/BUG/FIXME: "TODO : this not a proper way to check, b..." (godox)
t.Fatal("There are unconfined processes running on the system")
}
}

func TestUmask(t *testing.T) {

Check failure on line 141 in tests/sec/sec_test.go

View workflow job for this annotation

GitHub Actions / yetus

golangcilint: Function TestUmask missing the call to method parallel (paralleltest)
log.Println("TestUmask started")
defer log.Println("TestUmask finished")
Expand Down

0 comments on commit 0f7de85

Please sign in to comment.