home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.03k stars 28.28k forks source link

Bluetooth dependency check breaks Shelly usage #116776

Closed nemihome closed 2 weeks ago

nemihome commented 2 weeks ago

The problem

Im Using Home Assistant Core. I installed Shelly integration successfully with several Shelly devices. After reboot I got bluetooth integration not available errors in log although I have deactivated bluetooth for all Shelly devices in the Shelly integration. This could be related to a kernel update. I'm not sure. I think I have rebooted before without problems.

Currently I'm using a system user home assistant for running the service with a group homeassistant. Due to the fact that I thought maybe this is an authorization problem I assigend all existing groups to homeassistant for test purposes. The error is still coming up after that.

If I start homeassistant service with root user as service user bluetooth is working (and also the Shelly devices) but this is a major security risk. Currently the only thing which is obvious for me that root has some rights which the homeassistant user is lacking.

But if all groups are assigned and the user is a system user (id < 1000) what can be missing?

Second question: Why are the dependencies checked even if bluetooth is totally deactivated in Shelly itegrationI don't need bluetooth integration and if this check could be deactivated I would have no problem.

The check makes no sense for me if bluetooth is not even activated. Before it did work even after several service restarts of home assistant but if this is related to a kernel update it makes sense that this is connected to a reboot.

I'm using Ubuntu 22.04 LTS Kernel 6.5.0-28

What version of Home Assistant Core has the issue?

core-2023.7.3

What was the last working version of Home Assistant Core?

core-2023.7.3

What type of installation are you running?

Home Assistant Core

Integration causing the issue

Shelly

Link to integration documentation on our website

No response

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

2024-05-03 22:47:11.427 ERROR (MainThread) [homeassistant.setup] Error during setup of component bluetooth
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.10/site-packages/homeassistant/setup.py", line 288, in _async_setup_component
    result = await task
  File "/opt/homeassistant/lib/python3.10/site-packages/homeassistant/components/bluetooth/__init__.py", line 138, in async_setup
    await manager.async_setup()
  File "/opt/homeassistant/lib/python3.10/site-packages/homeassistant/components/bluetooth/manager.py", line 214, in async_setup
    await self._bluetooth_adapters.refresh()
  File "/opt/homeassistant/lib/python3.10/site-packages/bluetooth_adapters/systems/linux.py", line 33, in refresh
    await self._bluez.load()
  File "/opt/homeassistant/lib/python3.10/site-packages/bluetooth_adapters/dbus.py", line 30, in load
    self._packed_managed_objects = await _get_dbus_managed_objects()
  File "/opt/homeassistant/lib/python3.10/site-packages/bluetooth_adapters/dbus.py", line 94, in _get_dbus_managed_objects
    bus = await MessageBus(bus_type=BusType.SYSTEM).connect()
  File "/opt/homeassistant/lib/python3.10/site-packages/dbus_fast/aio/message_bus.py", line 197, in connect
    await self._authenticate()
  File "/opt/homeassistant/lib/python3.10/site-packages/dbus_fast/aio/message_bus.py", line 458, in _authenticate
    response = self._auth._receive_line(await self._auth_readline())
  File "/opt/homeassistant/lib/python3.10/site-packages/dbus_fast/auth.py", line 99, in _receive_line
    raise AuthError(f"authentication failed: {response.value}: {args}")
dbus_fast.errors.AuthError: authentication failed: REJECTED: ['EXTERNAL']
2024-05-03 22:47:11.661 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of shelly. Setup failed for dependencies: bluetooth
2024-05-03 22:47:11.663 ERROR (MainThread) [homeassistant.setup] Setup failed for shelly: (DependencyError(...), 'Could not setup dependencies: bluetooth')
2024-05-03 22:47:13.027 ERROR (MainThread) [homeassistant.setup] Unable to set up dependencies of default_config. Setup failed for dependencies: bluetooth
2024-05-03 22:47:13.027 ERROR (MainThread) [homeassistant.setup] Setup failed for default_config: (DependencyError(...), 'Could not setup dependencies: bluetooth')

Additional information

No response

home-assistant[bot] commented 2 weeks ago

Hey there @bdraco, mind taking a look at this issue as it has been labeled with an integration (bluetooth) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `bluetooth` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign bluetooth` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


bluetooth documentation bluetooth source (message by IssueLinks)

nemihome commented 2 weeks ago

Found a workaround. Not sure how this is connected to the reboot because this is nothing which have changed but anyway it would be nice if bluetooth dependency is not checked if deactivated. It is not really needed for the Shellys which are connected via network.

/etc/dbus-1/system.d/Bluetooth.conf

<policy user="homeassistant">
  <allow own="org.bluez"/>
  <allow send_destination="org.bluez"/>
  <allow send_interface="org.bluez.GattCharacteristic1"/>
  <allow send_interface="org.bluez.GattDescriptor1"/>
  <allow send_interface="org.freedesktop.DBus.ObjectManager"/>
  <allow send_interface="org.freedesktop.DBus.Properties"/>
</policy>  

There was also a policy for the group which is used already because of group assignment to the user but with less allow lines. Seems to be the allows for the group are not enough.

  <!-- allow users of bluetooth group to communicate -->
  <policy group="bluetooth">
    <allow send_destination="org.bluez"/>
  </policy>
bdraco commented 2 weeks ago

Found a workaround. Not sure how this is connected to the reboot because this is nothing which have changed but anyway it would be nice if bluetooth dependency is not checked if deactivated. It is not really needed for the Shellys which are connected via network.

Its currently needed for Bluetooth in Shelly devices support https://www.home-assistant.io/integrations/shelly/#bluetooth-support , and since Home Assistant doesn't have a way to list a dep as conditional based on a config entry setting, its not possible at this time. It is not likely a feature we would add since it would significantly increase development complexity and dependency resolution, increasing risk.

home-assistant[bot] commented 2 weeks ago

Hey there @balloob, @bieniu, @thecode, @chemelli74, mind taking a look at this issue as it has been labeled with an integration (shelly) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `shelly` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign shelly` Removes the current integration label and assignees on the issue, add the integration domain after the command. - `@home-assistant add-label needs-more-information` Add a label (needs-more-information, problem in dependency, problem in custom component) to the issue. - `@home-assistant remove-label needs-more-information` Remove a label (needs-more-information, problem in dependency, problem in custom component) on the issue.

(message by CodeOwnersMention)


shelly documentation shelly source (message by IssueLinks)