Desktop interface should allow access to org.freedesktop.DBus.Peer

For a project I need to access the unique ID of my system in a very reliable way, so I opted to using dbus for that but it seems snapd does not like that.

My python code looks like this

def get_machine_id():
    bus = dbus.SessionBus()
    obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
    iface = dbus.Interface(obj, 'org.freedesktop.DBus.Peer')
    return str(iface.get_dbus_method('GetMachineId')())

This is the error my program gets if its confined

om26er@chaoticX:~/code/crossbario/linux-desktop-manager$ linux-desktop-manager 
2018-04-07T03:34:26 Introspect error on org.freedesktop.DBus:/org/freedesktop/DBus: dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.166" (uid=1000 pid=32631 comm="python3 /snap/linux-desktop-manager/x1/bin/linux-d" label="snap.linux-desktop-manager.linux-desktop-manager (enforce)") interface="org.freedesktop.DBus.Introspectable" member="Introspect" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
2018-04-07T03:34:26 ApplicationSession could not be instantiated: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.166" (uid=1000 pid=32631 comm="python3 /snap/linux-desktop-manager/x1/bin/linux-d" label="snap.linux-desktop-manager.linux-desktop-manager (enforce)") interface="org.freedesktop.DBus.Peer" member="GetMachineId" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)
2018-04-07T03:34:26 Traceback (most recent call last):
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/autobahn/wamp/websocket.py", line 60, in onOpen
    self._session = self.factory._factory()
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/autobahn/asyncio/wamp.py", line 181, in create
    session = make(cfg)
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/linux_desktop_manager/wamp/display_component.py", line 25, in __init__
    self.machine_id = get_machine_id()
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/linux_desktop_manager/wamp/display_component.py", line 18, in get_machine_id
    return str(iface.get_dbus_method('GetMachineId')())
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/dbus/proxies.py", line 70, in __call__
    return self._proxy_method(*args, **keywords)
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/dbus/proxies.py", line 145, in __call__
    **keywords)
  File "/snap/linux-desktop-manager/x1/lib/python3.5/site-packages/dbus/connection.py", line 651, in call_blocking
    message, timeout)
dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: An AppArmor policy prevents this sender from sending this message to this recipient; type="method_call", sender=":1.166" (uid=1000 pid=32631 comm="python3 /snap/linux-desktop-manager/x1/bin/linux-d" label="snap.linux-desktop-manager.linux-desktop-manager (enforce)") interface="org.freedesktop.DBus.Peer" member="GetMachineId" error name="(unset)" requested_reply="0" destination="org.freedesktop.DBus" (bus)

\cc @jdstrand continuation of Need an interface to lock the screen

It is true that GetMachineId is not allowed by any interfaces. This should probably be in system-observe. I’ll add this to the next batch of updates.

https://github.com/snapcore/snapd/pull/5189

1 Like