Skip to content

Commit

Permalink
run presets test suite on bpflsm only
Browse files Browse the repository at this point in the history
Signed-off-by: rksharma95 <[email protected]>
  • Loading branch information
rksharma95 committed Dec 23, 2024
1 parent d44b2ca commit f98482d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 82 deletions.
4 changes: 2 additions & 2 deletions KubeArmor/BPF/anonmapexec.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ int BPF_PROG(enforce_mmap_file, struct file *file, unsigned long reqprot,
event_data->args[2] = flags;
event_data->event_id = ANON_MAP_EXEC;
if (*present == BLOCK) {
event_data->retval = -13;
event_data->retval = -EPERM;
} else {
event_data->retval = 0;
}
bpf_ringbuf_submit(event_data, 0);
// mapping not backed by any file with executable permission, denying mapping
if (*present == BLOCK) {
return -13;
return -EPERM;
} else {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion KubeArmor/BPF/protectenv.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int BPF_PROG(enforce_file, struct file *file) {
task_info->pid_ns = okey.pid_ns;
task_info->mnt_ns = okey.mnt_ns;
bpf_ringbuf_submit(task_info, 0);
return -13;
return -EPERM;
}

return 0;
Expand Down
2 changes: 1 addition & 1 deletion KubeArmor/core/kubeArmor.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func (dm *KubeArmorDaemon) InitPresets(logger *fd.Feeder, monitor *mon.SystemMon
// ClosePresets Function
func (dm *KubeArmorDaemon) ClosePresets() bool {
if err := dm.Presets.Destroy(); err != nil {
dm.Logger.Errf("Failed to destry preset (%s)", err.Error())
dm.Logger.Errf("Failed to destroy preset (%s)", err.Error())
return false
}
return true
Expand Down
72 changes: 0 additions & 72 deletions KubeArmor/presets/base/containers.go

This file was deleted.

2 changes: 1 addition & 1 deletion KubeArmor/presets/filelessexec/preset.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func (p *Preset) TraceEvents() {
log.Type = "MatchedPolicy"
}

log.Operation = "File"
log.Operation = "Process"

if event.Retval >= 0 {
log.Result = "Passed"
Expand Down
3 changes: 3 additions & 0 deletions tests/k8s_env/presets/presets_suite_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 Authors of KubeArmor

package presets_test

import (
Expand Down
16 changes: 13 additions & 3 deletions tests/k8s_env/presets/presets_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022 Authors of KubeArmor

package presets

import (
"fmt"
"strings"
"time"

"github.com/kubearmor/KubeArmor/protobuf"
Expand Down Expand Up @@ -37,7 +41,7 @@ var _ = Describe("Presets", func() {
var fp string

BeforeEach(func() {
fp = getfilelessPod("fileless-", nil)
fp = getfilelessPod("fileless-", []string{"kubearmor-policy: enabled"})
})

AfterEach(func() {
Expand All @@ -50,12 +54,15 @@ var _ = Describe("Presets", func() {

Describe("Policy Apply", func() {
It("can audit fileless execution", func() {
if !strings.Contains(K8sRuntimeEnforcer(), "bpf") {
Skip("fileless execution preset requires bpf-lsm")
}
// Apply policy
err := K8sApplyFile("res/ksp-preset-audit-fileless.yaml")
Expect(err).To(BeNil())

// Start Kubearmor Logs
err = KarmorLogStart("policy", "presets", "File", fp)
err = KarmorLogStart("policy", "presets", "Process", fp)
Expect(err).To(BeNil())

// wait for policy creation
Expand All @@ -80,12 +87,15 @@ var _ = Describe("Presets", func() {
})

It("can block fileless execution", func() {
if !strings.Contains(K8sRuntimeEnforcer(), "bpf") {
Skip("fileless execution preset requires bpf-lsm")
}
// Apply policy
err := K8sApplyFile("res/ksp-preset-block-fileless.yaml")
Expect(err).To(BeNil())

// Start Kubearmor Logs
err = KarmorLogStart("policy", "presets", "File", fp)
err = KarmorLogStart("policy", "presets", "Process", fp)
Expect(err).To(BeNil())

// wait for policy creation
Expand Down
3 changes: 1 addition & 2 deletions tests/k8s_env/presets/res/python-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ spec:
spec:
containers:
- name: fileless
image: rksharma95/python:fileless
command: ["tail", "-f", "/dev/null"]
image: kubearmor/ubuntu-w-utils:0.2

0 comments on commit f98482d

Please sign in to comment.