Skip to content

Commit

Permalink
add a test case for protocol:all handling
Browse files Browse the repository at this point in the history
Signed-off-by: rksharma95 <[email protected]>
  • Loading branch information
rksharma95 authored and daemon1024 committed Nov 25, 2024
1 parent cd488cd commit 8321894
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/k8s_env/ksp/ksp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,32 @@ var _ = Describe("Ksp", func() {

})

It("it can block all network traffic", func() {

// Apply Policy
err := K8sApplyFile("multiubuntu/ksp-ubuntu-1-block-net-all.yaml")
Expect(err).To(BeNil())

// Start KubeArmor Logs
err = KarmorLogStart("policy", "multiubuntu", "Network", ub1)
Expect(err).To(BeNil())
AssertCommand(ub1, "multiubuntu", []string{"bash", "-c", "arping -c 1 127.0.0.1"},
MatchRegexp("arping.*Permission denied"), true,
)

expect := protobuf.Alert{
PolicyName: "ksp-ubuntu-1-block-net-all",
Severity: "8",
Action: "Block",
Result: "Permission denied",
}

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

})

})

Describe("Apply Capabilities Policy", func() {
Expand Down
15 changes: 15 additions & 0 deletions tests/k8s_env/ksp/multiubuntu/ksp-ubuntu-1-block-net-all.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: security.kubearmor.com/v1
kind: KubeArmorPolicy
metadata:
name: ksp-ubuntu-1-block-net-all
namespace: multiubuntu
spec:
severity: 8
selector:
matchLabels:
container: ubuntu-1
network:
matchProtocols:
- protocol: all
action:
Block

0 comments on commit 8321894

Please sign in to comment.