Skip to content

Commit 779f30c

Browse files
authored
Add SUPERVISOR_UNCONFINED option and document AppArmor (#172)
Allow users to opt out of AppArmor enforcement for the Supervisor by setting SUPERVISOR_UNCONFINED in their containerEnv. Document AppArmor behavior, host kernel considerations, and auditd limitations in the README.
1 parent efbc292 commit 779f30c

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,36 @@ Example files for the `apps` devcontainer
3535
- Use the command `supervisor_run` to start Home Assistant inside the devcontainer, or run the task "Start Home Assistant" if you copied the tasks file.
3636
- Use `ha` to use the custom Home Assistant CLI (Needs the supervisor to be running).
3737

38+
### AppArmor
39+
40+
If the host kernel supports AppArmor, it is automatically active inside
41+
the devcontainer for the Supervisor and apps. The `hassio-supervisor`
42+
profile is downloaded and loaded on first boot. This allows apps
43+
developers to develop and test AppArmor profiles within the devcontainer
44+
environment.
45+
46+
AppArmor denials are logged to the kernel ring buffer and can be viewed
47+
with `dmesg` or `journalctl -k`. Note that `auditd` cannot run inside
48+
the container due to missing permissions on the host kernel's audit
49+
subsystem. For full audit logging, run `auditd` on the host OS directly.
50+
51+
**Host kernel considerations:** The `apparmor` package inside the
52+
container ships default policies which may prohibit D-Bus communication,
53+
potentially interfering with the Supervisor and apps. Additionally, the
54+
host kernel's AppArmor feature set can lead to different behavior of
55+
profile enforcement. For example, Ubuntu kernels may enable AppArmor
56+
features that are not present on other distributions, which can affect
57+
how profiles are applied.
58+
59+
To disable AppArmor for the Supervisor, set `SUPERVISOR_UNCONFINED` in
60+
your `containerEnv`:
61+
62+
```json
63+
"containerEnv": {
64+
"SUPERVISOR_UNCONFINED": "1"
65+
}
66+
```
67+
68+
This causes the Supervisor container to run with `apparmor=unconfined`
69+
instead of the `hassio-supervisor` profile.
70+

apps/rootfs/usr/bin/supervisor_run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,16 @@ echo "Run Supervisor"
99
function run_supervisor() {
1010
validate_devcontainer "apps"
1111

12+
local apparmor_profile="hassio-supervisor"
13+
if [ -n "${SUPERVISOR_UNCONFINED}" ]; then
14+
apparmor_profile="unconfined"
15+
fi
16+
1217
docker run --rm --privileged \
1318
--name hassio_supervisor \
1419
--privileged \
1520
--security-opt seccomp=unconfined \
16-
--security-opt apparmor=hassio-supervisor \
21+
--security-opt "apparmor=${apparmor_profile}" \
1722
-v /run/docker.sock:/run/docker.sock:rw \
1823
-v /run/dbus:/run/dbus:ro \
1924
-v /run/supervisor:/run/os:rw \

supervisor/rootfs/usr/bin/supervisor_run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,17 @@ function build_supervisor() {
4343
function run_supervisor() {
4444
validate_devcontainer "supervisor"
4545

46+
local apparmor_profile="hassio-supervisor"
47+
if [ -n "${SUPERVISOR_UNCONFINED}" ]; then
48+
apparmor_profile="unconfined"
49+
fi
50+
4651
echo "Start Supervisor"
4752
docker run --rm --privileged \
4853
--name hassio_supervisor \
4954
--privileged \
5055
--security-opt seccomp=unconfined \
51-
--security-opt apparmor=hassio-supervisor \
56+
--security-opt "apparmor=${apparmor_profile}" \
5257
-v /run/docker.sock:/run/docker.sock:rw \
5358
-v /run/dbus:/run/dbus:ro \
5459
-v /run/supervisor:/run/os:rw \

0 commit comments

Comments
 (0)