vnc-security.rst 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. .. _VNC security:
  2. VNC security
  3. ------------
  4. The VNC server capability provides access to the graphical console of
  5. the guest VM across the network. This has a number of security
  6. considerations depending on the deployment scenarios.
  7. .. _vnc_005fsec_005fnone:
  8. Without passwords
  9. ~~~~~~~~~~~~~~~~~
  10. The simplest VNC server setup does not include any form of
  11. authentication. For this setup it is recommended to restrict it to
  12. listen on a UNIX domain socket only. For example
  13. .. parsed-literal::
  14. |qemu_system| [...OPTIONS...] -vnc unix:/home/joebloggs/.qemu-myvm-vnc
  15. This ensures that only users on local box with read/write access to that
  16. path can access the VNC server. To securely access the VNC server from a
  17. remote machine, a combination of netcat+ssh can be used to provide a
  18. secure tunnel.
  19. .. _vnc_005fsec_005fpassword:
  20. With passwords
  21. ~~~~~~~~~~~~~~
  22. The VNC protocol has limited support for password based authentication.
  23. Since the protocol limits passwords to 8 characters it should not be
  24. considered to provide high security. The password can be fairly easily
  25. brute-forced by a client making repeat connections. For this reason, a
  26. VNC server using password authentication should be restricted to only
  27. listen on the loopback interface or UNIX domain sockets. Password
  28. authentication is not supported when operating in FIPS 140-2 compliance
  29. mode as it requires the use of the DES cipher. Password authentication
  30. is requested with the ``password`` option, and then once QEMU is running
  31. the password is set with the monitor. Until the monitor is used to set
  32. the password all clients will be rejected.
  33. .. parsed-literal::
  34. |qemu_system| [...OPTIONS...] -vnc :1,password=on -monitor stdio
  35. (qemu) change vnc password
  36. Password: ********
  37. (qemu)
  38. .. _vnc_005fsec_005fcertificate:
  39. With x509 certificates
  40. ~~~~~~~~~~~~~~~~~~~~~~
  41. The QEMU VNC server also implements the VeNCrypt extension allowing use
  42. of TLS for encryption of the session, and x509 certificates for
  43. authentication. The use of x509 certificates is strongly recommended,
  44. because TLS on its own is susceptible to man-in-the-middle attacks.
  45. Basic x509 certificate support provides a secure session, but no
  46. authentication. This allows any client to connect, and provides an
  47. encrypted session.
  48. .. parsed-literal::
  49. |qemu_system| [...OPTIONS...] \
  50. -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=off \
  51. -vnc :1,tls-creds=tls0 -monitor stdio
  52. In the above example ``/etc/pki/qemu`` should contain at least three
  53. files, ``ca-cert.pem``, ``server-cert.pem`` and ``server-key.pem``.
  54. Unprivileged users will want to use a private directory, for example
  55. ``$HOME/.pki/qemu``. NB the ``server-key.pem`` file should be protected
  56. with file mode 0600 to only be readable by the user owning it.
  57. .. _vnc_005fsec_005fcertificate_005fverify:
  58. With x509 certificates and client verification
  59. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  60. Certificates can also provide a means to authenticate the client
  61. connecting. The server will request that the client provide a
  62. certificate, which it will then validate against the CA certificate.
  63. This is a good choice if deploying in an environment with a private
  64. internal certificate authority. It uses the same syntax as previously,
  65. but with ``verify-peer`` set to ``on`` instead.
  66. .. parsed-literal::
  67. |qemu_system| [...OPTIONS...] \
  68. -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=on \
  69. -vnc :1,tls-creds=tls0 -monitor stdio
  70. .. _vnc_005fsec_005fcertificate_005fpw:
  71. With x509 certificates, client verification and passwords
  72. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  73. Finally, the previous method can be combined with VNC password
  74. authentication to provide two layers of authentication for clients.
  75. .. parsed-literal::
  76. |qemu_system| [...OPTIONS...] \
  77. -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=on \
  78. -vnc :1,tls-creds=tls0,password=on -monitor stdio
  79. (qemu) change vnc password
  80. Password: ********
  81. (qemu)
  82. .. _vnc_005fsec_005fsasl:
  83. With SASL authentication
  84. ~~~~~~~~~~~~~~~~~~~~~~~~
  85. The SASL authentication method is a VNC extension, that provides an
  86. easily extendable, pluggable authentication method. This allows for
  87. integration with a wide range of authentication mechanisms, such as PAM,
  88. GSSAPI/Kerberos, LDAP, SQL databases, one-time keys and more. The
  89. strength of the authentication depends on the exact mechanism
  90. configured. If the chosen mechanism also provides a SSF layer, then it
  91. will encrypt the datastream as well.
  92. Refer to the later docs on how to choose the exact SASL mechanism used
  93. for authentication, but assuming use of one supporting SSF, then QEMU
  94. can be launched with:
  95. .. parsed-literal::
  96. |qemu_system| [...OPTIONS...] -vnc :1,sasl=on -monitor stdio
  97. .. _vnc_005fsec_005fcertificate_005fsasl:
  98. With x509 certificates and SASL authentication
  99. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  100. If the desired SASL authentication mechanism does not supported SSF
  101. layers, then it is strongly advised to run it in combination with TLS
  102. and x509 certificates. This provides securely encrypted data stream,
  103. avoiding risk of compromising of the security credentials. This can be
  104. enabled, by combining the 'sasl' option with the aforementioned TLS +
  105. x509 options:
  106. .. parsed-literal::
  107. |qemu_system| [...OPTIONS...] \
  108. -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=on \
  109. -vnc :1,tls-creds=tls0,sasl=on -monitor stdio
  110. .. _vnc_005fsetup_005fsasl:
  111. Configuring SASL mechanisms
  112. ~~~~~~~~~~~~~~~~~~~~~~~~~~~
  113. The following documentation assumes use of the Cyrus SASL implementation
  114. on a Linux host, but the principles should apply to any other SASL
  115. implementation or host. When SASL is enabled, the mechanism
  116. configuration will be loaded from system default SASL service config
  117. /etc/sasl2/qemu.conf. If running QEMU as an unprivileged user, an
  118. environment variable SASL_CONF_PATH can be used to make it search
  119. alternate locations for the service config file.
  120. If the TLS option is enabled for VNC, then it will provide session
  121. encryption, otherwise the SASL mechanism will have to provide
  122. encryption. In the latter case the list of possible plugins that can be
  123. used is drastically reduced. In fact only the GSSAPI SASL mechanism
  124. provides an acceptable level of security by modern standards. Previous
  125. versions of QEMU referred to the DIGEST-MD5 mechanism, however, it has
  126. multiple serious flaws described in detail in RFC 6331 and thus should
  127. never be used any more. The SCRAM-SHA-256 mechanism provides a simple
  128. username/password auth facility similar to DIGEST-MD5, but does not
  129. support session encryption, so can only be used in combination with TLS.
  130. When not using TLS the recommended configuration is
  131. ::
  132. mech_list: gssapi
  133. keytab: /etc/qemu/krb5.tab
  134. This says to use the 'GSSAPI' mechanism with the Kerberos v5 protocol,
  135. with the server principal stored in /etc/qemu/krb5.tab. For this to work
  136. the administrator of your KDC must generate a Kerberos principal for the
  137. server, with a name of 'qemu/somehost.example.com@EXAMPLE.COM' replacing
  138. 'somehost.example.com' with the fully qualified host name of the machine
  139. running QEMU, and 'EXAMPLE.COM' with the Kerberos Realm.
  140. When using TLS, if username+password authentication is desired, then a
  141. reasonable configuration is
  142. ::
  143. mech_list: scram-sha-256
  144. sasldb_path: /etc/qemu/passwd.db
  145. The ``saslpasswd2`` program can be used to populate the ``passwd.db``
  146. file with accounts. Note that the ``passwd.db`` file stores passwords
  147. in clear text.
  148. Other SASL configurations will be left as an exercise for the reader.
  149. Note that all mechanisms, except GSSAPI, should be combined with use of
  150. TLS to ensure a secure data channel.