[6726] Support ACLs for controlling VNC access ("Daniel P.
Revision: 6726
http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6726 Author: aliguori Date: 2009-03-06 20:27:37 +0000 (Fri, 06 Mar 2009)
Log Message:
-----------
Support ACLs for controlling VNC access ("Daniel P. Berrange")
This patch introduces a generic internal API for access control lists to be used by network servers in QEMU. It adds support for checking these ACL in the VNC server, in two places. The first ACL is for the SASL authentication mechanism, checking the SASL username. This ACL is called 'vnc.username'. The second is for the TLS authentication mechanism, when x509 client certificates are turned on, checking against the Distinguished Name of the client. This ACL is called 'vnc.x509dname'
The internal API provides for an ACL with the following characteristics
- A unique name, eg vnc.username, and vnc.x509dname.
- A default policy, allow or deny
- An ordered series of match rules, with allow or deny policy
If none of the match rules apply, then the default policy is used.
There is a monitor API to manipulate the ACLs, which I'll describe via examples
(qemu) acl show vnc.username
policy: allow
(qemu) acl policy vnc.username denya
acl: policy set to 'deny'
(qemu) acl allow vnc.username fred
acl: added rule at position 1
(qemu) acl allow vnc.username bob
acl: added rule at position 2
(qemu) acl allow vnc.username joe 1
acl: added rule at position 1
(qemu) acl show vnc.username
policy: deny
0: allow fred
1: allow joe
2: allow bob
(qemu) acl show vnc.x509dname
policy: allow
(qemu) acl policy vnc.x509dname deny
acl: policy set to 'deny'
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=London,CN=*
acl: added rule at position 1
(qemu) acl allow vnc.x509dname C=GB,O=ACME,L=Boston,CN=bob
acl: added rule at position 2
(qemu) acl show vnc.x509dname
policy: deny
0: allow C=GB,O=ACME,L=London,CN=*
1: allow C=GB,O=ACME,L=Boston,CN=bob
By default the VNC server will not use any ACLs, allowing access to the server if the user successfully authenticates. To enable use of ACLs to restrict user access, the ',acl' flag should be given when starting QEMU. The initial ACL activated will be a 'deny all' policy and should be customized using monitor commands.
eg enable SASL auth and ACLs
qemu .... -vnc localhost:1,sasl,acl
The next patch will provide a way to load a pre-defined ACL when starting up
Makefile | 6 + b/acl.c | 185 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ b/acl.h | 74 ++++++++++++++++++++++ configure | 18 +++++ monitor.c | 95 ++++++++++++++++++++++++++++ qemu-doc.texi | 49 ++++++++++++++ vnc-auth-sasl.c | 16 +++- vnc-auth-sasl.h | 7 ++ vnc-tls.c | 19 +++++ vnc-tls.h | 3 vnc.c | 21 ++++++ vnc.h | 3 12 files changed, 491 insertions(+), 5 deletions(-)
Modified Paths:
--------------
trunk/Makefile
trunk/configure
trunk/monitor.c
trunk/qemu-doc.texi
trunk/vnc-auth-sasl.c
trunk/vnc-auth-sasl.h
trunk/vnc.c
trunk/vnc.h
Added Paths:
-----------
trunk/acl.c
trunk/acl.h
Modified: trunk/Makefile
===================================================================
Makefile +4 -2
@@ -144,7 +144,7 @@ ifdef CONFIG_CURSES OBJS+=curses.o endif -OBJS+=vnc.o d3des.o +OBJS+=vnc.o acl.o d3des.o ifdef CONFIG_VNC_TLS OBJS+=vnc-tls.o vnc-auth-vencrypt.o endif
@@ -174,9 +174,11 @@ sdl.o audio/sdlaudio.o: CFLAGS += $(SDL_CFLAGS) +acl.o: acl.h acl.c + vnc.h: vnc-tls.h vnc-auth-vencrypt.h vnc-auth-sasl.h keymaps.h -vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h +vnc.o: vnc.c vnc.h vnc_keysym.h vnchextile.h d3des.c d3des.h acl.h vnc.o: CFLAGS += $(CONFIG_VNC_TLS_CFLAGS)
Added: trunk/acl.c
===================================================================
acl.c +185 -0
185 lines not on this page · raw message
Added: trunk/acl.h
===================================================================
acl.h +74 -0
74 lines not on this page · raw message
Modified: trunk/configure
===================================================================
configure +18 -0
@@ -862,6 +862,21 @@ fi ########################################## +# fnmatch() probe, used for ACL routines +fnmatch="no" +cat > $TMPC << EOF +#include <fnmatch.h> +int main(void) +{ + fnmatch("foo", "foo", 0); + return 0; +} +EOF +if $cc $ARCH_CFLAGS -o $TMPE $TMPC > /dev/null 2> /dev/null ; then + fnmatch="yes" +fi + +########################################## # vde libraries probe if test "$vde" = "yes" ; then cat > $TMPC << EOF
@@ -1421,6 +1436,9 @@ echo "CONFIG_VNC_SASL_LIBS=$vnc_sasl_libs" >> $config_mak echo "#define CONFIG_VNC_SASL 1" >> $config_h fi +if test "$fnmatch" = "yes" ; then + echo "#define HAVE_FNMATCH_H 1" >> $config_h +fi qemu_version=`head $source_path/VERSION` echo "VERSION=$qemu_version" >>$config_mak echo "#define QEMU_VERSION \"$qemu_version\"" >> $config_h
Modified: trunk/monitor.c
===================================================================
monitor.c +96 -0
120 lines not on this page · raw message
Modified: trunk/qemu-doc.texi
===================================================================
qemu-doc.texi +49 -0
61 lines not on this page · raw message
Modified: trunk/vnc-auth-sasl.c
===================================================================
vnc-auth-sasl.c +13 -3
@@ -120,22 +120,32 @@ {const void *val;int err; +int allow; err =sasl_getprop (vs->sasl.conn,SASL_USERNAME , &val);if (err !=SASL_OK ) { -VNC_DEBUG ("cannot query SASL username on connection %d (%s)\n" , +VNC_DEBUG ("cannot query SASL username on connection %d (%s), denying access\n" , err,sasl_errstring (err,NULL ,NULL ));return -1 ; }if (val ==NULL ) { -VNC_DEBUG ("no client username was found\n" ); +VNC_DEBUG ("no client username was found, denying access\n" );return -1 ; }VNC_DEBUG ("SASL client username %s\n" , (const char *)val); vs->sasl.username =qemu_strdup ((const char *)val); -return 0 ; +if (vs->vd->sasl.acl ==NULL ) { +VNC_DEBUG ("no ACL activated, allowing access\n" ); +return 0 ; + } + + allow =qemu_acl_party_is_allowed (vs->vd->sasl.acl, vs->sasl.username); + +VNC_DEBUG ("SASL client %s %s by ACL\n" , vs->sasl.username, + allow ?"allowed" :"denied" ); +return allow ?0 :-1 ; }static int vnc_auth_sasl_check_ssf (VncState *vs)
Modified: trunk/vnc-auth-sasl.h
===================================================================
vnc-auth-sasl.h +7 -0
@@ -30,7 +30,10 @@#include <sasl/sasl.h> typedef struct VncStateSASL VncStateSASL ; +typedef struct VncDisplaySASL VncDisplaySASL ; +#include "acl.h" +struct VncStateSASL {sasl_conn_t *conn;/* If we want to negotiate an SSF layer with client */
@@ -56,6 +59,10 @@char *mechlist; }; +struct VncDisplaySASL { +qemu_acl *acl; +}; +void vnc_sasl_client_cleanup (VncState *vs);long vnc_client_read_sasl (VncState *vs);
Modified: trunk/vnc.c
===================================================================
vnc.c +21 -0
@@ -28,6 +28,7 @@#include "sysemu.h" #include "qemu_socket.h" #include "qemu-timer.h" +#include "acl.h" #define VNC_REFRESH_INTERVAL (1000 / 30)
@@ -2083,6 +2084,7 @@int sasl =0 ;int saslErr;#endif +int acl =0 ;if (!vnc_display)return -1 ;
@@ -2139,9 +2141,28 @@ return -1; }#endif + }else if (strncmp (options,"acl" ,3 ) ==0 ) { + acl =1 ; } } +#ifdef CONFIG_VNC_TLS +if (acl && x509 && vs->tls.x509verify) { +if (!(vs->tls.acl =qemu_acl_init ("vnc.x509dname" ))) { +fprintf (stderr,"Failed to create x509 dname ACL\n" ); +exit (1 ); + } + } +#endif +#ifdef CONFIG_VNC_SASL +if (acl && sasl) { +if (!(vs->sasl.acl =qemu_acl_init ("vnc.username" ))) { +fprintf (stderr,"Failed to create username ACL\n" ); +exit (1 ); + } + } +#endif +/* * Combinations we support here: *
Modified: trunk/vnc.h
===================================================================
vnc.h +3 -0
@@ -99,6 +99,9 @@int subauth;/* Used by VeNCrypt */ VncDisplayTLS tls;#endif +#ifdef CONFIG_VNC_SASL +VncDisplaySASL sasl; +#endif };struct VncState