Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubearmor addon #147

Merged
merged 14 commits into from
Jul 21, 2023
9 changes: 9 additions & 0 deletions addons.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,12 @@ microk8s-addons:
supported_architectures:
- amd64
- arm64

- name: "kubearmor"
description: "Cloud-native runtime security enforcement system for k8s"
version: "0.10.2"
check_status: "daemonset.apps/kubearmor"
gopiak marked this conversation as resolved.
Show resolved Hide resolved
confinement: "classic"
supported_architectures:
- amd64
- arm64
14 changes: 14 additions & 0 deletions addons/kubearmor/disable
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

echo "Removing kubearmor from k8s cluster"

sudo microk8s karmor uninstall

if [[ -f "$SNAP_COMMON/plugins/karmor" ]]; then
sudo rm "$SNAP_COMMON/plugins/karmor"
fi

if [[ -f "$SNAP_COMMON/bin/karmor" ]]; then
sudo rm "$SNAP_COMMON/bin/karmor"
fi

13 changes: 13 additions & 0 deletions addons/kubearmor/enable
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

CURRENT_DIR=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)

curl -sfL http://get.kubearmor.io/ | sudo sh -s -- -b "$SNAP_COMMON/bin"
gopiak marked this conversation as resolved.
Show resolved Hide resolved

cp "$CURRENT_DIR/karmor" "$SNAP_COMMON/plugins"

chmod +x "$SNAP_COMMON/plugins/karmor"

sudo microk8s karmor install
10 changes: 10 additions & 0 deletions addons/kubearmor/karmor
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

if [ "$EUID" -ne 0 ]
then echo "Elevated permissions are needed for this command. Please use sudo."
exit 1
fi

export KUBECONFIG=$SNAP_DATA/credentials/client.config

${SNAP_COMMON}/bin/karmor $*
48 changes: 48 additions & 0 deletions tests/test_kubearmor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest
import platform
import os


from utils import (
is_container,
microk8s_enable,
microk8s_disable,
microk8s_reset,
wait_for_installation,
wait_for_pod_state,
)


class TestKubearmor(object):
@pytest.mark.skipif(os.environ.get("STRICT") == "yes", reason=("Skipping kubearmor tests in strict confinement as they are expected to fail"))
@pytest.mark.skipif(is_container(), reason="Kubearmor tests are skipped in containers")
@pytest.mark.skipif(platform.machine() == "s390x", reason="Not available on s390x")
def test_kubearmor(self):
"""
Sets up and validates kubearmor.
"""
print("Enabling Kubearmor")
microk8s_enable("kubearmor")
print("Validating Kubearmor")
self.validate_kubearmor()
print("Disabling Kubearmor")
microk8s_disable("kubearmor")
microk8s_reset()

def validate_kubearmor(self):
"""
Validate kubearmor by applying policy to nginx container.
"""

wait_for_installation()
kubearmor_pods = [
"kubearmor-controller",
"kubearmor",
"kubearmor-relay",
]
for pod in kubearmor_pods:
wait_for_pod_state(
"", "kube-system", "running", label="kubearmor-app={}".format(pod)
)

print("Kubearmor testing passed.")