Skip to content

Commit

Permalink
move syscall test to syscalls suite
Browse files Browse the repository at this point in the history
Signed-off-by: Rudraksh Pareek <rudraksh@accuknox.com>
  • Loading branch information
DelusionalOptimist committed Jun 23, 2023
1 parent 5036c11 commit 10be32c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 51 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci-test-controllers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "main"
paths:
- "pkg/**"
- ".github/workflows/ci-test-ginkgo.yml"
- ".github/workflows/ci-test-controllers.yml"

jobs:
kubearmor-controller-test:
Expand All @@ -22,9 +22,13 @@ jobs:
go-version: "v1.20"

- uses: actions/checkout@v3
with:
go-version: "v1.20"

- name: Setup a Kubernetes environment
run: ./.github/workflows/install-k3s.sh
run: |
cd ../../
.github/workflows/install-k3s.sh
- name: Build KubeArmorController
run: make docker-build TAG=latest
Expand Down
49 changes: 0 additions & 49 deletions tests/ksp/ksp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,55 +568,6 @@ var _ = Describe("Ksp", func() {

})

It("mount will be blocked by default for a pod", func() {
// Start KubeArmor Logs
err := KarmorLogStart("policy", "multiubuntu", "Syscall", ub3)
Expect(err).To(BeNil())

// execute mount inside the pod
sout, _, err := K8sExecInPod(ub3, "multiubuntu",
[]string{"bash", "-c", "mkdir /mnt/test"})
Expect(err).To(BeNil())
sout, _, err = K8sExecInPod(ub3, "multiubuntu",
[]string{"bash", "-c", "mount /home /mnt/test"})
Expect(err).To(BeNil())
fmt.Printf("OUTPUT: %s\n", sout)

expect := protobuf.Alert{
PolicyName: "DefaultPosture",
Action: "Block",
Result: "Permission denied",
Data: "syscall=SYS_MOUNT",
}

res, err := KarmorGetTargetAlert(5*time.Second, &expect)
Expect(err).To(BeNil())
Expect(res.Found).To(BeTrue())
})

It("umount will be blocked by default for a pod as the capability not added", func() {
// Start KubeArmor Logs
err := KarmorLogStart("policy", "multiubuntu", "Syscall", ub3)
Expect(err).To(BeNil())

// execute umount inside the pod
sout, _, err := K8sExecInPod(ub3, "multiubuntu",
[]string{"bash", "-c", "umount /mnt"})
Expect(err).To(BeNil())
fmt.Printf("OUTPUT: %s\n", sout)

expect := protobuf.Alert{
PolicyName: "DefaultPosture",
Action: "Block",
Result: "Operation not permitted",
Data: "syscall=SYS_UMOUNT2",
}

res, err := KarmorGetTargetAlert(5*time.Second, &expect)
Expect(err).To(BeNil())
Expect(res.Found).To(BeTrue())
})

})

Describe("Apply Files Policies", func() {
Expand Down
51 changes: 51 additions & 0 deletions tests/syscalls/syscalls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
package syscalls

import (
"fmt"
"time"

"github.com/kubearmor/KubeArmor/protobuf"
. "github.com/kubearmor/KubeArmor/tests/util"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -477,6 +479,55 @@ var _ = Describe("Syscalls", func() {
Expect(alerts[0].Tags).To(Equal("Global tag"))
Expect(alerts[0].Message).To(Equal("Local message"))
})

It("mount will be blocked by default for a pod", func() {
// Start KubeArmor Logs
err := KarmorLogStart("policy", "syscalls", "Syscall", ubuntu)
Expect(err).To(BeNil())

// execute mount inside the pod
sout, _, err := K8sExecInPod(ubuntu, "syscalls",
[]string{"bash", "-c", "mkdir /mnt/test"})
Expect(err).To(BeNil())
sout, _, err = K8sExecInPod(ubuntu, "syscalls",
[]string{"bash", "-c", "mount /home /mnt/test"})
Expect(err).To(BeNil())
fmt.Printf("OUTPUT: %s\n", sout)

expect := protobuf.Alert{
PolicyName: "DefaultPosture",
Action: "Block",
Result: "Permission denied",
Data: "syscall=SYS_MOUNT",
}

res, err := KarmorGetTargetAlert(5*time.Second, &expect)
Expect(err).To(BeNil())
Expect(res.Found).To(BeTrue())
})

It("umount will be blocked by default for a pod as the capability not added", func() {
// Start KubeArmor Logs
err := KarmorLogStart("policy", "syscalls", "Syscall", ubuntu)
Expect(err).To(BeNil())

// execute umount inside the pod
sout, _, err := K8sExecInPod(ubuntu, "syscalls",
[]string{"bash", "-c", "umount /mnt"})
Expect(err).To(BeNil())
fmt.Printf("OUTPUT: %s\n", sout)

expect := protobuf.Alert{
PolicyName: "DefaultPosture",
Action: "Block",
Result: "Operation not permitted",
Data: "syscall=SYS_UMOUNT2",
}

res, err := KarmorGetTargetAlert(5*time.Second, &expect)
Expect(err).To(BeNil())
Expect(res.Found).To(BeTrue())
})
})

})

0 comments on commit 10be32c

Please sign in to comment.