minimal permissions for BLE operations?
I wonder what kernel capabilities or permissions are needed to use HCI for
1. passive BLE scan on channels 37, 38, 39,
2. (read) access to a BLE GAP (for Thread/Matter device commissioning)
3. hciconfig hci0 up/down
I'm asking because I just hardened a Docker image by restricting to an unprivileged user, but the above BLE operations fail. I was expecting to add something like NET_ADMIN + NET_RAW kernel caps, but it didn't change anything. I also tried adding the unprivileged user to the bluetooth group.
Does "hciconfig hci0 up" always need the root user, or is there a minimal permission I could grant instead? Currently, I get "Can't init device hci0: Operation not permitted (1)" if I try from an unprivileged user.
Maybe related: is it normal that if you use HCI from within a Docker container you mount the DBus (/run/dbus) into the container? Is it perhaps possible to just pass the hci0 device via --device instead? I didn't manage to do that either.
I'm on kernel 6.12.69, Docker version 26.1.5, bluez 5.82 (both on host and in container)
Cheers,
Andreas
Luiz Augusto von Dentz
maintainerHi Andreas,
Quoted 6 lines · Andreas Schildbach
I wonder what kernel capabilities or permissions are needed to use HCI for
1. passive BLE scan on channels 37, 38, 39,
2. (read) access to a BLE GAP (for Thread/Matter device commissioning)
3. hciconfig hci0 up/down
If really want to do low level access to HCI then you probably need to use HCI_CHANNEL_USER and take full ownership of HCI state machine:
https://github.com/bluez/bluez/blob/master/doc/hci-protocol.rst
If you don't want to take ownership of HCI, the next best step is to learn how to use BlueZ's D-Bus. Don't cut corners, because I believe all 3 can be achieved with D-Bus or in the worst case, you will need a socket for GAP (is that an L2CAP channel that is used as transport for Thread/Matter?).
Quoted 23 lines
I'm asking because I just hardened a Docker image by restricting to an unprivileged user, but the above BLE operations fail. I was expecting to add something like
NET_ADMIN+NET_RAWkernel caps, but it didn't change anything. I also tried adding the unprivileged user to the bluetooth group.Does "hciconfig hci0 up" always need the root user, or is there a minimal permission I could grant instead? Currently, I get "Can't init device hci0: Operation not permitted (1)" if I try from an unprivileged user.
Maybe related: is it normal that if you use HCI from within a Docker container you mount the DBus (
/run/dbus) into the container? Is it perhaps possible to just pass the hci0 device via--deviceinstead? I didn't manage to do that either.I'm on kernel 6.12.69, Docker version 26.1.5, bluez 5.82 (both on host and in container)
Cheers,
Andreas
Signature · 1 line
Luiz Augusto von Dentz
Hi Luiz,
Quoted 11 lines
Quoted 6 lines · Andreas Schildbach
I wonder what kernel capabilities or permissions are needed to use HCI for
1. passive BLE scan on channels 37, 38, 39,
2. (read) access to a BLE GAP (for Thread/Matter device commissioning)
3. hciconfig hci0 up/downIf really want to do low level access to HCI then you probably need to use
HCI_CHANNEL_USERand take full ownership of HCI state machine…
Sorry, for I should have made this clearer: the software is already written (by others) and works, given root privileges. Now I want to allow it to run under an unprivileged user and grant just the right/minimal set of permissions/capabilities.
Let's take the probably easiest example from above (because it's part of Bluez): hciconfig hci0 up/down
What kernel capability does hciconfig need in oder to open and close HCI devices (and not print "Operation not permitted" when trying)? It's not mentioned in its man page.
Quoted 1 line
If you don't want to take ownership of HCI, …
Yes, I assume the software already takes ownership of the HCI.
Quoted 1 line
in the worst case, you will need a socket for GAP (is that an L2CAP channel that is used as transport for> Thread/Matter?).
It's just one small data packet that gets "broadcasted" via a GAP by the commissionee (the device being commissioned) and needs to be received by the commissioner (the "device" I'm trying to harden). After that, "device discovery" is finished and BLE isn't used again by the Matter protocol.
So I assume (but don't know for sure) no BLE channel is needed, I would expect more like a characteristic/beacon.