Skip to content

Commit

Permalink
fix : Kuberamor compatibility with Bottlerocket vm 1.16 (#1512)
Browse files Browse the repository at this point in the history
* fix : containerd mount points for bottlerocket vm

Signed-off-by: Aryan-sharma11 <[email protected]>

* revert commit a6e16a1 to fix bottle rocket vm

Signed-off-by: Aryan-sharma11 <[email protected]>

* fix : kubearmor clean up process

Signed-off-by: Aryan-sharma11 <[email protected]>

* changed events map name to kubearmor_events

Signed-off-by: Aryan-sharma11 <[email protected]>

---------

Signed-off-by: Aryan-sharma11 <[email protected]>
  • Loading branch information
Aryan-sharma11 authored Nov 28, 2023
1 parent 718f829 commit 7c21066
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 39 deletions.
4 changes: 2 additions & 2 deletions KubeArmor/BPF/enforcer.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ int BPF_PROG(enforce_proc, struct linux_binprm *bprm, int ret) {
}

decision:
task_info = bpf_ringbuf_reserve(&events, sizeof(event), 0);
task_info = bpf_ringbuf_reserve(&kubearmor_events, sizeof(event), 0);
if (!task_info) {
return 0;
}
Expand Down Expand Up @@ -360,7 +360,7 @@ static inline int match_net_rules(int type, int protocol, u32 eventID) {

decision:

task_info = bpf_ringbuf_reserve(&events, sizeof(event), 0);
task_info = bpf_ringbuf_reserve(&kubearmor_events, sizeof(event), 0);
if (!task_info) {
return 0;
}
Expand Down
4 changes: 2 additions & 2 deletions KubeArmor/BPF/probe.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ typedef struct {
struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
} events SEC(".maps");
} kubearmor_events SEC(".maps");

// Force emitting struct event into the ELF.
const event *unused __attribute__((unused));
Expand All @@ -23,7 +23,7 @@ SEC("lsm/mmap_file")
int test_memfd() {
event *task_info;

task_info = bpf_ringbuf_reserve(&events, sizeof(event), 0);
task_info = bpf_ringbuf_reserve(&kubearmor_events, sizeof(event), 0);
if (!task_info) {
return 0;
}
Expand Down
14 changes: 7 additions & 7 deletions KubeArmor/BPF/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct {
__uint(type, BPF_MAP_TYPE_RINGBUF);
__uint(max_entries, 1 << 24);
__uint(pinning, LIBBPF_PIN_BY_NAME);
} events SEC(".maps");
} kubearmor_events SEC(".maps");

#define RULE_EXEC 1 << 0
#define RULE_WRITE 1 << 1
Expand Down Expand Up @@ -194,7 +194,7 @@ static __always_inline bool prepend_path(struct path *path, bufs_t *string_p) {
int sz = bpf_probe_read_str(
&(string_p->buf[(offset) & (MAX_COMBINED_LENGTH - 1)]),
(d_name.len + 1) & (MAX_COMBINED_LENGTH - 1), d_name.name);
if (sz > 1) {
if (sz > 1) {
bpf_probe_read(
&(string_p->buf[(offset + d_name.len) & (MAX_COMBINED_LENGTH - 1)]), 1,
&slash);
Expand Down Expand Up @@ -400,7 +400,7 @@ static inline int match_and_enforce_path_hooks(struct path *f_path, u32 id , u32
}

#pragma unroll
for (int i = 0; i < MAX_STRING_SIZE; i++) {
for (int i = 0; i < 64; i++) {
if (store->path[i] == '\0')
break;

Expand Down Expand Up @@ -463,7 +463,7 @@ static inline int match_and_enforce_path_hooks(struct path *f_path, u32 id , u32
recursivebuthint = false;

#pragma unroll
for (int i = 0; i < MAX_STRING_SIZE; i++) {
for (int i = 0; i < 64; i++) {
if (store->path[i] == '\0')
break;

Expand Down Expand Up @@ -502,7 +502,7 @@ static inline int match_and_enforce_path_hooks(struct path *f_path, u32 id , u32

decision:

task_info = bpf_ringbuf_reserve(&events, sizeof(event), 0);
task_info = bpf_ringbuf_reserve(&kubearmor_events, sizeof(event), 0);
if (!task_info) {
return 0;
}
Expand Down Expand Up @@ -538,7 +538,7 @@ static inline int match_and_enforce_path_hooks(struct path *f_path, u32 id , u32
pk->path[0] = dfile;
struct data_t *allow = bpf_map_lookup_elem(inner, pk);

if (allow) {
if (allow) {
if (!match) {
if(allow->processmask == BLOCK_POSTURE) {
bpf_ringbuf_submit(task_info, BPF_RB_FORCE_WAKEUP);
Expand All @@ -550,7 +550,7 @@ static inline int match_and_enforce_path_hooks(struct path *f_path, u32 id , u32
}
}
}

} else if (id == dfileread) { // file open
if (match) {
if (val && (val->filemask & RULE_OWNER)) {
Expand Down
10 changes: 9 additions & 1 deletion KubeArmor/enforcer/bpflsm/enforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func NewBPFEnforcer(node tp.Node, pinpath string, logger *fd.Feeder, monitor *mo
}
}

be.Events, err = ringbuf.NewReader(be.obj.Events)
be.Events, err = ringbuf.NewReader(be.obj.KubearmorEvents)
if err != nil {
be.Logger.Errf("opening ringbuf reader: %s", err)
return be, err
Expand Down Expand Up @@ -412,6 +412,14 @@ func (be *BPFEnforcer) DestroyBPFEnforcer() error {
errBPFCleanUp = true
}
}
if err := be.obj.KubearmorEvents.Unpin(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = true
}
if err := be.obj.KubearmorEvents.Close(); err != nil {
be.Logger.Err(err.Error())
errBPFCleanUp = true
}

if err := be.Events.Close(); err != nil {
be.Logger.Err(err.Error())
Expand Down
6 changes: 3 additions & 3 deletions KubeArmor/enforcer/bpflsm/enforcer_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/enforcer/bpflsm/enforcer_bpfeb.o
Binary file not shown.
6 changes: 3 additions & 3 deletions KubeArmor/enforcer/bpflsm/enforcer_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/enforcer/bpflsm/enforcer_bpfel.o
Binary file not shown.
6 changes: 3 additions & 3 deletions KubeArmor/enforcer/bpflsm/enforcer_path_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/enforcer/bpflsm/enforcer_path_bpfeb.o
Binary file not shown.
6 changes: 3 additions & 3 deletions KubeArmor/enforcer/bpflsm/enforcer_path_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/enforcer/bpflsm/enforcer_path_bpfel.o
Binary file not shown.
18 changes: 18 additions & 0 deletions KubeArmor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ func main() {
return
}
}
// initial clean up

bpfMapsDir := "/sys/fs/bpf/"
bpfMapsName := []string{"kubearmor_config", "kubearmor_events", "kubearmor_contianers", "kubearmor_visibility"}
for _, mp := range bpfMapsName {
path := bpfMapsDir + mp
/* This should not be triggered in ideal cases,
if this is triggered that means there is incomplete cleanup process
from the last installation */
if _, err := os.Stat(path); !os.IsNotExist(err) {
err = os.Remove(path)
if err != nil {
kg.Err(err.Error())
}
kg.Warnf("Deleteing existing map %s. This means previous cleanup was failed", path)

}
}

dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion KubeArmor/utils/bpflsmprobe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func CheckBPFLSMSupport() error {
if err := loadProbeObjects(&objs, nil); err != nil {
return err
}
defer objs.KubearmorEvents.Close()
defer objs.KubearmorEvents.Unpin()
defer objs.Close()

kp, err := link.AttachLSM(link.LSMOptions{Program: objs.TestMemfd})
Expand All @@ -40,7 +42,7 @@ func CheckBPFLSMSupport() error {
}
defer kp.Close()

rd, err := ringbuf.NewReader(objs.Events)
rd, err := ringbuf.NewReader(objs.KubearmorEvents)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions KubeArmor/utils/bpflsmprobe/probe_bpfeb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/utils/bpflsmprobe/probe_bpfeb.o
Binary file not shown.
6 changes: 3 additions & 3 deletions KubeArmor/utils/bpflsmprobe/probe_bpfel.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified KubeArmor/utils/bpflsmprobe/probe_bpfel.o
Binary file not shown.
8 changes: 3 additions & 5 deletions deployments/get/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,15 +332,13 @@ var defaultConfigs = map[string]DaemonSetConfig{
},
},
"bottlerocket": {
Args: []string{
"-criSocket=unix:///run/dockershim.sock",
},
Args: []string{},
Envs: envVar,
VolumeMounts: []corev1.VolumeMount{
apparmorVolMnt,
{
Name: "containerd-sock-path", // containerd
MountPath: "/run/dockershim.sock",
MountPath: "/var/run/containerd/containerd.sock",
ReadOnly: true,
},
},
Expand All @@ -350,7 +348,7 @@ var defaultConfigs = map[string]DaemonSetConfig{
Name: "containerd-sock-path",
VolumeSource: corev1.VolumeSource{
HostPath: &corev1.HostPathVolumeSource{
Path: "/run/dockershim.sock",
Path: "/run/containerd/containerd.sock",
Type: &hostPathSocket,
},
},
Expand Down
2 changes: 1 addition & 1 deletion deployments/get/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func GenerateDaemonSet(env, namespace string) *appsv1.DaemonSet {
"kubearmor-app": kubearmor,
}
var privileged = bool(false)
var terminationGracePeriodSeconds = int64(30)
var terminationGracePeriodSeconds = int64(60)
var args = []string{
"-gRPC=" + strconv.Itoa(int(port)),
}
Expand Down
4 changes: 2 additions & 2 deletions deployments/helm/KubeArmor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ kubearmor:
readOnly: true
- mountPath: /etc/apparmor.d
name: etc-apparmor-d-path
- mountPath: /run/dockershim.sock
- mountPath: /var/run/containerd/container.sock
name: containerd-sock-path
readOnly: true

Expand Down Expand Up @@ -636,7 +636,7 @@ kubearmor:
type: DirectoryOrCreate
name: etc-apparmor-d-path
- hostPath:
path: /run/dockershim.sock
path: /var/run/containerd/container.sock
type: Socket
name: containerd-sock-path

Expand Down

0 comments on commit 7c21066

Please sign in to comment.