Skip to content

Commit 54c2401

Browse files
committed
Blog Post to Describe Defectdojo Dev Setup on Apple Silicon
Signed-off-by: Sven Strittmatter <sven.strittmatter@iteratec.com>
1 parent c322ad5 commit 54c2401

5 files changed

Lines changed: 183 additions & 2 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ documentation/docs/hooks/*.md
6969
documentation/src/integrations.js
7070
## Copied over during the build
7171
documentation/static/findings
72+
documentation/.author_meta
7273

73-
**/node_modules/
74+
**/node_modules/
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
---
2+
# SPDX-FileCopyrightText: the secureCodeBox authors
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
title: Run x86 Images With Kubernetes on Apple Silicon
7+
author: Sven Strittmatter
8+
author_title: Core Developer
9+
author_url: https://github.com/Weltraumschaf
10+
author_image_url: https://www.gravatar.com/avatar/3fe213284598b5cb69009665902c77a1
11+
tags:
12+
- secureCodeBox
13+
- v2
14+
- kubernetes
15+
- macos
16+
description: This blog article describes how to setup Colima container runtime on macOS to run x86 images in Kubernetes on Apple Silicon.
17+
image: /img/blog/2024-10-25-a-close-up-of-a-computer-processor-chip.jpg
18+
draft: true
19+
---
20+
21+
![A close up of a computer processor chip](/img/blog/2024-10-25-a-close-up-of-a-computer-processor-chip.jpg)
22+
23+
Cover photo by [Bill Fairs](https://unsplash.com/@moonboyz) on [Unsplash](https://unsplash.com/photos/a-close-up-of-a-computer-processor-chip--QALfjTlhTE).
24+
25+
Maybe you've heard from the shiny new CPUs from Apple: [Silicon](https://en.wikipedia.org/wiki/Apple_silicon). Besides the good things (low power consumption, less fan noise) they have not so shiny drawbacks. One ran into is the problem of running containers built with/for x86 architecture. Yes, the problem itself is completely solved: Multi arch images. But, not every project builds them. No, I'm not looking at you [DefectDojo](https://www.defectdojo.org/) 😉 BTW _secureCodeBox_ provides multi arch images 🤗 So, I tinkered around with my Mac to get our _secureCodeBox_ setup with DefectDojo up and running on Silicon Macs. Since there was not much help out there in the Internet I use this post to summarize the steps to get it run, for later reference.
26+
27+
## Colima FTW
28+
29+
I use [Colima](https://github.com/abiosoft/colima) since roundabout a year now as drop in replacement for Docker Desktop. Works great. It was never necessary to read docs. It runs x86 images emulated via Qemu. But running single containers is not sufficient for _secureCodeBox_. Kubernetes is mandatory. Until now, I used Minikube, but it can't run x86 images on Silicon Macs. KIND also does not support them, as my colleagues told me. Some days ago, I told a friend about Colima, and he said: "Oh, nice. It can start a Kubernetes cluster."
30+
31+
Remember, I've never read the docs 😬 To install Colima and start a Kubernetes just execute (I assume you have [Homebrew installed](https://docs.brew.sh/Installation).):
32+
33+
```shell
34+
brew install colima
35+
colima start -f --kubernetes --arch x86_64
36+
```
37+
38+
:::caution
39+
This will _emulate_ an x86 vm under the hood. It is not _virtualized_ as usual. This brings a performance penalty.
40+
:::
41+
42+
### Should I Use Brew Services to Launch Colima at Login?
43+
44+
**TL;DR**: No, don't!
45+
46+
Brew offers very simple solution to start such services on login it. Just simply run `brew services start colima` and Colima will always start on login.
47+
48+
:::caution
49+
Never use `brew services` with `sudo`! This will break your Homebrew installation: You can't update anymore without hassle. The reason for that: Homebrew assumes that it is always executed in the context of an unprivileged user. If you run `brew services` with `sudo` files wil be written with "root" as owner. Since Homebrew always runs with your unprivileged user it can't modify such files anymore. Been there, done that. Its no good!
50+
:::
51+
52+
The "problem" with `brew services` ia, that it always uses the [LaunchAgents](https://www.launchd.info/) plist-File from the brew. For Colima this means that `brew services start colima` always copies the file from the Homebrew's Formula to `~/Library/LaunchAgents/homebrew.mxcl.colima.plist`. But since this LaunchAgents definition invokes colima without the arguments `--kubernetes` and `--arch x86_64` you need to modify it:
53+
54+
```xml
55+
...
56+
<key>ProgramArguments</key>
57+
<array>
58+
<string>/opt/homebrew/opt/colima/bin/colima</string>
59+
<string>start</string>
60+
<string>-f</string>
61+
</array>
62+
...
63+
```
64+
65+
If you modify this file and restart the daemon via `brew services` **your changes will be lost**! [And this is by design](https://github.com/Homebrew/homebrew-services/issues/71).
66+
67+
You have two options:
68+
69+
1. Either start it by hand: `colima start --kubernetes --arch x86_64` or
70+
2. handroll your own LaunchDaemon:
71+
72+
```xml
73+
<?xml version="1.0" encoding="UTF-8"?>
74+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
75+
<plist version="1.0">
76+
<dict>
77+
<key>EnvironmentVariables</key>
78+
<dict>
79+
<key>PATH</key>
80+
<string>/opt/homebrew/bin:/opt/homebrew/sbin:/usr/bin:/bin:/usr/sbin:/sbin</string>
81+
</dict>
82+
<key>KeepAlive</key>
83+
<dict>
84+
<key>SuccessfulExit</key>
85+
<true/>
86+
</dict>
87+
<key>Label</key>
88+
<string>de.weltraumschaf.colima</string>
89+
<key>LimitLoadToSessionType</key>
90+
<array>
91+
<string>Aqua</string>
92+
<string>Background</string>
93+
<string>LoginWindow</string>
94+
<string>StandardIO</string>
95+
</array>
96+
<key>ProgramArguments</key>
97+
<array>
98+
<string>/opt/homebrew/opt/colima/bin/colima</string>
99+
<string>start</string>
100+
<string>-f</string>
101+
<string>--kubernetes</string>
102+
<string>--arch</string>
103+
<string>x86_64</string>
104+
</array>
105+
<key>RunAtLoad</key>
106+
<true/>
107+
<key>StandardErrorPath</key>
108+
<string>/opt/homebrew/var/log/colima.log</string>
109+
<key>StandardOutPath</key>
110+
<string>/opt/homebrew/var/log/colima.log</string>
111+
<key>WorkingDirectory</key>
112+
<string>/Users/sst</string>
113+
</dict>
114+
</plist>
115+
```
116+
117+
And store it in the file `~/Library/LaunchAgents/de.weltraumschaf.colima.plist`. Obviously, change "de.weltraumschaf" to whatever you like. Instead of Homebrew, now you need to use `launchctl` to interact with the LaunchAgent.
118+
119+
## Install secureCodeBox with DefectDojo
120+
121+
The rest is straight forward. To install _secureCodeBox_ simply execute (as documented [here](https://www.securecodebox.io/docs/getting-started/installation)):
122+
123+
```shell
124+
helm --namespace securecodebox-system \
125+
upgrade \
126+
--install \
127+
--create-namespace securecodebox-operator \
128+
oci://ghcr.io/securecodebox/helm/operator
129+
```
130+
131+
Then install the scanners you want, e.g. [Nmap](https://nmap.org/:
132+
```shell
133+
helm install nmap oci://ghcr.io/securecodebox/helm/nmap
134+
kubectl get scantypes
135+
```
136+
137+
To install DefectDojo the easiest way is to clone their repo and install from it (as documented [here](https://www.securecodebox.io/docs/how-tos/persistence-storage/#defectdojo-kubernetes-setup)):
138+
139+
```shell
140+
git clone https://github.com/DefectDojo/django-DefectDojo
141+
cd django-DefectDojo
142+
143+
helm repo add bitnami https://charts.bitnami.com/bitnami
144+
helm repo update
145+
helm dependency update ./helm/defectdojo
146+
147+
helm upgrade --install \
148+
defectdojo \
149+
./helm/defectdojo \
150+
--set django.ingress.enabled=true \
151+
--set django.ingress.activateTLS=false \
152+
--set createSecret=true \
153+
--set createRabbitMqSecret=true \
154+
--set createRedisSecret=true \
155+
--set createMysqlSecret=true \
156+
--set createPostgresqlSecret=true \
157+
--set host="defectdojo.default.colima.local" \
158+
--set "alternativeHosts={localhost}"
159+
```
160+
161+
Get DefectDojo admin user password:
162+
163+
```shell
164+
echo "DefectDojo admin password: $(kubectl \
165+
get secret defectdojo \
166+
--namespace=default \
167+
--output jsonpath='{.data.DD_ADMIN_PASSWORD}' \
168+
| base64 --decode)"
169+
```
170+
171+
Finally forward port to service:
172+
173+
```shell
174+
kubectl port-forward svc/defectdojo-django 8080:80 -n default
175+
```
176+
177+
Now you can visit the DefectDojo web UI at `http://localhost:8080`.

documentation/docs/how-tos/persistence-storage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ we install the *secureCodeBox* and the [DefectDojo hook](https://www.securecodeb
4747

4848
:::info
4949
At the moment **DefectDojo does not provide a Docker image for arm64**. As a workaround you can run a local instance
50-
of DefectDojo (see [Troubleshooting](#troubleshooting)).
50+
of DefectDojo (see [Troubleshooting](#troubleshooting)) or [use Colima on Silicon Macs](/blog/2024/10/25/run-x86-images-with-kubernetes-on-apple-silicon).
5151
:::
5252

5353
Using *minikube* (for kind clusters see instructions below):
7.26 MB
Loading
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
SPDX-FileCopyrightText: Bill Fairs
2+
3+
SPDX-License-Identifier: LicenseRef-Unsplash-License

0 commit comments

Comments
 (0)