From patchwork Thu Jun 2 16:46:27 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 9151031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 596AC60467 for ; Thu, 2 Jun 2016 17:22:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4741028309 for ; Thu, 2 Jun 2016 17:22:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3C15A2831B; Thu, 2 Jun 2016 17:22:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.9 required=2.0 tests=BAYES_00,FSL_HELO_HOME, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AC65F28309 for ; Thu, 2 Jun 2016 17:22:12 +0000 (UTC) Received: from localhost ([::1]:49417 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8WJv-0000Zn-S2 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 13:22:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38741) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vm4-0004y9-Na for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Vm3-0003c0-Gx for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:12 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50869) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vlp-0003WG-JT; Thu, 02 Jun 2016 12:46:57 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 238A764070; Thu, 2 Jun 2016 16:46:57 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-7-181.ams2.redhat.com [10.36.7.181]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u52GkVdT023498; Thu, 2 Jun 2016 12:46:55 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 17:46:27 +0100 Message-Id: <1464885987-4039-12-git-send-email-berrange@redhat.com> In-Reply-To: <1464885987-4039-1-git-send-email-berrange@redhat.com> References: <1464885987-4039-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 02 Jun 2016 16:46:57 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 11/11] vnc: allow specifying a custom ACL object name X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The VNC server has historically had support for ACLs to check both the SASL username and the TLS x509 distinguished name. The VNC server was responsible for creating the initial ACL, and the client app was then responsible for populating it with rules using the HMP 'acl_add' command. This is not satisfactory for a variety of reasons. There is no way to populate the ACLs from the command line, users are forced to use the HMP. With multiple network services all supporting TLS and ACLs now, it is desirable to be able to define a single ACL that is referenced by all services. To address these limitations, two new options are added to the VNC server CLI. The 'tls-acl' option takes the ID of a QAuthZ object to use for checking TLS x509 distinguished names, and the 'sasl-acl' option takes the ID of another object to use for checking SASL usernames. In this example, we setup two ACLs. The first allows any client with a certificate issued by the 'RedHat' organization in the 'London' locality. The second ACL allows clients with either the 'joe@REDHAT.COM' or 'fred@REDHAT.COM' kerberos usernames. Both ACLs must pass for the user to be allowed. $QEMU -object tls-creds-x509,id=tls0,dir=/home/berrange/qemutls,\ endpoint=server,verify-peer=yes \ -object authz-simple,id=tlsacl0,policy=deny,\ rules.0.match=O=RedHat,,L=London,rules.0.policy=allow \ -object authz-simple,id=saslacl0,policy=deny,\ rules.0.match=fred@REDHAT.COM,rules.0.policy=allow \ rules.0.match=joe@REDHAT.COM,rules.0.policy=allow \ -vnc 0.0.0.0:1,tls-creds=tls0,tls-acl=tlsacl0, sasl,sasl-acl=saslacl0 \ ...other QEMU args... Signed-off-by: Daniel P. Berrange --- ui/vnc.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 64 insertions(+), 13 deletions(-) diff --git a/ui/vnc.c b/ui/vnc.c index ba07715..939c3d3 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3263,6 +3263,12 @@ static QemuOptsList qemu_vnc_opts = { .name = "acl", .type = QEMU_OPT_BOOL, },{ + .name = "tls-acl", + .type = QEMU_OPT_STRING, + },{ + .name = "sasl-acl", + .type = QEMU_OPT_STRING, + },{ .name = "lossy", .type = QEMU_OPT_BOOL, },{ @@ -3485,6 +3491,8 @@ void vnc_display_open(const char *id, Error **errp) int saslErr; #endif int acl = 0; + const char *tlsacl; + const char *saslacl; int lock_key_sync = 1; if (!vs) { @@ -3672,6 +3680,27 @@ void vnc_display_open(const char *id, Error **errp) } } acl = qemu_opt_get_bool(opts, "acl", false); + tlsacl = qemu_opt_get(opts, "tls-acl"); + if (acl && tlsacl) { + error_setg(errp, "'acl' option is mutually exclusive with the " + "'tls-acl' options"); + goto fail; + } + if (tlsacl && !vs->tlscreds) { + error_setg(errp, "'tls-acl' provided but TLS is not enabled"); + goto fail; + } + + saslacl = qemu_opt_get(opts, "sasl-acl"); + if (acl && saslacl) { + error_setg(errp, "'acl' option is mutually exclusive with the " + "'sasl-acl' options"); + goto fail; + } + if (saslacl && !sasl) { + error_setg(errp, "'sasl-acl' provided but SASL auth is not enabled"); + goto fail; + } share = qemu_opt_get(opts, "share"); if (share) { @@ -3701,7 +3730,9 @@ void vnc_display_open(const char *id, Error **errp) vs->non_adaptive = true; } - if (acl) { + if (tlsacl) { + vs->tlsaclname = g_strdup(tlsacl); + } else if (acl) { if (strcmp(vs->id, "default") == 0) { vs->tlsaclname = g_strdup("vnc.x509dname"); } else { @@ -3712,19 +3743,39 @@ void vnc_display_open(const char *id, Error **errp) &error_abort); } #ifdef CONFIG_VNC_SASL - if (acl && sasl) { - char *aclname; + if (sasl) { + if (saslacl) { + Object *container, *acl; + container = object_get_objects_root(); + acl = object_resolve_path_component(container, saslacl); + if (!acl) { + error_setg(errp, "Cannot find ACL %s", saslacl); + goto fail; + } - if (strcmp(vs->id, "default") == 0) { - aclname = g_strdup("vnc.username"); - } else { - aclname = g_strdup_printf("vnc.%s.username", vs->id); - } - vs->sasl.acl = - QAUTHZ(qauthz_simple_new(aclname, - QAUTHZ_SIMPLE_POLICY_DENY, - &error_abort)); - g_free(aclname); + if (!object_dynamic_cast(acl, TYPE_QAUTHZ)) { + error_setg(errp, "Object '%s' is not a QAuthZ subclass", + saslacl); + goto fail; + } + vs->sasl.acl = QAUTHZ(acl); + } else if (acl) { + char *aclname; + + if (strcmp(vs->id, "default") == 0) { + aclname = g_strdup("vnc.username"); + } else { + aclname = g_strdup_printf("vnc.%s.username", vs->id); + } + vs->sasl.acl = + QAUTHZ(qauthz_simple_new(aclname, + QAUTHZ_SIMPLE_POLICY_DENY, + &error_abort)); + g_free(aclname); + } + } else if (saslacl) { + error_setg(errp, "SASL ACL provided when SASL is disabled"); + goto fail; } #endif