authz.rst 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. .. _client authorization:
  2. Client authorization
  3. --------------------
  4. When configuring a QEMU network backend with either TLS certificates or SASL
  5. authentication, access will be granted if the client successfully proves
  6. their identity. If the authorization identity database is scoped to the QEMU
  7. client this may be sufficient. It is common, however, for the identity database
  8. to be much broader and thus authentication alone does not enable sufficient
  9. access control. In this case QEMU provides a flexible system for enforcing
  10. finer grained authorization on clients post-authentication.
  11. Identity providers
  12. ~~~~~~~~~~~~~~~~~~
  13. At the time of writing there are two authentication frameworks used by QEMU
  14. that emit an identity upon completion.
  15. * TLS x509 certificate distinguished name.
  16. When configuring the QEMU backend as a network server with TLS, there
  17. are a choice of credentials to use. The most common scenario is to utilize
  18. x509 certificates. The simplest configuration only involves issuing
  19. certificates to the servers, allowing the client to avoid a MITM attack
  20. against their intended server.
  21. It is possible, however, to enable mutual verification by requiring that
  22. the client provide a certificate to the server to prove its own identity.
  23. This is done by setting the property ``verify-peer=yes`` on the
  24. ``tls-creds-x509`` object, which is in fact the default.
  25. When peer verification is enabled, client will need to be issued with a
  26. certificate by the same certificate authority as the server. If this is
  27. still not sufficiently strong access control the Distinguished Name of
  28. the certificate can be used as an identity in the QEMU authorization
  29. framework.
  30. * SASL username.
  31. When configuring the QEMU backend as a network server with SASL, upon
  32. completion of the SASL authentication mechanism, a username will be
  33. provided. The format of this username will vary depending on the choice
  34. of mechanism configured for SASL. It might be a simple UNIX style user
  35. ``joebloggs``, while if using Kerberos/GSSAPI it can have a realm
  36. attached ``joebloggs@QEMU.ORG``. Whatever format the username is presented
  37. in, it can be used with the QEMU authorization framework.
  38. Authorization drivers
  39. ~~~~~~~~~~~~~~~~~~~~~
  40. The QEMU authorization framework is a general purpose design with choice of
  41. user customizable drivers. These are provided as objects that can be
  42. created at startup using the ``-object`` argument, or at runtime using the
  43. ``object_add`` monitor command.
  44. Simple
  45. ^^^^^^
  46. This authorization driver provides a simple mechanism for granting access
  47. based on an exact match against a single identity. This is useful when it is
  48. known that only a single client is to be allowed access.
  49. A possible use case would be when configuring QEMU for an incoming live
  50. migration. It is known exactly which source QEMU the migration is expected
  51. to arrive from. The x509 certificate associated with this source QEMU would
  52. thus be used as the identity to match against. Alternatively if the virtual
  53. machine is dedicated to a specific tenant, then the VNC server would be
  54. configured with SASL and the username of only that tenant listed.
  55. To create an instance of this driver via QMP:
  56. ::
  57. {
  58. "execute": "object-add",
  59. "arguments": {
  60. "qom-type": "authz-simple",
  61. "id": "authz0",
  62. "identity": "fred"
  63. }
  64. }
  65. Or via the command line
  66. ::
  67. -object authz-simple,id=authz0,identity=fred
  68. List
  69. ^^^^
  70. In some network backends it will be desirable to grant access to a range of
  71. clients. This authorization driver provides a list mechanism for granting
  72. access by matching identities against a list of permitted one. Each match
  73. rule has an associated policy and a catch all policy applies if no rule
  74. matches. The match can either be done as an exact string comparison, or can
  75. use the shell-like glob syntax, which allows for use of wildcards.
  76. To create an instance of this class via QMP:
  77. ::
  78. {
  79. "execute": "object-add",
  80. "arguments": {
  81. "qom-type": "authz-list",
  82. "id": "authz0",
  83. "rules": [
  84. { "match": "fred", "policy": "allow", "format": "exact" },
  85. { "match": "bob", "policy": "allow", "format": "exact" },
  86. { "match": "danb", "policy": "deny", "format": "exact" },
  87. { "match": "dan*", "policy": "allow", "format": "glob" }
  88. ],
  89. "policy": "deny"
  90. }
  91. }
  92. Due to the way this driver requires setting nested properties, creating
  93. it on the command line will require use of the JSON syntax for ``-object``.
  94. In most cases, however, the next driver will be more suitable.
  95. List file
  96. ^^^^^^^^^
  97. This is a variant on the previous driver that allows for a more dynamic
  98. access control policy by storing the match rules in a standalone file
  99. that can be reloaded automatically upon change.
  100. To create an instance of this class via QMP:
  101. ::
  102. {
  103. "execute": "object-add",
  104. "arguments": {
  105. "qom-type": "authz-list-file",
  106. "id": "authz0",
  107. "filename": "/etc/qemu/myvm-vnc.acl",
  108. "refresh": true
  109. }
  110. }
  111. If ``refresh`` is ``yes``, inotify is used to monitor for changes
  112. to the file and auto-reload the rules.
  113. The ``myvm-vnc.acl`` file should contain the match rules in a format that
  114. closely matches the previous driver:
  115. ::
  116. {
  117. "rules": [
  118. { "match": "fred", "policy": "allow", "format": "exact" },
  119. { "match": "bob", "policy": "allow", "format": "exact" },
  120. { "match": "danb", "policy": "deny", "format": "exact" },
  121. { "match": "dan*", "policy": "allow", "format": "glob" }
  122. ],
  123. "policy": "deny"
  124. }
  125. The object can be created on the command line using
  126. ::
  127. -object authz-list-file,id=authz0,\
  128. filename=/etc/qemu/myvm-vnc.acl,refresh=on
  129. PAM
  130. ^^^
  131. In some scenarios it might be desirable to integrate with authorization
  132. mechanisms that are implemented outside of QEMU. In order to allow maximum
  133. flexibility, QEMU provides a driver that uses the ``PAM`` framework.
  134. To create an instance of this class via QMP:
  135. ::
  136. {
  137. "execute": "object-add",
  138. "arguments": {
  139. "qom-type": "authz-pam",
  140. "id": "authz0",
  141. "parameters": {
  142. "service": "qemu-vnc-tls"
  143. }
  144. }
  145. }
  146. The driver only uses the PAM "account" verification
  147. subsystem. The above config would require a config
  148. file /etc/pam.d/qemu-vnc-tls. For a simple file
  149. lookup it would contain
  150. ::
  151. account requisite pam_listfile.so item=user sense=allow \
  152. file=/etc/qemu/vnc.allow
  153. The external file would then contain a list of usernames.
  154. If x509 cert was being used as the username, a suitable
  155. entry would match the distinguished name:
  156. ::
  157. CN=laptop.berrange.com,O=Berrange Home,L=London,ST=London,C=GB
  158. On the command line it can be created using
  159. ::
  160. -object authz-pam,id=authz0,service=qemu-vnc-tls
  161. There are a variety of PAM plugins that can be used which are not illustrated
  162. here, and it is possible to implement brand new plugins using the PAM API.
  163. Connecting backends
  164. ~~~~~~~~~~~~~~~~~~~
  165. The authorization driver is created using the ``-object`` argument and then
  166. needs to be associated with a network service. The authorization driver object
  167. will be given a unique ID that needs to be referenced.
  168. The property to set in the network service will vary depending on the type of
  169. identity to verify. By convention, any network server backend that uses TLS
  170. will provide ``tls-authz`` property, while any server using SASL will provide
  171. a ``sasl-authz`` property.
  172. Thus an example using SASL and authorization for the VNC server would look
  173. like:
  174. ::
  175. $QEMU --object authz-simple,id=authz0,identity=fred \
  176. --vnc 0.0.0.0:1,sasl,sasl-authz=authz0
  177. While to validate both the x509 certificate and SASL username:
  178. ::
  179. echo "CN=laptop.qemu.org,O=QEMU Project,L=London,ST=London,C=GB" >> tls.acl
  180. $QEMU --object authz-simple,id=authz0,identity=fred \
  181. --object authz-list-file,id=authz1,filename=tls.acl \
  182. --object tls-creds-x509,id=tls0,dir=/etc/qemu/tls,verify-peer=yes \
  183. --vnc 0.0.0.0:1,sasl,sasl-authz=auth0,tls-creds=tls0,tls-authz=authz1