From patchwork Thu Jun 2 16:46:26 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: 9150999 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 3F4F560467 for ; Thu, 2 Jun 2016 17:09:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A63A2040D for ; Thu, 2 Jun 2016 17:09:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F0F228310; Thu, 2 Jun 2016 17:09:17 +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 97AF02040D for ; Thu, 2 Jun 2016 17:09:16 +0000 (UTC) Received: from localhost ([::1]:49297 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8W7P-0007GS-R7 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 13:09:15 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vlv-0004pS-Lg for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:04 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Vlt-0003Zk-HV for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:02 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30886) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vln-0003Uj-N0; Thu, 02 Jun 2016 12:46:55 -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 4385CC0703A5; Thu, 2 Jun 2016 16:46:55 +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 u52GkVdS023498; Thu, 2 Jun 2016 12:46:53 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 17:46:26 +0100 Message-Id: <1464885987-4039-11-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.32]); Thu, 02 Jun 2016 16:46:55 +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 10/11] chardev: add support for ACLs for TLS clients 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 Currently any client which can complete the TLS handshake is able to use a chardev server. The server admin can turn on the 'verify-peer' option for the x509 creds to require the client to provide a x509 certificate. This means the client will have to acquire a certificate from the CA before they are permitted to use the chardev server. This is still a fairly weak bar. This adds a 'tls-acl=ACL-ID' option to the socket chardev backend which takes the ID of a previously added 'QAuthZ' object instance. This ACL will be used to validate the client's x509 distinguished name. Clients failing the ACL will not be permitted to use the chardev server. For example to setup an ACL that only allows connection from a client whose x509 certificate distinguished name contains 'CN=fred', you would use: $QEMU -object tls-creds-x509,id=tls0,dir=/home/berrange/qemutls,\ endpoint=server,verify-peer=yes \ -object authz-simple,id=acl0,policy=deny,\ rules.0.match=\*CN=fred,rules.0.policy=allow \ -chardev socket,host=127.0.0.1,port=9000,server,\ tls-creds=tls0,tls-acl=acl0 \ ...other qemud args... Signed-off-by: Daniel P. Berrange --- qapi-schema.json | 2 ++ qemu-char.c | 11 ++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/qapi-schema.json b/qapi-schema.json index e7ec2a1..b231e2f 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -3293,6 +3293,7 @@ # @addr: socket address to listen on (server=true) # or connect to (server=false) # @tls-creds: #optional the ID of the TLS credentials object (since 2.6) +# @tls-acl: #optional the ID of the QAuthZ authorization object (since 2.6) # @server: #optional create server socket (default: true) # @wait: #optional wait for incoming connection on server # sockets (default: false). @@ -3308,6 +3309,7 @@ ## { 'struct': 'ChardevSocket', 'data': { 'addr' : 'SocketAddress', '*tls-creds' : 'str', + '*tls-acl' : 'str', '*server' : 'bool', '*wait' : 'bool', '*nodelay' : 'bool', diff --git a/qemu-char.c b/qemu-char.c index b597ee1..e3ced21 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -2604,6 +2604,7 @@ typedef struct { QIOChannelSocket *listen_ioc; guint listen_tag; QCryptoTLSCreds *tls_creds; + char *tls_acl; int connected; int max_size; int do_telnetopt; @@ -3047,7 +3048,7 @@ static void tcp_chr_tls_init(CharDriverState *chr) if (s->is_listen) { tioc = qio_channel_tls_new_server( s->ioc, s->tls_creds, - NULL, /* XXX Use an ACL */ + s->tls_acl, &err); } else { tioc = qio_channel_tls_new_client( @@ -3169,6 +3170,7 @@ static void tcp_chr_close(CharDriverState *chr) if (s->tls_creds) { object_unref(OBJECT(s->tls_creds)); } + g_free(s->tls_acl); if (s->write_msgfds_num) { g_free(s->write_msgfds); } @@ -3668,6 +3670,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, const char *host = qemu_opt_get(opts, "host"); const char *port = qemu_opt_get(opts, "port"); const char *tls_creds = qemu_opt_get(opts, "tls-creds"); + const char *tls_acl = qemu_opt_get(opts, "tls-acl"); SocketAddress *addr; ChardevSocket *sock; @@ -3701,6 +3704,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, ChardevBackend *backend, sock->has_reconnect = true; sock->reconnect = reconnect; sock->tls_creds = g_strdup(tls_creds); + sock->tls_acl = g_strdup(tls_acl); addr = g_new0(SocketAddress, 1); if (path) { @@ -4155,6 +4159,9 @@ QemuOptsList qemu_chardev_opts = { .name = "tls-creds", .type = QEMU_OPT_STRING, },{ + .name = "tls-acl", + .type = QEMU_OPT_STRING, + },{ .name = "width", .type = QEMU_OPT_NUMBER, },{ @@ -4398,6 +4405,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id, } } } + s->tls_acl = g_strdup(sock->tls_acl); qapi_copy_SocketAddress(&s->addr, sock->addr); @@ -4461,6 +4469,7 @@ static CharDriverState *qmp_chardev_open_socket(const char *id, if (s->tls_creds) { object_unref(OBJECT(s->tls_creds)); } + g_free(s->tls_acl); g_free(s); qemu_chr_free_common(chr); return NULL;