From patchwork Thu Mar 10 18:59:54 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: 8559491 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BDC089FDE3 for ; Thu, 10 Mar 2016 19:04:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1B4A12034C for ; Thu, 10 Mar 2016 19:04:58 +0000 (UTC) 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.kernel.org (Postfix) with ESMTPS id 51DC62034B for ; Thu, 10 Mar 2016 19:04:57 +0000 (UTC) Received: from localhost ([::1]:50723 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae5tI-00033X-OR for patchwork-qemu-devel@patchwork.kernel.org; Thu, 10 Mar 2016 14:04:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae5p0-0004HN-Q1 for qemu-devel@nongnu.org; Thu, 10 Mar 2016 14:00:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ae5ow-0003W1-Bq for qemu-devel@nongnu.org; Thu, 10 Mar 2016 14:00:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41435) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ae5oo-0003Rg-UI; Thu, 10 Mar 2016 14:00:19 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 62B1196A2; Thu, 10 Mar 2016 19:00:17 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-4-172.ams2.redhat.com [10.36.4.172]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2AJ01Mw002433; Thu, 10 Mar 2016 14:00:15 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 10 Mar 2016 18:59:54 +0000 Message-Id: <1457636396-24983-8-git-send-email-berrange@redhat.com> In-Reply-To: <1457636396-24983-1-git-send-email-berrange@redhat.com> References: <1457635927-23045-1-git-send-email-berrange@redhat.com> <1457636396-24983-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-block@nongnu.org, Markus Armbruster , Max Reitz , Paolo Bonzini , =?UTF-8?q?Andreas=20F=C3=A4rber?= Subject: [Qemu-devel] [PATCH v3 08/10] nbd: allow an ACL to be set with nbd-server-start QMP command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP As with the previous patch to qemu-nbd, the nbd-server-start QMP command also needs to be able to specify an ACL when enabling TLS encryption. First the client must create a QAuthZ object instance using the 'object-add' command: { 'execute': 'object-add', 'arguments': { 'qom-type': 'authz-simple', 'id': 'tls0', 'parameters': { 'policy': 'deny', 'rules': [ { 'match': '*CN=fred', 'policy': 'allow' } ] } } } They can then reference this in the new 'tls-acl' parameter when executing the 'nbd-server-start' command. { 'execute': 'nbd-server-start', 'arguments': { 'addr': { 'type': 'inet', 'host': '127.0.0.1', 'port': '9000' }, 'tls-creds': 'tls0', 'tls-acl': 'tlsacl0' } } Signed-off-by: Daniel P. Berrange Reviewed-by: Eric Blake --- blockdev-nbd.c | 10 +++++++++- hmp.c | 2 +- qapi/block.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 12cae0e..ae5335e 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -24,6 +24,7 @@ typedef struct NBDServerData { QIOChannelSocket *listen_ioc; int watch; QCryptoTLSCreds *tlscreds; + char *tlsacl; } NBDServerData; static NBDServerData *nbd_server; @@ -45,7 +46,8 @@ static gboolean nbd_accept(QIOChannel *ioc, GIOCondition condition, } nbd_client_new(NULL, cioc, - nbd_server->tlscreds, NULL, + nbd_server->tlscreds, + nbd_server->tlsacl, nbd_client_put); object_unref(OBJECT(cioc)); return TRUE; @@ -65,6 +67,7 @@ static void nbd_server_free(NBDServerData *server) if (server->tlscreds) { object_unref(OBJECT(server->tlscreds)); } + g_free(server->tlsacl); g_free(server); } @@ -101,6 +104,7 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id, Error **errp) void qmp_nbd_server_start(SocketAddress *addr, bool has_tls_creds, const char *tls_creds, + bool has_tls_acl, const char *tls_acl, Error **errp) { if (nbd_server) { @@ -128,6 +132,10 @@ void qmp_nbd_server_start(SocketAddress *addr, } } + if (has_tls_acl) { + nbd_server->tlsacl = g_strdup(tls_acl); + } + nbd_server->watch = qio_channel_add_watch( QIO_CHANNEL(nbd_server->listen_ioc), G_IO_IN, diff --git a/hmp.c b/hmp.c index 7a98726..20703fd 100644 --- a/hmp.c +++ b/hmp.c @@ -1802,7 +1802,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict) goto exit; } - qmp_nbd_server_start(addr, false, NULL, &local_err); + qmp_nbd_server_start(addr, false, NULL, false, NULL, &local_err); qapi_free_SocketAddress(addr); if (local_err != NULL) { goto exit; diff --git a/qapi/block.json b/qapi/block.json index 58e6b30..6b209e1 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -147,6 +147,7 @@ # # @addr: Address on which to listen. # @tls-creds: (optional) ID of the TLS credentials object. Since 2.6 +# @tls-acl: (optional) ID of the QAuthZ authorization object. Since 2.6 # # Returns: error if the server is already running. # @@ -154,7 +155,8 @@ ## { 'command': 'nbd-server-start', 'data': { 'addr': 'SocketAddress', - '*tls-creds': 'str'} } + '*tls-creds': 'str', + '*tls-acl': 'str'} } ## # @nbd-server-add: diff --git a/qmp-commands.hx b/qmp-commands.hx index b629673..7a3fa26 100644 --- a/qmp-commands.hx +++ b/qmp-commands.hx @@ -3859,7 +3859,7 @@ EQMP { .name = "nbd-server-start", - .args_type = "addr:q,tls-creds:s?", + .args_type = "addr:q,tls-creds:s?,tls-acl:s?", .mhandler.cmd_new = qmp_marshal_nbd_server_start, }, {