Bluetooth and Docker (part 2)

For some, but probably not all, the actual issue can be seen in the logs searching for “dbus”. If you see “EXTERNAL, REJECTED” there it’s an issue with the python library dbus-fast and running H-A in a rootless Docker container (or podman).

It’s probably this error, which has unfortunately been closed as a configuration issue (it isn’t): Bluetooth in container (podman) gives dbus-related error: authentication failed: REJECTED: ['EXTERNAL']) · Issue #76429 · home-assistant/core · GitHub

I spent way too much time looking into this today, since not being able to set up bluetooth stopped me from being able to use ESPHome. It turns out that dbus-fast isn’t authenticating the way it should, and patching the code makes it work.

My dirty patch follows.

Enter your container using docker exec, then:

# vi /usr/local/lib/python3.11/site-packages/dbus_fast/auth.py

Add a line to this function:

   def _authentication_start(self, negotiate_unix_fd: bool = False) -> str:                                                
        self.negotiate_unix_fd = negotiate_unix_fd                                                                          
        self.uid = UID_NOT_SPECIFIED                                                                                        
        uid = self.uid 

Save, restart your container. The information behind this patch comes from a discussion on libdbus: libdbus client should try "AUTH EXTERNAL\r\n" first? (#195) · Issues · dbus / dbus · GitLab

I now have host bluetooth working fine inside my rootless docker H-A container without resorting to using --privileged or other security problems.

1 Like