Skip to content

Commit

Permalink
Package KubeArmor as systemd service
Browse files Browse the repository at this point in the history
- Add packaging scripts and configs
- Add Makefile targets to generate packaged service
- Configured github workflow to generate packages on tag release

Signed-off-by: daemon1024 <[email protected]>
  • Loading branch information
daemon1024 committed Dec 17, 2021
1 parent 98e574e commit 41a9490
Show file tree
Hide file tree
Showing 8 changed files with 171 additions and 1 deletion.
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: goreleaser

on:
push:
tags:
- "*"

permissions:
contents: write

jobs:
goreleaser:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Build bcc
run: |
set -x
sudo apt-get update
sudo apt-get -y install build-essential cmake bison flex git python3 python3-pip clang-9 libllvm9 llvm-9-dev libclang-9-dev zlib1g-dev libelf-dev libedit-dev libfl-dev
pushd /tmp
git clone https://github.com/iovisor/bcc.git
mkdir -p bcc/build; cd bcc/build
sudo ln -s /usr/lib/llvm-9 /usr/local/llvm
cmake .. -DPYTHON_CMD=python3 -DCMAKE_INSTALL_PREFIX=/usr
make -j$(nproc)
sudo make install
popd
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.17
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: release --rm-dist
workdir: KubeArmor
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ kubearmor
.vscode

# vagrant
contribution/vagrant/.vagrant
.vagrant
contribution/vagrant/ubuntu-*-console.log

# Packages
*.deb
*.rpm
41 changes: 41 additions & 0 deletions KubeArmor/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
project_name: kubearmor

builds:
- binary: kubearmor
id: kubearmor
goos:
- linux
goarch:
- amd64

nfpms:
- id: "kubearmor"
builds:
- "kubearmor"
formats:
- deb
- rpm
replaces:
- kubearmor
maintainer: "Barun Acharya <[email protected]>"
description: |
Cloud-native Runtime Security Enforcement System
vendor: "kubearmor"
homepage: "https://kubearmor.com"
license: "Apache 2"
file_name_template: "{{.ProjectName}}_{{.Version}}_{{.Os}}-{{.Arch}}"
contents:
- dst: /opt/kubearmor
type: dir
- src: ./packaging/kubearmor.conf
dst: /opt/kubearmor/kubearmor.conf
type: config
- src: ./packaging/kubearmor.service
dst: /usr/lib/systemd/system/kubearmor.service
type: config
- src: ./BPF/*
dst: /opt/kubearmor/BPF/
- src: ./templates/*
dst: /opt/kubearmor/templates/
scripts:
postinstall: packaging/postinstall.sh
23 changes: 23 additions & 0 deletions KubeArmor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,29 @@ ifeq (, $(shell which gosec))
endif
cd $(CURDIR); gosec ./...

.PHONY: systemd-deb
systemd-deb: build
ifeq (, $(shell which nfpm))
@{ \
set -e ;\
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
}
endif
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) nfpm pkg --packager deb

.PHONY: systemd-rpm
systemd-rpm: build
ifeq (, $(shell which nfpm))
@{ \
set -e ;\
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest
}
endif
cd $(CURDIR); VERSION=$(shell git describe --tags --always --dirty) nfpm pkg --packager rpm

.PHONY: systemd
systemd: systemd-deb systemd-rpm

.PHONY: clean
clean:
cd $(CURDIR); sudo rm -f kubearmor /tmp/kubearmor.log
Expand Down
33 changes: 33 additions & 0 deletions KubeArmor/nfpm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: "kubearmor"
arch: "${ARCH}"
platform: "linux"
version: "${VERSION}"
section: "default"
priority: "extra"
replaces:
- kubearmor
provides:
- kubearmor
maintainer: "Barun Acharya <[email protected]>"
description: |
Cloud-native Runtime Security Enforcement System
vendor: "kubearmor"
homepage: "https://kubearmor.com"
license: "Apache 2"
contents:
- src: ./kubearmor
dst: /usr/local/bin/kubearmor
- dst: /opt/kubearmor
type: dir
- src: ./packaging/kubearmor.conf
dst: /opt/kubearmor/kubearmor.conf
type: config
- src: ./packaging/kubearmor.service
dst: /usr/lib/systemd/system/kubearmor.service
type: config
- src: ./BPF/*
dst: /opt/kubearmor/BPF/
- src: ./templates/*
dst: /opt/kubearmor/templates/
scripts:
postinstall: packaging/postinstall.sh
4 changes: 4 additions & 0 deletions KubeArmor/packaging/kubearmor.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LOG_PATH=/tmp/kubearmor.log
ENABLE_HOST_POLICY=true
ENABLE_KVM=true
GRPC=32767
13 changes: 13 additions & 0 deletions KubeArmor/packaging/kubearmor.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=KubeArmor

[Service]
User=root
KillMode=process
EnvironmentFile=/opt/kubearmor/kubearmor.conf
WorkingDirectory=/opt/kubearmor/
ExecStart=/usr/local/bin/kubearmor -logPath=${LOG_PATH} -enableKubeArmorHostPolicy=${ENABLE_HOST_POLICY} -enableKubeArmorVm=${ENABLE_KVM} -gRPC=${GRPC}

[Install]
WantedBy=multi-user.target

8 changes: 8 additions & 0 deletions KubeArmor/packaging/postinstall.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2021 Authors of KubeArmor
#!/usr/bin/env bash

set -e

/bin/systemctl daemon-reload
/bin/systemctl start kubearmor.service

0 comments on commit 41a9490

Please sign in to comment.