Skip to content

Commit c8fe2d1

Browse files
authored
Merge pull request #136 from linuxserver/btsetcap
add caps to python binary for bt stack access
2 parents f23e627 + f694b47 commit c8fe2d1

7 files changed

Lines changed: 16 additions & 5 deletions

File tree

.editorconfig

100755100644
File mode changed.

.github/ISSUE_TEMPLATE/issue.bug.yml

100755100644
File mode changed.

.github/ISSUE_TEMPLATE/issue.feature.yml

100755100644
File mode changed.

.github/workflows/permissions.yml

100755100644
File mode changed.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ In order to provide HA with access to the host's Bluetooth device, one needs to
7777

7878
#### Docker Cli:
7979
```bash
80-
--cap-add=NET_ADMIN --cap-add=NET_RAW -v /var/run/dbus:/var/run/dbus:ro
80+
--cap-add=NET_ADMIN --cap-add=NET_RAW -v /run/dbus:/run/dbus:ro
8181
```
8282

8383
#### Docker Compose:
@@ -86,9 +86,11 @@ In order to provide HA with access to the host's Bluetooth device, one needs to
8686
- NET_ADMIN
8787
- NET_RAW
8888
volumes:
89-
- /var/run/dbus:/var/run/dbus:ro
89+
- /run/dbus:/run/dbus:ro
9090
```
9191
92+
If the dbus path on host differs, such as `/var/run/dbus`, then you can map it as `/var/run/dbus:/run/dbus:ro`.
93+
9294
### Using the Ping integration
9395

9496
For the [Ping][ping0] integration to work, the capability `NET_RAW` must be added to the container. See above for instructions.
@@ -316,6 +318,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
316318

317319
## Versions
318320

321+
* **19.09.25:** - Add the necessary capabilities in the container to allow the unprivileged user access to bluetooth stack.
319322
* **03.01.25:** - Rebase to alpine 3.21.
320323
* **04.12.24:** - Make setcap target dynamic.
321324
* **07.11.24:** - Add go2rtc binary.

readme-vars.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ app_setup_block: |
5151
5252
#### Docker Cli:
5353
```bash
54-
--cap-add=NET_ADMIN --cap-add=NET_RAW -v /var/run/dbus:/var/run/dbus:ro
54+
--cap-add=NET_ADMIN --cap-add=NET_RAW -v /run/dbus:/run/dbus:ro
5555
```
5656
5757
#### Docker Compose:
@@ -60,9 +60,11 @@ app_setup_block: |
6060
- NET_ADMIN
6161
- NET_RAW
6262
volumes:
63-
- /var/run/dbus:/var/run/dbus:ro
63+
- /run/dbus:/run/dbus:ro
6464
```
6565
66+
If the dbus path on host differs, such as `/var/run/dbus`, then you can map it as `/var/run/dbus:/run/dbus:ro`.
67+
6668
### Using the Ping integration
6769
6870
For the [Ping][ping0] integration to work, the capability `NET_RAW` must be added to the container. See above for instructions.
@@ -114,6 +116,7 @@ init_diagram: |
114116
"homeassistant:latest" <- Base Images
115117
# changelog
116118
changelogs:
119+
- {date: "19.09.25:", desc: "Add the necessary capabilities in the container to allow the unprivileged user access to bluetooth stack."}
117120
- {date: "03.01.25:", desc: "Rebase to alpine 3.21."}
118121
- {date: "04.12.24:", desc: "Make setcap target dynamic."}
119122
- {date: "07.11.24:", desc: "Add go2rtc binary."}

root/etc/s6-overlay/s6-rc.d/svc-homeassistant/run

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33

44
PY_LOCAL_PATH=$(find /usr/local/lib -maxdepth 1 -name python* -type d)
55
PY_LOCAL_BIN=$(basename "${PY_LOCAL_PATH}")
6-
setcap 'cap_net_bind_service=+ep' "/usr/local/bin/${PY_LOCAL_BIN}"
6+
if capsh --has-p=cap_net_admin 2>/dev/null && capsh --has-p=cap_net_raw 2>/dev/null; then
7+
echo "Adding cap_net_admin and cap_net_raw to python binary for bt access"
8+
setcap 'cap_net_bind_service,cap_net_raw,cap_net_admin=+ep' "/usr/local/bin/${PY_LOCAL_BIN}"
9+
else
10+
setcap 'cap_net_bind_service=+ep' "/usr/local/bin/${PY_LOCAL_BIN}"
11+
fi
712

813
if [[ -z "${DISABLE_JEMALLOC+x}" ]]; then
914
export LD_PRELOAD="/usr/local/lib/libjemalloc.so.2"

0 commit comments

Comments
 (0)