From patchwork Thu Jun 2 16:46:23 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: 9150925 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 3126F6074E for ; Thu, 2 Jun 2016 16:57:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 219AD2780C for ; Thu, 2 Jun 2016 16:57:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 168D928310; Thu, 2 Jun 2016 16:57:54 +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 93A142780C for ; Thu, 2 Jun 2016 16:57:53 +0000 (UTC) Received: from localhost ([::1]:49175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8VwO-000617-N1 for patchwork-qemu-devel@patchwork.kernel.org; Thu, 02 Jun 2016 12:57:52 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38647) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vlw-0004r5-PR for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8Vlu-0003Zu-I9 for qemu-devel@nongnu.org; Thu, 02 Jun 2016 12:47:03 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56382) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8Vlg-0003QC-Ht; Thu, 02 Jun 2016 12:46:48 -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 1F0D546212; Thu, 2 Jun 2016 16:46:48 +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 u52GkVdP023498; Thu, 2 Jun 2016 12:46:45 -0400 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 2 Jun 2016 17:46:23 +0100 Message-Id: <1464885987-4039-8-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.29]); Thu, 02 Jun 2016 16:46:48 +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 07/11] qemu-nbd: 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 the NBD 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 NBD server. This is still a fairly weak bar. This adds a '--tls-acl ACL-ID' option to the qemu-nbd command 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 NBD 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-nbd -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 \ -tls-creds tls0 \ -tls-acl acl0 ....other qemu-nbd args... Signed-off-by: Daniel P. Berrange --- qemu-nbd.c | 13 ++++++++++++- qemu-nbd.texi | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 6554f0a..2450214 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -46,6 +46,7 @@ #define QEMU_NBD_OPT_OBJECT 260 #define QEMU_NBD_OPT_TLSCREDS 261 #define QEMU_NBD_OPT_IMAGE_OPTS 262 +#define QEMU_NBD_OPT_TLSACL 263 #define MBR_SIZE 512 @@ -61,6 +62,7 @@ static int nb_fds; static QIOChannelSocket *server_ioc; static int server_watch = -1; static QCryptoTLSCreds *tlscreds; +static const char *tlsacl; static void usage(const char *name) { @@ -354,7 +356,7 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition cond, gpointer opaque) nb_fds++; nbd_update_server_watch(); nbd_client_new(newproto ? NULL : exp, cioc, - tlscreds, NULL, nbd_client_closed); + tlscreds, tlsacl, nbd_client_closed); object_unref(OBJECT(cioc)); return TRUE; @@ -498,6 +500,7 @@ int main(int argc, char **argv) { "export-name", required_argument, NULL, 'x' }, { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS }, { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, + { "tls-acl", no_argument, NULL, QEMU_NBD_OPT_TLSACL }, { NULL, 0, NULL, 0 } }; int ch; @@ -703,6 +706,9 @@ int main(int argc, char **argv) case QEMU_NBD_OPT_IMAGE_OPTS: imageOpts = true; break; + case QEMU_NBD_OPT_TLSACL: + tlsacl = optarg; + break; } } @@ -738,6 +744,11 @@ int main(int argc, char **argv) error_get_pretty(local_err)); exit(EXIT_FAILURE); } + } else { + if (tlsacl) { + error_report("--tls-acl is not permitted without --tls-creds"); + exit(EXIT_FAILURE); + } } if (disconnect) { diff --git a/qemu-nbd.texi b/qemu-nbd.texi index 9f23343..69f32cb 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -86,6 +86,10 @@ the new style NBD protocol negotiation Enable mandatory TLS encryption for the server by setting the ID of the TLS credentials object previously created with the --object option. +@item --tls-acl=ID +Specify the ID of a qauthz object previously created with the +--object option. This will be used to authorize users who +connect against their x509 distinguish name. @item -v, --verbose Display extra debugging information @item -h, --help