Skip to content

Commit

Permalink
feat: Add helm chart for nimbus-kubearmor adapter
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
anurag-rajawat committed Jan 23, 2024
1 parent ef3d075 commit 1deae9b
Show file tree
Hide file tree
Showing 15 changed files with 234 additions and 39 deletions.
23 changes: 23 additions & 0 deletions deployments/nimbus-kubearmor/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions deployments/nimbus-kubearmor/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: nimbus-kubearmor
description: A Helm chart for KubeArmor Security Engine as an adapter for Nimbus.

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.1.0"
46 changes: 46 additions & 0 deletions deployments/nimbus-kubearmor/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Install KubeArmor adapter

> [!NOTE]
> `nimbus-kubearmor` adapter depends on [KubeArmor](https://kubearmor.io) security engine for its functionalities.
> Follow [this](https://github.com/kubearmor/KubeArmor/blob/main/getting-started/deployment_guide.md) guide to install
> KubeArmor.

Install `nimbus-kubearmor` adapter using Helm charts locally (for testing)

```bash
cd deployments/nimbus-kubearmor/
helm upgrade --install nimbus-kubearmor . -n nimbus
```

## Values

| Key | Type | Default | Description |
|------------------|--------|------------------------|----------------------------------------------------------------------------|
| image.repository | string | 5gsec/nimbus-kubearmor | Image repository from which to pull the `nimbus-kubearmor` adapter's image |
| image.pullPolicy | string | IfNotPresent | `nimbus-kubearmor` adapter image pull policy |
| image.tag | string | latest | `nimbus-kubearmor` adapter image tag |

## Verify if all the resources are up and running

Once done, the following resources will exist in your cluster:

```shell
$ kubectl get all -n nimbus -l app.kubernetes.io/instance=nimbus-kubearmor
NAME READY STATUS RESTARTS AGE
pod/nimbus-kubearmor-7f6854cf8f-gm7c8 1/1 Running 0 3m25s

NAME READY UP-TO-DATE AVAILABLE AGE
deployment.apps/nimbus-kubearmor 1/1 1 1 3m25s

NAME DESIRED CURRENT READY AGE
replicaset.apps/nimbus-kubearmor-7f6854cf8f 1 1 1 3m25s
```

## Uninstall the Operator

To uninstall, just run:

```bash
helm uninstall nimbus-kubearmor -n nimbus
```
62 changes: 62 additions & 0 deletions deployments/nimbus-kubearmor/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{{/*
Expand the name of the chart.
*/}}
{{- define "nimbus-kubearmor.name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Create a default fully qualified app name.
We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
If release name contains chart name it will be used as a full name.
*/}}
{{- define "nimbus-kubearmor.fullname" -}}
{{- if .Values.fullnameOverride }}
{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- $name := default .Chart.Name .Values.nameOverride }}
{{- if contains $name .Release.Name }}
{{- .Release.Name | trunc 63 | trimSuffix "-" }}
{{- else }}
{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}
{{- end }}
{{- end }}
{{- end }}

{{/*
Create chart name and version as used by the chart label.
*/}}
{{- define "nimbus-kubearmor.chart" -}}
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}
{{- end }}

