| 1 |
D-BUS System Activation |
| 2 |
|
| 3 |
Introduction: |
| 4 |
|
| 5 |
The dbus-daemon runs as the dbus user, and is therefore unprivileged. |
| 6 |
Earlier attempts [1] by David Zeuthen at launching system scripts using a |
| 7 |
custom DBUS protocol were reviewed, but deemed too difficult to audit, and |
| 8 |
also due to a multi-threaded design, too difficult to test. |
| 9 |
In the next few paragraphs I will outline a simpler setuid approach for |
| 10 |
launching daemons as a configured user. |
| 11 |
|
| 12 |
Scope: |
| 13 |
|
| 14 |
Launching programs using dbus has been a topic of interest for many months. |
| 15 |
This would allow simple systems to only start services that are needed, |
| 16 |
and that are automatically started only when first requested. |
| 17 |
This removes the need for an init system, and means that we can trivially |
| 18 |
startup services in parallel. |
| 19 |
This has immediate pressing need for OLPC, with a longer term evaluation for |
| 20 |
perhaps Fedora and RHEL. |
| 21 |
|
| 22 |
Details: |
| 23 |
|
| 24 |
Setuid applications have to used only when absolutely necessary. |
| 25 |
In this implementation I have an single executable, |
| 26 |
dbus-daemon-launch-helper, with the ownership root:dbus. |
| 27 |
This has the permissions 4750, i.e. u+rwx g+rx +setuid. |
| 28 |
It is located in /usr/libexec/ and thus is not designed to be invoked by a |
| 29 |
user directly. |
| 30 |
|
| 31 |
The helper must not be passed input that can be changed maliciously, and |
| 32 |
therefore passing a random path with user id is totally out of the question. |
| 33 |
In this implementation a similar idea as discussed with Davids' patch was |
| 34 |
taken, that to pass a single name argument to the helper. |
| 35 |
The service filename of "org.me.test.service" is then searched for in |
| 36 |
/usr/share/dbus-1/system-services or other specified directories. |
| 37 |
|
| 38 |
If applications want to be activated on the system _and_ session busses, then |
| 39 |
service files should be installed in both directories. |
| 40 |
|
| 41 |
A typical service file would look like: |
| 42 |
|
| 43 |
[D-BUS Service] |
| 44 |
Name=org.me.test |
| 45 |
Exec=/usr/sbin/dbus-test-server.py |
| 46 |
User=ftp |
| 47 |
|
| 48 |
This gives the user to switch to, and also the path of the executable. |
| 49 |
The service name must match that specified in the /etc/dbus-1/system.d or |
| 50 |
/usr/share/dbus-1/system.d conf file. |
| 51 |
|
| 52 |
Precautions taken: |
| 53 |
|
| 54 |
* Only the bus name is passed to the helper, and this is validated |
| 55 |
* We are super paranoid about the user that called us, and what permissions we have. |
| 56 |
* We clear all environment variables except for DBUS_VERBOSE which is used for debugging |
| 57 |
* Anything out of the ordinary causes the helper to abort. |
| 58 |
|
| 59 |
Launching services: |
| 60 |
|
| 61 |
Trivial methods on services can be called directly and the launch helper will |
| 62 |
start the service and execute the method on the service. The lauching of the |
| 63 |
service is completely transparent to the caller, e.g.: |
| 64 |
|
| 65 |
dbus-send --system --print-reply \ |
| 66 |
--dest=org.freedesktop.Hal \ |
| 67 |
/org/freedesktop/Hal/Manager \ |
| 68 |
org.freedesktop.Hal.Manager.DeviceExists \ |
| 69 |
string:/org/freedesktop/Hal/devices/computer |
| 70 |
|
| 71 |
If you wish to activate the service without calling a well known method, |
| 72 |
the standard dbus method StartServiceByName can be used: |
| 73 |
|
| 74 |
dbus-send --system --print-reply \ |
| 75 |
--dest=org.freedesktop.DBus \ |
| 76 |
/org/freedesktop/DBus \ |
| 77 |
org.freedesktop.DBus.StartServiceByName \ |
| 78 |
string:org.freedesktop.Hal uint32:0 |
| 79 |
|
| 80 |
[1] http://lists.freedesktop.org/archives/dbus/2006-October/006096.html |
| 81 |
|