dbus.rst 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. =====
  2. D-Bus
  3. =====
  4. Introduction
  5. ============
  6. QEMU may be running with various helper processes involved:
  7. - vhost-user* processes (gpu, virtfs, input, etc...)
  8. - TPM emulation (or other devices)
  9. - user networking (slirp)
  10. - network services (DHCP/DNS, samba/ftp etc)
  11. - background tasks (compression, streaming etc)
  12. - client UI
  13. - admin & cli
  14. Having several processes allows stricter security rules, as well as
  15. greater modularity.
  16. While QEMU itself uses QMP as primary IPC (and Spice/VNC for remote
  17. display), D-Bus is the de facto IPC of choice on Unix systems. The
  18. wire format is machine friendly, good bindings exist for various
  19. languages, and there are various tools available.
  20. Using a bus, helper processes can discover and communicate with each
  21. other easily, without going through QEMU. The bus topology is also
  22. easier to apprehend and debug than a mesh. However, it is wise to
  23. consider the security aspects of it.
  24. Security
  25. ========
  26. A QEMU D-Bus bus should be private to a single VM. Thus, only
  27. cooperative tasks are running on the same bus to serve the VM.
  28. D-Bus, the protocol and standard, doesn't have mechanisms to enforce
  29. security between peers once the connection is established. Peers may
  30. have additional mechanisms to enforce security rules, based for
  31. example on UNIX credentials.
  32. The daemon can control which peers can send/recv messages using
  33. various metadata attributes, however, this is alone is not generally
  34. sufficient to make the deployment secure. The semantics of the actual
  35. methods implemented using D-Bus are just as critical. Peers need to
  36. carefully validate any information they received from a peer with a
  37. different trust level.
  38. dbus-daemon policy
  39. ------------------
  40. dbus-daemon can enforce various policies based on the UID/GID of the
  41. processes that are connected to it. It is thus a good idea to run
  42. helpers as different UID from QEMU and set appropriate policies.
  43. Depending on the use case, you may choose different scenarios:
  44. - Everything the same UID
  45. - Convenient for developers
  46. - Improved reliability - crash of one part doesn't take
  47. out entire VM
  48. - No security benefit over traditional QEMU, unless additional
  49. unless additional controls such as SELinux or AppArmor are
  50. applied
  51. - Two UIDs, one for QEMU, one for dbus & helpers
  52. - Moderately improved user based security isolation
  53. - Many UIDs, one for QEMU one for dbus and one for each helpers
  54. - Best user based security isolation
  55. - Complex to manager distinct UIDs needed for each VM
  56. For example, to allow only ``qemu`` user to talk to ``qemu-helper``
  57. ``org.qemu.Helper1`` service, a dbus-daemon policy may contain:
  58. .. code:: xml
  59. <policy user="qemu">
  60. <allow send_destination="org.qemu.Helper1"/>
  61. <allow receive_sender="org.qemu.Helper1"/>
  62. </policy>
  63. <policy user="qemu-helper">
  64. <allow own="org.qemu.Helper1"/>
  65. </policy>
  66. dbus-daemon can also perform SELinux checks based on the security
  67. context of the source and the target. For example, ``virtiofs_t``
  68. could be allowed to send a message to ``svirt_t``, but ``virtiofs_t``
  69. wouldn't be allowed to send a message to ``virtiofs_t``.
  70. See dbus-daemon man page for details.
  71. Guidelines
  72. ==========
  73. When implementing new D-Bus interfaces, it is recommended to follow
  74. the "D-Bus API Design Guidelines":
  75. https://dbus.freedesktop.org/doc/dbus-api-design.html
  76. The "org.qemu.*" prefix is reserved for services implemented &
  77. distributed by the QEMU project.
  78. QEMU Interfaces
  79. ===============
  80. :doc:`dbus-vmstate`
  81. :doc:`dbus-display`