1*324b2298SPaolo Bonzini.. _vnc_005fsecurity: 2*324b2298SPaolo Bonzini 3*324b2298SPaolo BonziniVNC security 4*324b2298SPaolo Bonzini------------ 5*324b2298SPaolo Bonzini 6*324b2298SPaolo BonziniThe VNC server capability provides access to the graphical console of 7*324b2298SPaolo Bonzinithe guest VM across the network. This has a number of security 8*324b2298SPaolo Bonziniconsiderations depending on the deployment scenarios. 9*324b2298SPaolo Bonzini 10*324b2298SPaolo Bonzini.. _vnc_005fsec_005fnone: 11*324b2298SPaolo Bonzini 12*324b2298SPaolo BonziniWithout passwords 13*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~ 14*324b2298SPaolo Bonzini 15*324b2298SPaolo BonziniThe simplest VNC server setup does not include any form of 16*324b2298SPaolo Bonziniauthentication. For this setup it is recommended to restrict it to 17*324b2298SPaolo Bonzinilisten on a UNIX domain socket only. For example 18*324b2298SPaolo Bonzini 19*324b2298SPaolo Bonzini.. parsed-literal:: 20*324b2298SPaolo Bonzini 21*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] -vnc unix:/home/joebloggs/.qemu-myvm-vnc 22*324b2298SPaolo Bonzini 23*324b2298SPaolo BonziniThis ensures that only users on local box with read/write access to that 24*324b2298SPaolo Bonzinipath can access the VNC server. To securely access the VNC server from a 25*324b2298SPaolo Bonziniremote machine, a combination of netcat+ssh can be used to provide a 26*324b2298SPaolo Bonzinisecure tunnel. 27*324b2298SPaolo Bonzini 28*324b2298SPaolo Bonzini.. _vnc_005fsec_005fpassword: 29*324b2298SPaolo Bonzini 30*324b2298SPaolo BonziniWith passwords 31*324b2298SPaolo Bonzini~~~~~~~~~~~~~~ 32*324b2298SPaolo Bonzini 33*324b2298SPaolo BonziniThe VNC protocol has limited support for password based authentication. 34*324b2298SPaolo BonziniSince the protocol limits passwords to 8 characters it should not be 35*324b2298SPaolo Bonziniconsidered to provide high security. The password can be fairly easily 36*324b2298SPaolo Bonzinibrute-forced by a client making repeat connections. For this reason, a 37*324b2298SPaolo BonziniVNC server using password authentication should be restricted to only 38*324b2298SPaolo Bonzinilisten on the loopback interface or UNIX domain sockets. Password 39*324b2298SPaolo Bonziniauthentication is not supported when operating in FIPS 140-2 compliance 40*324b2298SPaolo Bonzinimode as it requires the use of the DES cipher. Password authentication 41*324b2298SPaolo Bonziniis requested with the ``password`` option, and then once QEMU is running 42*324b2298SPaolo Bonzinithe password is set with the monitor. Until the monitor is used to set 43*324b2298SPaolo Bonzinithe password all clients will be rejected. 44*324b2298SPaolo Bonzini 45*324b2298SPaolo Bonzini.. parsed-literal:: 46*324b2298SPaolo Bonzini 47*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] -vnc :1,password -monitor stdio 48*324b2298SPaolo Bonzini (qemu) change vnc password 49*324b2298SPaolo Bonzini Password: ******** 50*324b2298SPaolo Bonzini (qemu) 51*324b2298SPaolo Bonzini 52*324b2298SPaolo Bonzini.. _vnc_005fsec_005fcertificate: 53*324b2298SPaolo Bonzini 54*324b2298SPaolo BonziniWith x509 certificates 55*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~ 56*324b2298SPaolo Bonzini 57*324b2298SPaolo BonziniThe QEMU VNC server also implements the VeNCrypt extension allowing use 58*324b2298SPaolo Bonziniof TLS for encryption of the session, and x509 certificates for 59*324b2298SPaolo Bonziniauthentication. The use of x509 certificates is strongly recommended, 60*324b2298SPaolo Bonzinibecause TLS on its own is susceptible to man-in-the-middle attacks. 61*324b2298SPaolo BonziniBasic x509 certificate support provides a secure session, but no 62*324b2298SPaolo Bonziniauthentication. This allows any client to connect, and provides an 63*324b2298SPaolo Bonziniencrypted session. 64*324b2298SPaolo Bonzini 65*324b2298SPaolo Bonzini.. parsed-literal:: 66*324b2298SPaolo Bonzini 67*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] \ 68*324b2298SPaolo Bonzini -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=no \ 69*324b2298SPaolo Bonzini -vnc :1,tls-creds=tls0 -monitor stdio 70*324b2298SPaolo Bonzini 71*324b2298SPaolo BonziniIn the above example ``/etc/pki/qemu`` should contain at least three 72*324b2298SPaolo Bonzinifiles, ``ca-cert.pem``, ``server-cert.pem`` and ``server-key.pem``. 73*324b2298SPaolo BonziniUnprivileged users will want to use a private directory, for example 74*324b2298SPaolo Bonzini``$HOME/.pki/qemu``. NB the ``server-key.pem`` file should be protected 75*324b2298SPaolo Bonziniwith file mode 0600 to only be readable by the user owning it. 76*324b2298SPaolo Bonzini 77*324b2298SPaolo Bonzini.. _vnc_005fsec_005fcertificate_005fverify: 78*324b2298SPaolo Bonzini 79*324b2298SPaolo BonziniWith x509 certificates and client verification 80*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 81*324b2298SPaolo Bonzini 82*324b2298SPaolo BonziniCertificates can also provide a means to authenticate the client 83*324b2298SPaolo Bonziniconnecting. The server will request that the client provide a 84*324b2298SPaolo Bonzinicertificate, which it will then validate against the CA certificate. 85*324b2298SPaolo BonziniThis is a good choice if deploying in an environment with a private 86*324b2298SPaolo Bonziniinternal certificate authority. It uses the same syntax as previously, 87*324b2298SPaolo Bonzinibut with ``verify-peer`` set to ``yes`` instead. 88*324b2298SPaolo Bonzini 89*324b2298SPaolo Bonzini.. parsed-literal:: 90*324b2298SPaolo Bonzini 91*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] \ 92*324b2298SPaolo Bonzini -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=yes \ 93*324b2298SPaolo Bonzini -vnc :1,tls-creds=tls0 -monitor stdio 94*324b2298SPaolo Bonzini 95*324b2298SPaolo Bonzini.. _vnc_005fsec_005fcertificate_005fpw: 96*324b2298SPaolo Bonzini 97*324b2298SPaolo BonziniWith x509 certificates, client verification and passwords 98*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 99*324b2298SPaolo Bonzini 100*324b2298SPaolo BonziniFinally, the previous method can be combined with VNC password 101*324b2298SPaolo Bonziniauthentication to provide two layers of authentication for clients. 102*324b2298SPaolo Bonzini 103*324b2298SPaolo Bonzini.. parsed-literal:: 104*324b2298SPaolo Bonzini 105*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] \ 106*324b2298SPaolo Bonzini -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=yes \ 107*324b2298SPaolo Bonzini -vnc :1,tls-creds=tls0,password -monitor stdio 108*324b2298SPaolo Bonzini (qemu) change vnc password 109*324b2298SPaolo Bonzini Password: ******** 110*324b2298SPaolo Bonzini (qemu) 111*324b2298SPaolo Bonzini 112*324b2298SPaolo Bonzini.. _vnc_005fsec_005fsasl: 113*324b2298SPaolo Bonzini 114*324b2298SPaolo BonziniWith SASL authentication 115*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~ 116*324b2298SPaolo Bonzini 117*324b2298SPaolo BonziniThe SASL authentication method is a VNC extension, that provides an 118*324b2298SPaolo Bonzinieasily extendable, pluggable authentication method. This allows for 119*324b2298SPaolo Bonziniintegration with a wide range of authentication mechanisms, such as PAM, 120*324b2298SPaolo BonziniGSSAPI/Kerberos, LDAP, SQL databases, one-time keys and more. The 121*324b2298SPaolo Bonzinistrength of the authentication depends on the exact mechanism 122*324b2298SPaolo Bonziniconfigured. If the chosen mechanism also provides a SSF layer, then it 123*324b2298SPaolo Bonziniwill encrypt the datastream as well. 124*324b2298SPaolo Bonzini 125*324b2298SPaolo BonziniRefer to the later docs on how to choose the exact SASL mechanism used 126*324b2298SPaolo Bonzinifor authentication, but assuming use of one supporting SSF, then QEMU 127*324b2298SPaolo Bonzinican be launched with: 128*324b2298SPaolo Bonzini 129*324b2298SPaolo Bonzini.. parsed-literal:: 130*324b2298SPaolo Bonzini 131*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] -vnc :1,sasl -monitor stdio 132*324b2298SPaolo Bonzini 133*324b2298SPaolo Bonzini.. _vnc_005fsec_005fcertificate_005fsasl: 134*324b2298SPaolo Bonzini 135*324b2298SPaolo BonziniWith x509 certificates and SASL authentication 136*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 137*324b2298SPaolo Bonzini 138*324b2298SPaolo BonziniIf the desired SASL authentication mechanism does not supported SSF 139*324b2298SPaolo Bonzinilayers, then it is strongly advised to run it in combination with TLS 140*324b2298SPaolo Bonziniand x509 certificates. This provides securely encrypted data stream, 141*324b2298SPaolo Bonziniavoiding risk of compromising of the security credentials. This can be 142*324b2298SPaolo Bonzinienabled, by combining the 'sasl' option with the aforementioned TLS + 143*324b2298SPaolo Bonzinix509 options: 144*324b2298SPaolo Bonzini 145*324b2298SPaolo Bonzini.. parsed-literal:: 146*324b2298SPaolo Bonzini 147*324b2298SPaolo Bonzini |qemu_system| [...OPTIONS...] \ 148*324b2298SPaolo Bonzini -object tls-creds-x509,id=tls0,dir=/etc/pki/qemu,endpoint=server,verify-peer=yes \ 149*324b2298SPaolo Bonzini -vnc :1,tls-creds=tls0,sasl -monitor stdio 150*324b2298SPaolo Bonzini 151*324b2298SPaolo Bonzini.. _vnc_005fsetup_005fsasl: 152*324b2298SPaolo Bonzini 153*324b2298SPaolo BonziniConfiguring SASL mechanisms 154*324b2298SPaolo Bonzini~~~~~~~~~~~~~~~~~~~~~~~~~~~ 155*324b2298SPaolo Bonzini 156*324b2298SPaolo BonziniThe following documentation assumes use of the Cyrus SASL implementation 157*324b2298SPaolo Bonzinion a Linux host, but the principles should apply to any other SASL 158*324b2298SPaolo Bonziniimplementation or host. When SASL is enabled, the mechanism 159*324b2298SPaolo Bonziniconfiguration will be loaded from system default SASL service config 160*324b2298SPaolo Bonzini/etc/sasl2/qemu.conf. If running QEMU as an unprivileged user, an 161*324b2298SPaolo Bonzinienvironment variable SASL_CONF_PATH can be used to make it search 162*324b2298SPaolo Bonzinialternate locations for the service config file. 163*324b2298SPaolo Bonzini 164*324b2298SPaolo BonziniIf the TLS option is enabled for VNC, then it will provide session 165*324b2298SPaolo Bonziniencryption, otherwise the SASL mechanism will have to provide 166*324b2298SPaolo Bonziniencryption. In the latter case the list of possible plugins that can be 167*324b2298SPaolo Bonziniused is drastically reduced. In fact only the GSSAPI SASL mechanism 168*324b2298SPaolo Bonziniprovides an acceptable level of security by modern standards. Previous 169*324b2298SPaolo Bonziniversions of QEMU referred to the DIGEST-MD5 mechanism, however, it has 170*324b2298SPaolo Bonzinimultiple serious flaws described in detail in RFC 6331 and thus should 171*324b2298SPaolo Bonzininever be used any more. The SCRAM-SHA-1 mechanism provides a simple 172*324b2298SPaolo Bonziniusername/password auth facility similar to DIGEST-MD5, but does not 173*324b2298SPaolo Bonzinisupport session encryption, so can only be used in combination with TLS. 174*324b2298SPaolo Bonzini 175*324b2298SPaolo BonziniWhen not using TLS the recommended configuration is 176*324b2298SPaolo Bonzini 177*324b2298SPaolo Bonzini:: 178*324b2298SPaolo Bonzini 179*324b2298SPaolo Bonzini mech_list: gssapi 180*324b2298SPaolo Bonzini keytab: /etc/qemu/krb5.tab 181*324b2298SPaolo Bonzini 182*324b2298SPaolo BonziniThis says to use the 'GSSAPI' mechanism with the Kerberos v5 protocol, 183*324b2298SPaolo Bonziniwith the server principal stored in /etc/qemu/krb5.tab. For this to work 184*324b2298SPaolo Bonzinithe administrator of your KDC must generate a Kerberos principal for the 185*324b2298SPaolo Bonziniserver, with a name of 'qemu/somehost.example.com@EXAMPLE.COM' replacing 186*324b2298SPaolo Bonzini'somehost.example.com' with the fully qualified host name of the machine 187*324b2298SPaolo Bonzinirunning QEMU, and 'EXAMPLE.COM' with the Kerberos Realm. 188*324b2298SPaolo Bonzini 189*324b2298SPaolo BonziniWhen using TLS, if username+password authentication is desired, then a 190*324b2298SPaolo Bonzinireasonable configuration is 191*324b2298SPaolo Bonzini 192*324b2298SPaolo Bonzini:: 193*324b2298SPaolo Bonzini 194*324b2298SPaolo Bonzini mech_list: scram-sha-1 195*324b2298SPaolo Bonzini sasldb_path: /etc/qemu/passwd.db 196*324b2298SPaolo Bonzini 197*324b2298SPaolo BonziniThe ``saslpasswd2`` program can be used to populate the ``passwd.db`` 198*324b2298SPaolo Bonzinifile with accounts. 199*324b2298SPaolo Bonzini 200*324b2298SPaolo BonziniOther SASL configurations will be left as an exercise for the reader. 201*324b2298SPaolo BonziniNote that all mechanisms, except GSSAPI, should be combined with use of 202*324b2298SPaolo BonziniTLS to ensure a secure data channel. 203