Skip to content

Commit 15da4e4

Browse files
committed
Feature: validate profile file content
1 parent 689fa39 commit 15da4e4

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ helm upgrade kapparmor --install --atomic --timeout 120s --debug --set image.tag
4646
```
4747

4848
## Known limitations
49-
- Profiles names are checked on the first line, so if there is some include before that would fail
50-
- Profile names have to start with 'custom.' and to be equal as the filename containing it
51-
- There could be issues if you start the daemonsets on "dirty" nodes, where some old custom profiles were left after stopping or uninstalling Kapparmor. E.g: you stop the pods and then redeploy the app with an empty profiles configmap without removing the previous custom profiles: Kapparmor will try to remove the old profiles but it could fail since there is no definition of them anymore.
49+
- Constraint: Profiles are validated on the "`profile`" keyword presence before of a opening curly bracket `{`.
50+
It must be a [unattached profiles](https://documentation.suse.com/sles/15-SP1/html/SLES-all/cha-apparmor-profiles.html#sec-apparmor-profiles-types-unattached).
51+
- Profile names have to start with 'custom.' and to be equal as the filename containing it.
52+
- There could be issues if you start the daemonsets on "dirty" nodes, where some old custom profiles were left after stopping or uninstalling Kapparmor.
53+
E.G: By default if you delete a pod all the profiles should be automatically deleted from that node, but the app crashes during the process.
54+
5255
- Not a limitation relative to this project, but if you deny write access in the /bin folder of a privileged container it could not be deleted by Kubernetes even after 'kubectl delete'. The command will succeed but the pod will stay in Terminating state.
5356

5457
## ToDo:
55-
- 🌱 Intercept Term signal and uninstall profiles before the Helm chart deletion completes.
58+
- [X] Intercept Term signal and uninstall profiles before the Helm chart deletion completes.
5659
- ⚠️ Implement the [controller-runtime](https://pkg.go.dev/sigs.k8s.io/controller-runtime#section-readme) design pattern through [Kubebuilder](https://book.kubebuilder.io/quick-start.html).
5760
- 😁 Find funnier quotes for app starting and ending message (David Zucker, Monty Python, Woody Allen...).
5861
- 🌱 Make the ticker loop thread safe: skip running a new loop if previous run is still ongoing.

charts/kapparmor/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ kubeVersion: ">= 1.23.0-0"
77

88
# Respect spaces and double quotes since this will be validated by the build-app script.
99
version: "0.1.3"
10-
appVersion: "0.1.4"
10+
appVersion: "0.1.5"
1111

1212
keywords:
1313
- kubernetes

config/config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
APP_VERSION=0.1.4
1+
APP_VERSION=0.1.5
22
CHART_VERSION=0.1.3

go/src/app/filesystemOperations.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ func IsProfileNameCorrect(directory, filename string) error {
168168
}
169169
scanner := bufio.NewScanner(fileReader)
170170

171+
// Validate the syntax
172+
// the first index of a curly bracket should be greater than the first occurrence of "profile"
173+
fileBytes, err := os.ReadFile(path.Join(directory, filename))
174+
checkFatal(err)
175+
profileIndex := bytes.Index(fileBytes, []byte("profile"))
176+
curlyBracketIndex := bytes.Index(fileBytes, []byte("{"))
177+
if curlyBracketIndex < 0 || curlyBracketIndex < profileIndex {
178+
return errors.New("couldn't find a { after 'profile' keyword")
179+
}
180+
171181
// Search for line starting with 'profile' word
172182
for scanner.Scan() {
173183
fileLine := scanner.Text()

0 commit comments

Comments
 (0)