{{/*
Common labels
*/}}
{{- define "nimbus-kubearmor.labels" -}}
helm.sh/chart: {{ include "nimbus-kubearmor.chart" . }}
{{ include "nimbus-kubearmor.selectorLabels" . }}
{{- if .Chart.AppVersion }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
{{- end }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
{{- end }}

{{/*
Selector labels
*/}}
{{- define "nimbus-kubearmor.selectorLabels" -}}
app.kubernetes.io/name: {{ include "nimbus-kubearmor.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}

{{/*
Create the name of the service account to use
*/}}
{{- define "nimbus-kubearmor.serviceAccountName" -}}
{{- if .Values.serviceAccount.create }}
{{- default (include "nimbus-kubearmor.fullname" .) .Values.serviceAccount.name }}
{{- else }}
{{- default "default" .Values.serviceAccount.name }}
{{- end }}
{{- end }}
25 changes: 25 additions & 0 deletions deployments/nimbus-kubearmor/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "nimbus-kubearmor.fullname" . }}
labels:
{{- include "nimbus-kubearmor.labels" . | nindent 4 }}
namespace: {{ .Release.Namespace }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
{{- include "nimbus-kubearmor.selectorLabels" . | nindent 6 }}
template:
metadata:
labels:
{{- include "nimbus-kubearmor.labels" . | nindent 8 }}
spec:
serviceAccountName: {{ include "nimbus-kubearmor.serviceAccountName" . }}
containers:
- name: {{ .Values.fullnameOverride }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
terminationGracePeriodSeconds: 10
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2023 Authors of Nimbus

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: nimbus-kubearmor-role
name: {{ include "nimbus-kubearmor.fullname" . }}-clusterrole
rules:
- apiGroups:
- intent.security.nimbus.com
Expand All @@ -23,7 +20,5 @@ rules:
- create
- delete
- get
- list
- patch
- update
- watch
12 changes: 12 additions & 0 deletions deployments/nimbus-kubearmor/templates/rolebinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "nimbus-kubearmor.fullname" . }}-clusterrole-binding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "nimbus-kubearmor.fullname" . }}-clusterrole
subjects:
- kind: ServiceAccount
name: {{ include "nimbus-kubearmor.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
10 changes: 10 additions & 0 deletions deployments/nimbus-kubearmor/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "nimbus-kubearmor.serviceAccountName" . }}
namespace: {{ .Release.Namespace }}
labels:
{{- include "nimbus-kubearmor.labels" . | nindent 4 }}
automountServiceAccountToken: {{ .Values.serviceAccount.automount }}
{{- end }}
25 changes: 25 additions & 0 deletions deployments/nimbus-kubearmor/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Default values for nimbus-kubearmor.

replicaCount: 1

image:
repository: 5gsec/nimbus-kubearmor
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"

nameOverride: ""
fullnameOverride: "nimbus-kubearmor"

serviceAccount:
# Specifies whether a service account should be created
create: true
# Automatically mount a ServiceAccount's API credentials?
automount: true
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: "nimbus-kubearmor"

securityContext:
runAsNonRoot: true
runAsUser: 65533
1 change: 1 addition & 0 deletions pkg/adapter/nimbus-kubearmor/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/
9 changes: 2 additions & 7 deletions pkg/adapter/nimbus-kubearmor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,12 @@ build:
run: build
@./${BINARY}

deploy-rbac:
kubectl apply -f config/service_account.yaml
kubectl apply -f config/role.yaml
kubectl apply -f config/role_binding.yaml

.PHONY: docker-build
docker-build: ## Build docker image with the manager.
docker-build:
$(CONTAINER_TOOL) build -t ${IMG}:${TAG} -t ${IMG}:latest --build-arg VERSION=${TAG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
docker-push:
$(CONTAINER_TOOL) push ${IMG}:${TAG}
$(CONTAINER_TOOL) push ${IMG}:latest

Expand Down
15 changes: 0 additions & 15 deletions pkg/adapter/nimbus-kubearmor/config/role_binding.yaml

This file was deleted.

8 changes: 0 additions & 8 deletions pkg/adapter/nimbus-kubearmor/config/service_account.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/adapter/nimbus-kubearmor/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/5GSEC/nimbus/pkg/adapter/nimbus-kubearmor
go 1.21

require (
github.com/5GSEC/nimbus v0.0.0-20240104111857-cf09d5346fc6
github.com/5GSEC/nimbus v0.0.0-20240115232953-8e1950f95b7e
github.com/go-logr/logr v1.3.0
github.com/kubearmor/KubeArmor/pkg/KubeArmorController v0.0.0-20231218054902-8b18cac961c0
k8s.io/apimachinery v0.29.0
Expand Down
4 changes: 2 additions & 2 deletions pkg/adapter/nimbus-kubearmor/go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/5GSEC/nimbus v0.0.0-20240104111857-cf09d5346fc6 h1:DtWy2kV7zQad5dq9wN5yTvyImzNma702CXjnRvmxj3o=
github.com/5GSEC/nimbus v0.0.0-20240104111857-cf09d5346fc6/go.mod h1:lob1rgxnuApFgyV2IhFEMqfFaf1J3zuX5eIUTepMwLs=
github.com/5GSEC/nimbus v0.0.0-20240115232953-8e1950f95b7e h1:0QBv4sej6QpaQrNSkD68/FY/u7nXCjgcborEETz51bo=
github.com/5GSEC/nimbus v0.0.0-20240115232953-8e1950f95b7e/go.mod h1:e7IDCzHjsO5/Q+eNSNP7vR8wLPORVo4Ded2xjr2k4pk=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
Expand Down

0 comments on commit 1deae9b

Please sign in to comment.