Skip to content

Commit 8321894

Browse files
rksharma95daemon1024
authored andcommitted
add a test case for protocol:all handling
Signed-off-by: rksharma95 <[email protected]>
1 parent cd488cd commit 8321894

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

tests/k8s_env/ksp/ksp_test.go

+26
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,32 @@ var _ = Describe("Ksp", func() {
266266

267267
})
268268

269+
It("it can block all network traffic", func() {
270+
271+
// Apply Policy
272+
err := K8sApplyFile("multiubuntu/ksp-ubuntu-1-block-net-all.yaml")
273+
Expect(err).To(BeNil())
274+
275+
// Start KubeArmor Logs
276+
err = KarmorLogStart("policy", "multiubuntu", "Network", ub1)
277+
Expect(err).To(BeNil())
278+
AssertCommand(ub1, "multiubuntu", []string{"bash", "-c", "arping -c 1 127.0.0.1"},
279+
MatchRegexp("arping.*Permission denied"), true,
280+
)
281+
282+
expect := protobuf.Alert{
283+
PolicyName: "ksp-ubuntu-1-block-net-all",
284+
Severity: "8",
285+
Action: "Block",
286+
Result: "Permission denied",
287+
}
288+
289+
res, err := KarmorGetTargetAlert(5*time.Second, &expect)
290+
Expect(err).To(BeNil())
291+
Expect(res.Found).To(BeTrue())
292+
293+
})
294+
269295
})
270296

271297
Describe("Apply Capabilities Policy", func() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: security.kubearmor.com/v1
2+
kind: KubeArmorPolicy
3+
metadata:
4+
name: ksp-ubuntu-1-block-net-all
5+
namespace: multiubuntu
6+
spec:
7+
severity: 8
8+
selector:
9+
matchLabels:
10+
container: ubuntu-1
11+
network:
12+
matchProtocols:
13+
- protocol: all
14+
action:
15+
Block

0 commit comments

Comments
 (0)