Skip to content

Commit 4970502

Browse files
authored
Merge 311b97f into 849861d
2 parents 849861d + 311b97f commit 4970502

21 files changed

+744
-248
lines changed

.dockerignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
**/*.dbmdl
1313
**/*.jfm
1414
**/bin
15-
**/charts
1615
**/docker-compose*
1716
**/compose*
1817
**/Dockerfile*

.github/workflows/build-app.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: "1. Create app"
22

33
on:
44
push:
5-
branches: [main,dev]
5+
branches: [main,dev,feature/*]
66
paths:
77
- "go/src/app/**.go"
88
- Dockerfile
@@ -142,4 +142,4 @@ jobs:
142142
env:
143143
CR_TOKEN: "${{ env.GITHUB_TOKEN }}"
144144
with:
145-
config: ct.yaml
145+
config: cr.yaml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@
2020
# Editor configs
2121
.idea/
2222
.vscode/
23+
.errors/

CHANGELOG.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
1. Go unit tests
11+
- [ ] Create a new profile
12+
- [ ] Update an existing profile
13+
- [ ] Remove an existing profile
14+
- [ ] Remove a non existing profile
15+
1. Remove kubernetes Service and DaemonSet exposed ports if useless
16+
1. Evaluate an automatic changelog generation from commits like [googleapis/release-please](https://github.com/googleapis/release-please)
17+
1. Add daemonset commands for checking readiness
18+
1. Add tests for all the main functions
19+
1. Add test for checking current confinement state of the app
20+
1. Test on multiple nodes cluster
21+
22+
23+
## [0.1.0]() - 2023-02-01
24+
### Fixed
25+
1. "Unable to replace profiles. Permission denied, app seems still confined." - Switched to ubuntu image
26+
1. No need for SYS_ADMIN capabilities
27+
1. Ignore hidden and system folders while scanning for profiles
28+
29+
### Added
30+
1. Instructions to test the app in a virtual machine directly running the go app or in microk8s pushing the built container to the local registry
31+
32+
33+
## 0.0.6 - 2023-01-26
34+
35+
### Added
36+
Helm:
37+
- Added SYS_ADMIN capabilities to the daemonset
38+
- Mounted needed folders in the Dockerfile and in the daemonset
39+
- Added POLL_TIME and profiles files as configurable options through configmaps
40+
41+
Go:
42+
- Added first testing function
43+
- Moved file operations functions to dedicated module
44+
- Fixed POLL_TIME value passing from configmap
45+
46+
CI/CD:
47+
- Explicit changelog to help users understanding the project features
48+
- Automatic generation of release notes based on changelog file
49+
- Configurable poll time and profiles directory in the helm values file
50+
51+
## [0.0.5](https://github.com/tuxerrante/kapparmor/releases/tag/kapparmor-0.0.5-alpha) - 2023-01-23
52+
53+
### Added
54+
55+
Helm:
56+
- Helm Chart based mainly on a DaemonSet and a configmap. No operator needed.
57+
- Load all AppArmor profiles in the configmap template
58+
59+
Go:
60+
- Possibility to load continuously the security profiles from a configmap with a configurable poll time
61+
62+
CI/CD:
63+
- Helm chart linting and testing before releasing
64+
- Security vulnerability tests on Go dependencies and container file.
65+
- Auto generation of [GitHub pages](https://tuxerrante.github.io/kapparmor/)
66+
- Container image tag is set to current commit SHA for every release.
67+
68+
### Fixed
69+
70+
- Being still an alpha release I will add everything in the "Added" section

Dockerfile

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
# --- build stage
2-
FROM golang:1.19-alpine AS builder
3-
RUN apk add --no-cache git
2+
FROM golang:1.19 AS builder
3+
44
WORKDIR /go/src/app
55
COPY . .
66
RUN go get -d -v ./go/src/app/
77
RUN go build -o /go/bin/app -v ./go/src/app/
88

99
# ---
10-
FROM alpine:latest
10+
FROM ubuntu:latest
1111
LABEL Name=kapparmor Version=0.0.1
1212
LABEL Author="Affinito Alessandro"
1313

1414
WORKDIR /app
1515

16-
RUN addgroup --system appgroup &&\
17-
adduser --system appuser -G appgroup &&\
18-
apk --no-cache update &&\
19-
apk add apparmor
20-
21-
COPY --chown=appuser:appgroup --from=builder ./go/bin/app /app/
22-
COPY --chown=appuser:appgroup ./charts/kapparmor/profiles /app/profiles
16+
RUN apt-get update &&\
17+
apt-get upgrade -y &&\
18+
apt-get install --no-install-recommends --yes apparmor apparmor-utils &&\
19+
rm -rf /var/lib/apt/lists/* &&\
20+
mkdir --parent --verbose /etc/apparmor.d/custom
2321

24-
RUN chmod 550 app
22+
COPY --from=builder /go/bin/app /app/
23+
COPY ./charts/kapparmor/profiles /app/profiles/
2524

2625
ARG PROFILES_DIR
2726
ARG POLL_TIME
2827

2928
ENV PROFILES_DIR=$PROFILES_DIR
3029
ENV POLL_TIME=$POLL_TIME
3130

32-
USER appuser
31+
USER root
3332
CMD ./app

Dockerfile.alpine

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# --- build stage
2+
FROM golang:1.19-alpine AS builder
3+
RUN apk add --no-cache git
4+
WORKDIR /go/src/app
5+
COPY . .
6+
RUN go get -d -v ./go/src/app/
7+
RUN go build -o /go/bin/app -v ./go/src/app/
8+
9+
# ---
10+
FROM alpine:latest
11+
LABEL Name=kapparmor Version=0.0.1
12+
LABEL Author="Affinito Alessandro"
13+
14+
WORKDIR /app
15+
16+
RUN apk --no-cache update &&\
17+
apk add apparmor libapparmor &&\
18+
mkdir --parent --verbose /etc/apparmor.d/custom
19+
20+
COPY --from=builder ./go/bin/app /app/
21+
COPY ./charts/kapparmor/profiles /app/profiles
22+
23+
ARG PROFILES_DIR
24+
ARG POLL_TIME
25+
26+
ENV PROFILES_DIR=$PROFILES_DIR
27+
ENV POLL_TIME=$POLL_TIME
28+
29+
USER root
30+
CMD ./app

README.md

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44

55
# Kapparmor
66
- [Kapparmor](#kapparmor)
7-
- [Prerequisites](#prerequisites)
8-
- [How to initialize this project again](#how-to-initialize-this-project-again)
7+
- [Testing](#testing)
8+
- [How to initialize this project](#how-to-initialize-this-project)
99
- [Test the app locally](#test-the-app-locally)
10-
- [TO-DO](#to-do)
1110
- [External useful links](#external-useful-links)
1211
- -----
1312
Apparmor-loader project to deploy profiles through a kubernetes daemonset.
1413

15-
This work is inspired by [kubernetes/apparmor-loader](https://github.com/kubernetes/kubernetes/tree/master/test/images/apparmor-loader).
1614

1715
![architecture](./docs/kapparmor-architecture.png)
1816

17+
This app provide dynamic loading and unloading of AppArmor profiles to a Kubernetes cluster through a configmap.
18+
The app doesn't need an operator and it will be managed by a DaemonSet filtering the linux nodes to schedule the app pod.
19+
The custom profiles deployed in the configmap will be copied in a directory (`/etc/apparmor.d/custom` by default) since apparmor_parser needs the profiles definitions also to remove them. Once you will deploy a configmap with different profiles, Kapparmor will notice the missing ones and it will remove them from the apparmor cache and from the node directory.
20+
If you modify only the content of a profile leaving the same name, Kapparmor should notice it anyway since a byte comparison is done when configmap profiles names and local profiles names match.
21+
1922
1. The CD pipeline will
2023
- deploy a configmap in the security namespace containing all the profiles versioned in the current project
2124
- it will apply a daemonset on the linux nodes
@@ -24,10 +27,14 @@ This work is inspired by [kubernetes/apparmor-loader](https://github.com/kuberne
2427
- The name of the file should be the same as the name of the profile.
2528
3. The configmap will be polled every POLL_TIME seconds to move them into PROFILES_DIR host path and then enable them.
2629

27-
## Prerequisites
30+
You can view which profiles are loaded on a node by checking the /sys/kernel/security/apparmor/profiles, so its parent will need to be mounted in the pod.
31+
32+
This work was inspired by [kubernetes/apparmor-loader](https://github.com/kubernetes/kubernetes/tree/master/test/images/apparmor-loader).
33+
34+
## Testing
2835
[Set up a Microk8s environment](./docs/microk8s.md).
2936

30-
### How to initialize this project again
37+
### How to initialize this project
3138
```sh
3239
helm create kapparmor
3340
sudo usermod -aG docker $USER
@@ -38,6 +45,8 @@ go mod init ./go/src/app/
3845
```
3946

4047
### Test the app locally
48+
49+
Test Helm Chart creation
4150
```sh
4251
# --- Check the Helm chart
4352
# https://github.com/helm/chart-testing/issues/464
@@ -49,27 +58,26 @@ docker run -it --network host --workdir=/data --volume ~/.kube/config:/root/.kub
4958
--volume $(pwd):/data quay.io/helmpack/chart-testing:latest \
5059
/bin/sh -c "git config --global --add safe.directory /data; ct lint --print-config --charts ./charts/kapparmor"
5160

52-
export GITHUB_SHA=42
61+
# Replace here a commit id being part of an image tag
62+
export GITHUB_SHA="sha-93d0dc4c597a8ae8a9febe1d68e674daf1fa919a"
5363
helm install --dry-run --atomic --generate-name --timeout 30s --debug --set image.tag=$GITHUB_SHA charts/kapparmor/
5464

65+
```
5566

67+
Test the app inside a container:
68+
```sh
5669
# --- Build and run the container image
5770
docker build --quiet -t test-kapparmor --build-arg POLL_TIME=60 --build-arg PROFILES_DIR=/app/profiles -f Dockerfile . &&\
5871
echo &&\
5972
docker run --rm -it --privileged \
6073
--mount type=bind,source='/sys/kernel/security',target='/sys/kernel/security' \
6174
--mount type=bind,source='/etc',target='/etc'\
62-
test-kapparmor
63-
75+
--name kapparmor test-kapparmor
6476

6577
```
66-
## TO-DO
67-
1. Go unit tests
68-
- [ ] Create a new profile
69-
- [ ] Update an existing profile
70-
- [ ] Remove an existing profile
71-
- [ ] Remove a non existing profile
72-
1. Remove kubernetes Service and DaemonSet exposed ports if useless
78+
79+
To test Helm chart installation in a MicroK8s cluster, follow docs/microk8s.md instructions if you don't have any local cluster.
80+
7381

7482

7583
# External useful links

charts/kapparmor/Chart.yaml

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ type: application
55
home: https://artifacthub.io
66
kubeVersion: ">= 1.23.0-0"
77

8-
version: "0.0.5-alpha"
9-
appVersion: "0.0.1-alpha"
8+
version: "0.1.0"
9+
appVersion: "0.1.0"
1010

1111
keywords:
1212
- kubernetes
@@ -17,13 +17,3 @@ keywords:
1717
maintainers:
1818
- name: tuxerrante
1919
url: https://github.com/sponsors/tuxerrante
20-
21-
annotations:
22-
artifacthub.io/containsSecurityUpdates: "false"
23-
artifacthub.io/changes: |
24-
- kind: added
25-
description: Load new profiles in the configmap
26-
- kind: added
27-
description: Unload old profiles in the filesystem
28-
- kind: added
29-
description: Update profiles with same name and different content
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: {{ include "kapparmor.fullname" . }}
4+
name: kapparmor-profiles
55
data:
66
{{ (.Files.Glob "profiles/*").AsConfig | indent 2 }}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: kapparmor-settings
5+
data:
6+
PROFILES_DIR: "{{ .Values.app.profiles_dir }}"
7+
POLL_TIME: "{{ .Values.app.poll_time }}"

0 commit comments

Comments
 (0)