From nobody Tue Feb 10 00:22:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1529080095383642.0431808387125; Fri, 15 Jun 2018 09:28:15 -0700 (PDT) Received: from localhost ([::1]:48011 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTraA-0005GF-Es for importer@patchew.org; Fri, 15 Jun 2018 12:28:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58838) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fTr0R-0008Vz-7t for qemu-devel@nongnu.org; Fri, 15 Jun 2018 11:51:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fTr0P-0006bJ-2x for qemu-devel@nongnu.org; Fri, 15 Jun 2018 11:51:19 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:49074 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fTr0M-0006Xk-9P; Fri, 15 Jun 2018 11:51:14 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C95EAFFB5E; Fri, 15 Jun 2018 15:51:13 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.42.22.189]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5351B10FD2A6; Fri, 15 Jun 2018 15:51:12 +0000 (UTC) From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: qemu-devel@nongnu.org Date: Fri, 15 Jun 2018 16:50:59 +0100 Message-Id: <20180615155103.11924-3-berrange@redhat.com> In-Reply-To: <20180615155103.11924-1-berrange@redhat.com> References: <20180615155103.11924-1-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 15 Jun 2018 15:51:13 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Fri, 15 Jun 2018 15:51:13 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'berrange@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/6] nbd: allow authorization with nbd-server-start QMP command 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: Kevin Wolf , qemu-block@nongnu.org, Juan Quintela , Markus Armbruster , Max Reitz , Gerd Hoffmann , Paolo Bonzini , =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" As with the previous patch to qemu-nbd, the nbd-server-start QMP command also needs to be able to specify authorization 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': 'authz0', 'parameters': { 'policy': 'deny', 'rules': [ { 'match': '*CN=3Dfred', 'policy': 'allow' } ] } } } They can then reference this in the new 'tls-authz' 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-authz': 'authz0' } } Signed-off-by: Daniel P. Berrange --- blockdev-nbd.c | 14 +++++++++++--- hmp.c | 2 +- include/block/nbd.h | 2 +- qapi/block.json | 4 +++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/blockdev-nbd.c b/blockdev-nbd.c index 65a84739ed..1ef2989118 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -23,6 +23,7 @@ typedef struct NBDServerData { QIONetListener *listener; QCryptoTLSCreds *tlscreds; + char *tlsauthz; } NBDServerData; =20 static NBDServerData *nbd_server; @@ -37,7 +38,8 @@ static void nbd_accept(QIONetListener *listener, QIOChann= elSocket *cioc, { qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); nbd_client_new(NULL, cioc, - nbd_server->tlscreds, NULL, + nbd_server->tlscreds, + nbd_server->tlsauthz, nbd_blockdev_client_closed); } =20 @@ -53,6 +55,7 @@ static void nbd_server_free(NBDServerData *server) if (server->tlscreds) { object_unref(OBJECT(server->tlscreds)); } + g_free(server->tlsauthz); =20 g_free(server); } @@ -88,7 +91,7 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id,= Error **errp) =20 =20 void nbd_server_start(SocketAddress *addr, const char *tls_creds, - Error **errp) + const char *tls_authz, Error **errp) { if (nbd_server) { error_setg(errp, "NBD server already running"); @@ -118,6 +121,10 @@ void nbd_server_start(SocketAddress *addr, const char = *tls_creds, } } =20 + if (tls_authz) { + nbd_server->tlsauthz =3D g_strdup(tls_authz); + } + qio_net_listener_set_client_func(nbd_server->listener, nbd_accept, NULL, @@ -132,11 +139,12 @@ void nbd_server_start(SocketAddress *addr, const char= *tls_creds, =20 void qmp_nbd_server_start(SocketAddressLegacy *addr, bool has_tls_creds, const char *tls_creds, + bool has_tls_authz, const char *tls_authz, Error **errp) { SocketAddress *addr_flat =3D socket_address_flatten(addr); =20 - nbd_server_start(addr_flat, tls_creds, errp); + nbd_server_start(addr_flat, tls_creds, tls_authz, errp); qapi_free_SocketAddress(addr_flat); } =20 diff --git a/hmp.c b/hmp.c index ef93f4878b..74e18db103 100644 --- a/hmp.c +++ b/hmp.c @@ -2214,7 +2214,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *= qdict) goto exit; } =20 - nbd_server_start(addr, NULL, &local_err); + nbd_server_start(addr, NULL, NULL, &local_err); qapi_free_SocketAddress(addr); if (local_err !=3D NULL) { goto exit; diff --git a/include/block/nbd.h b/include/block/nbd.h index 80ea9d240c..8a8ae8c3a7 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -313,7 +313,7 @@ void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); =20 void nbd_server_start(SocketAddress *addr, const char *tls_creds, - Error **errp); + const char *tls_authz, Error **errp); =20 =20 /* nbd_read diff --git a/qapi/block.json b/qapi/block.json index c694524002..8c7cc9b798 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -197,6 +197,7 @@ # # @addr: Address on which to listen. # @tls-creds: (optional) ID of the TLS credentials object. Since 2.6 +# @tls-authz: (optional) ID of the QAuthZ authorization object. Since 2.13 # # Returns: error if the server is already running. # @@ -204,7 +205,8 @@ ## { 'command': 'nbd-server-start', 'data': { 'addr': 'SocketAddressLegacy', - '*tls-creds': 'str'} } + '*tls-creds': 'str', + '*tls-authz': 'str'} } =20 ## # @nbd-server-add: --=20 2.17.0