DBus SystemBus policies

18,395

The simplest way to get going with the example above is to edit /etc/dbus-1/system.conf and add the following line:

<policy>
    ...
    <allow own="org.testobj.service"/>
</policy>

Relevant documentation.

Share:
18,395
Admin
Author by

Admin

Updated on July 19, 2022

Comments

  • Admin
    Admin almost 2 years

    I wrote a program that runs as session service through dbus.
    I wanted to make it run as system service (creating a dbus.SystemBus bus name) if executed by root (uid 0).
    I am trying to run for dbus.SystemBus what I currently run for dbus.SessionBus but get a policy error.
    The code (python but it doesn't really matter), cleared from everything unnecessary, I run is this:

    import gobject
    import dbus
    import dbus.service
    from dbus.mainloop.glib import DBusGMainLoop
    
    DBusGMainLoop(set_as_default=True)
    loop = gobject.MainLoop()
    
    class dbusService(dbus.service.Object):
        def __init__(self):
            bus_name = dbus.service.BusName('org.testobj.service', bus=dbus.SystemBus())
            dbus.service.Object.__init__(self, bus_name, '/org/testobj/service')
    
    a = dbusService()
    

    and get:

    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "<stdin>", line 3, in __init__
      File "/usr/lib/python2.7/site-packages/dbus/service.py", line 131, in __new__ retval = bus.request_name(name, name_flags)
      File "/usr/lib/python2.7/site-packages/dbus/bus.py", line 303, in request_name 'su', (name, flags))
      File "/usr/lib/python2.7/site-packages/dbus/connection.py", line 651, in call_blocking message, timeout)
    dbus.exceptions.DBusException: org.freedesktop.DBus.Error.AccessDenied: Connection ":1.48" is not allowed to own the service "org.testobj.service" due to security policies in the configuration file
    
  • Joris
    Joris over 7 years
    FYI that I needed to reload the dbus service (Centos 7): systemctl reload dbus for this to work