core: Bluetooth in container give access denied error

The problem

After upgrading to the new home assistant 2022.8.1 i get an error for setting up the bluetooth

Opnieuw proberen in te stellen: Failed to start Bluetooth: [org.freedesktop.DBus.Error.AccessDenied] An AppArmor policy prevents this sender from sending this message

Tried both options mentioned in the documentation to -v the DBus

What version of Home Assistant Core has the issue?

2022.8.1

What was the last working version of Home Assistant Core?

core-2022.7.7

What type of installation are you running?

Home Assistant Container

Integration causing the issue

Bluetooth

Link to integration documentation on our website

https://www.home-assistant.io/integrations/bluetooth

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Error handling request
-----------------------
Logger: aiohttp.server
Source: components/bluetooth/util.py:19
First occurred: 17:17:57 (1 occurrences)
Last logged: 17:17:57

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 215, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 70, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 222, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 249, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/config_flow.py", line 69, in async_step_init
    if not (adapters := await async_get_bluetooth_adapters()):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/util.py", line 19, in async_get_bluetooth_adapters
    adapters = await get_bluetooth_adapters()
  File "/usr/local/lib/python3.10/site-packages/bluetooth_adapters/__init__.py", line 35, in get_bluetooth_adapters
    reply = await bus.call(msg)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 305, in call
    await future
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 365, in _message_reader
    if self._unmarshaller.unmarshall():
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 304, in unmarshall
    self._unmarshall()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 243, in _unmarshall
    self.read(16, prefetch=True)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 91, in read
    raise EOFError()
EOFError


========================

Error doing job: Future exception was never retrieved
-----------------------------------------------------
Logger: homeassistant
Source: components/bluetooth/util.py:19
First occurred: 17:18:00 (1 occurrences)
Last logged: 17:18:00

Error doing job: Future exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 82, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 136, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 215, in post
    return await super().post(request)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 73, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 70, in post
    result = await self._flow_mgr.async_init(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 222, in async_init
    flow, result = await task
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 249, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/config_flow.py", line 69, in async_step_init
    if not (adapters := await async_get_bluetooth_adapters()):
  File "/usr/src/homeassistant/homeassistant/components/bluetooth/util.py", line 19, in async_get_bluetooth_adapters
    adapters = await get_bluetooth_adapters()
  File "/usr/local/lib/python3.10/site-packages/bluetooth_adapters/__init__.py", line 35, in get_bluetooth_adapters
    reply = await bus.call(msg)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 305, in call
    await future
  File "/usr/local/lib/python3.10/site-packages/dbus_next/aio/message_bus.py", line 365, in _message_reader
    if self._unmarshaller.unmarshall():
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 304, in unmarshall
    self._unmarshall()
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 243, in _unmarshall
    self.read(16, prefetch=True)
  File "/usr/local/lib/python3.10/site-packages/dbus_next/_private/unmarshaller.py", line 91, in read
    raise EOFError()
EOFError

Additional information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 18 (5 by maintainers)

Most upvoted comments

I finally got it to work. The problem was that my docker is in swarm mode, and in swarm security_opt (and custom AppArmor profiles) are not available. I created a custom AppArmor profile and replaced the docker-default one. Here it explains how to do that. I also had to add a few rules to /etc/dbus-1/system.d/bluetooth.conf.

I’ve attached the files. They are a bit messy, but they might help.

docker-default bluetooth.conf

I have the same issue running HA in a docker container with Ubuntu 22.04 LTS as the host OS, and the dbus path mounted as a RO volume