从无根 Docker 容器访问 USB 蓝牙加密狗

问题描述

按照 here 所述设置无根 Docker 后,我尝试从容器内部使用蓝牙 USB 加密狗。我确认加密狗在主机上工作,我可以成功运行 hcitool -i hci0 lescan(使用 root 用户)。从互联网上的许多帖子来看,似乎必须使用以下选项的组合来启动容器:

  • --net=host
  • --privileged
  • 有能力NET_ADMIN
  • 有能力NET_RAW
  • 有能力SYS_ADMIN

请注意,我使用的是 Portainer,但使用的等效 CLI 命令是 docker run -ti --privileged --net=host --cap-add=NET_ADMIN --cap-add=NET_RAW --cap-add=SYS_ADMIN ubuntu:latest --name bletest /bin/bash。因此,我使用所有这些选项启动了容器 - 但是,尝试访问设备时出现以下错误

root@srv:/# service dbus status
 * dbus is running
root@srv:/# hciconfig hci0
Can't open HCI socket.: Address family not supported by protocol
root@srv:/# /usr/lib/bluetooth/bluetoothd -d -n
bluetoothd[790]: Bluetooth daemon 5.53
bluetoothd[790]: src/main.c:parse_config() parsing /etc/bluetooth/main.conf
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “discoverableTimeout” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “AlwaysPairable” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “PairableTimeout” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “Privacy” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “Name” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “Class” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “deviceid” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have key “ReverseServicediscovery” in group “General”
bluetoothd[790]: src/main.c:parse_config() Key file does not have group “GATT”
bluetoothd[790]: src/main.c:parse_config() Key file does not have group “GATT”
bluetoothd[790]: src/main.c:parse_config() Key file does not have group “GATT”
bluetoothd[790]: Failed to access management interface
bluetoothd[790]: Adapter handling initialization Failed

here 使用 -v /var/lib/bluetooth -v /sys/fs/cgroup:/sys/fs/cgroup:ro 运行:

root@srv:/# ls -lah /var/lib/bluetooth/00\:02\:72\:CD\:0B\:0B/
ls: cannot open directory '/var/lib/bluetooth/00:02:72:CD:0B:0B/': Permission denied

最后一个命令在主机上运行,​​这让我怀疑仍然存在一些权限错误。是否还有其他选项可以设置以允许使用容器中的蓝牙加密狗?

请注意,我在测试设备后从主机上卸载了 bluez,因为我读到 here 如果某些蓝牙服务访问它可能会被主机阻止。之后,我还确保物理重新连接加密狗。

编辑:另请注意,(现在)我将主机系统上的 Docker 用户 (dkr) 添加到蓝牙和 netdev(后者不存在,所以我创建了它)组。我确认主机用户可以使用 bluetoothctl 扫描设备 (scan on/off)。但是,由于某种原因,用户仍然不能运行 hcitool lescan

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)