From nobody Sun Oct 5 19:25:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552067070253458.1448149830512; Fri, 8 Mar 2019 09:44:30 -0800 (PST) Received: from localhost ([127.0.0.1]:47642 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JXk-0004nu-5H for importer@patchew.org; Fri, 08 Mar 2019 12:44:24 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41186) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JTh-0001hV-Ds for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2JTa-0002Pj-K6 for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:13 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2JTW-0002L4-L3; Fri, 08 Mar 2019 12:40:02 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D7B0D309E97C; Fri, 8 Mar 2019 17:40:01 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1AD165D704; Fri, 8 Mar 2019 17:40:01 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 11:39:55 -0600 Message-Id: <20190308173958.20618-2-eblake@redhat.com> In-Reply-To: <20190308173958.20618-1-eblake@redhat.com> References: <20190308173958.20618-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Fri, 08 Mar 2019 17:40:01 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 1/4] qemu-nbd: add support for authorization of 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: Kevin Wolf , Max Reitz , "open list:Network Block Dev..." , Juan Quintela Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: "Daniel P. Berrange" 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 low bar to cross. This adds a '--tls-authz OBJECT-ID' option to the qemu-nbd command which takes the ID of a previously added 'QAuthZ' object instance. This will be used to validate the client's x509 distinguished name. Clients failing the authorization check will not be permitted to use the NBD server. For example to setup authorization that only allows connection from a client whose x509 certificate distinguished name is CN=3Dlaptop.example.com,O=3DExample Org,L=3DLondon,ST=3DLondon,C=3DGB escape the commas in the name and use: qemu-nbd --object tls-creds-x509,id=3Dtls0,dir=3D/home/berrange/qemutls,\ endpoint=3Dserver,verify-peer=3Dyes \ --object 'authz-simple,id=3Dauth0,identity=3DCN=3Dlaptop.example= .com,,\ O=3DExample Org,,L=3DLondon,,ST=3DLondon,,C=3DGB' \ --tls-creds tls0 \ --tls-authz authz0 \ ....other qemu-nbd args... NB: a real shell command line would not have leading whitespace after the line continuation, it is just included here for clarity. Reviewed-by: Juan Quintela Signed-off-by: Daniel P. Berrange Message-Id: <20190227162035.18543-2-berrange@redhat.com> Reviewed-by: Eric Blake [eblake: split long line in --help text, tweak 233 to show that whitespace after ,, in identity=3D portion is actually okay] Signed-off-by: Eric Blake --- qemu-nbd.texi | 11 +++++++++-- include/block/nbd.h | 2 +- nbd/server.c | 10 +++++----- qemu-nbd.c | 19 ++++++++++++++++++- tests/qemu-iotests/233 | 32 +++++++++++++++++++++++++++++--- tests/qemu-iotests/233.out | 11 +++++++++++ 6 files changed, 73 insertions(+), 12 deletions(-) diff --git a/qemu-nbd.texi b/qemu-nbd.texi index d0c51828149..de342c76b87 100644 --- a/qemu-nbd.texi +++ b/qemu-nbd.texi @@ -117,6 +117,10 @@ option; or provide the credentials needed for connecti= ng as a client in list mode. @item --fork Fork off the server process and exit the parent once the server is running. +@item --tls-authz=3DID +Specify the ID of a qauthz object previously created with the +--object option. This will be used to authorize connecting users +against their x509 distinguished name. @item -v, --verbose Display extra debugging information. @item -h, --help @@ -142,13 +146,16 @@ qemu-nbd -f qcow2 file.qcow2 @end example Start a long-running server listening with encryption on port 10810, -and require clients to have a correct X.509 certificate to connect to +and whitelist clients with a specific X.509 certificate to connect to a 1 megabyte subset of a raw file, using the export name 'subset': @example qemu-nbd \ --object tls-creds-x509,id=3Dtls0,endpoint=3Dserver,dir=3D/path/to/qemut= ls \ - --tls-creds tls0 -t -x subset -p 10810 \ + --object 'authz-simple,id=3Dauth0,identity=3DCN=3Dlaptop.example.com,,\ + O=3DExample Org,,L=3DLondon,,ST=3DLondon,,C=3DGB' \ + --tls-creds tls0 --tls-authz auth0 \ + -t -x subset -p 10810 \ --image-opts driver=3Draw,offset=3D1M,size=3D1M,file.driver=3Dfile,file.= filename=3Dfile.raw @end example diff --git a/include/block/nbd.h b/include/block/nbd.h index c6ef1ef42e8..b742ec4a89b 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -326,7 +326,7 @@ void nbd_export_close_all(void); void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, - const char *tlsaclname, + const char *tlsauthz, void (*close_fn)(NBDClient *, bool)); void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); diff --git a/nbd/server.c b/nbd/server.c index 0910d09a6d4..8ddfd3e3198 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -111,7 +111,7 @@ struct NBDClient { NBDExport *exp; QCryptoTLSCreds *tlscreds; - char *tlsaclname; + char *tlsauthz; QIOChannelSocket *sioc; /* The underlying data channel */ QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) = */ @@ -686,7 +686,7 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDCli= ent *client, tioc =3D qio_channel_tls_new_server(ioc, client->tlscreds, - client->tlsaclname, + client->tlsauthz, errp); if (!tioc) { return NULL; @@ -1348,7 +1348,7 @@ void nbd_client_put(NBDClient *client) if (client->tlscreds) { object_unref(OBJECT(client->tlscreds)); } - g_free(client->tlsaclname); + g_free(client->tlsauthz); if (client->exp) { QTAILQ_REMOVE(&client->exp->clients, client, next); nbd_export_put(client->exp); @@ -2425,7 +2425,7 @@ static coroutine_fn void nbd_co_client_start(void *op= aque) */ void nbd_client_new(QIOChannelSocket *sioc, QCryptoTLSCreds *tlscreds, - const char *tlsaclname, + const char *tlsauthz, void (*close_fn)(NBDClient *, bool)) { NBDClient *client; @@ -2437,7 +2437,7 @@ void nbd_client_new(QIOChannelSocket *sioc, if (tlscreds) { object_ref(OBJECT(client->tlscreds)); } - client->tlsaclname =3D g_strdup(tlsaclname); + client->tlsauthz =3D g_strdup(tlsauthz); client->sioc =3D sioc; object_ref(OBJECT(client->sioc)); client->ioc =3D QIO_CHANNEL(sioc); diff --git a/qemu-nbd.c b/qemu-nbd.c index 00c07fd27ea..941ba729c2f 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -58,6 +58,7 @@ #define QEMU_NBD_OPT_TLSCREDS 261 #define QEMU_NBD_OPT_IMAGE_OPTS 262 #define QEMU_NBD_OPT_FORK 263 +#define QEMU_NBD_OPT_TLSAUTHZ 264 #define MBR_SIZE 512 @@ -71,6 +72,7 @@ static int shared =3D 1; static int nb_fds; static QIONetListener *server; static QCryptoTLSCreds *tlscreds; +static const char *tlsauthz; static void usage(const char *name) { @@ -103,6 +105,8 @@ static void usage(const char *name) " --object type,id=3DID,... define an object such as 'secret' for provi= ding\n" " passwords and/or encryption keys\n" " --tls-creds=3DID use id of an earlier --object to provide TL= S\n" +" --tls-authz=3DID use id of an earlier --object to provide\n" +" authorization\n" " -T, --trace [[enable=3D]][,events=3D][,file=3D]\n" " specify tracing options\n" " --fork fork off the server process and exit the pare= nt\n" @@ -452,7 +456,7 @@ static void nbd_accept(QIONetListener *listener, QIOCha= nnelSocket *cioc, nb_fds++; nbd_update_server_watch(); - nbd_client_new(cioc, tlscreds, NULL, nbd_client_closed); + nbd_client_new(cioc, tlscreds, tlsauthz, nbd_client_closed); } static void nbd_update_server_watch(void) @@ -643,6 +647,7 @@ int main(int argc, char **argv) { "export-name", required_argument, NULL, 'x' }, { "description", required_argument, NULL, 'D' }, { "tls-creds", required_argument, NULL, QEMU_NBD_OPT_TLSCREDS }, + { "tls-authz", required_argument, NULL, QEMU_NBD_OPT_TLSAUTHZ }, { "image-opts", no_argument, NULL, QEMU_NBD_OPT_IMAGE_OPTS }, { "trace", required_argument, NULL, 'T' }, { "fork", no_argument, NULL, QEMU_NBD_OPT_FORK }, @@ -862,6 +867,9 @@ int main(int argc, char **argv) g_free(trace_file); trace_file =3D trace_opt_parse(optarg); break; + case QEMU_NBD_OPT_TLSAUTHZ: + tlsauthz =3D optarg; + break; case QEMU_NBD_OPT_FORK: fork_process =3D true; break; @@ -934,12 +942,21 @@ int main(int argc, char **argv) error_report("TLS is not supported with a host device"); exit(EXIT_FAILURE); } + if (tlsauthz && list) { + error_report("TLS authorization is incompatible with export li= st"); + exit(EXIT_FAILURE); + } tlscreds =3D nbd_get_tls_creds(tlscredsid, list, &local_err); if (local_err) { error_report("Failed to get TLS creds %s", error_get_pretty(local_err)); exit(EXIT_FAILURE); } + } else { + if (tlsauthz) { + error_report("--tls-authz is not permitted without --tls-creds= "); + exit(EXIT_FAILURE); + } } if (list) { diff --git a/tests/qemu-iotests/233 b/tests/qemu-iotests/233 index adb742fafb0..5e5fe1e8cdb 100755 --- a/tests/qemu-iotests/233 +++ b/tests/qemu-iotests/233 @@ -61,6 +61,7 @@ tls_x509_create_root_ca "ca2" tls_x509_create_server "ca1" "server1" tls_x509_create_client "ca1" "client1" tls_x509_create_client "ca2" "client2" +tls_x509_create_client "ca1" "client3" echo echo "=3D=3D preparing image =3D=3D" @@ -93,11 +94,15 @@ $QEMU_NBD_PROG -L -b $nbd_tcp_addr -p $nbd_tcp_port echo echo "=3D=3D check TLS works =3D=3D" -obj=3Dtls-creds-x509,dir=3D${tls_dir}/client1,endpoint=3Dclient,id=3Dtls0 -$QEMU_IMG info --image-opts --object $obj \ +obj1=3Dtls-creds-x509,dir=3D${tls_dir}/client1,endpoint=3Dclient,id=3Dtls0 +obj2=3Dtls-creds-x509,dir=3D${tls_dir}/client3,endpoint=3Dclient,id=3Dtls0 +$QEMU_IMG info --image-opts --object $obj1 \ driver=3Dnbd,host=3D$nbd_tcp_addr,port=3D$nbd_tcp_port,tls-creds=3Dtls= 0 \ 2>&1 | sed "s/$nbd_tcp_port/PORT/g" -$QEMU_NBD_PROG -L -b $nbd_tcp_addr -p $nbd_tcp_port --object $obj \ +$QEMU_IMG info --image-opts --object $obj2 \ + driver=3Dnbd,host=3D$nbd_tcp_addr,port=3D$nbd_tcp_port,tls-creds=3Dtls= 0 \ + 2>&1 | sed "s/$nbd_tcp_port/PORT/g" +$QEMU_NBD_PROG -L -b $nbd_tcp_addr -p $nbd_tcp_port --object $obj1 \ --tls-creds=3Dtls0 echo @@ -119,6 +124,27 @@ $QEMU_IO -c 'r -P 0x11 1m 1m' -c 'w -P 0x22 1m 1m' --i= mage-opts \ $QEMU_IO -f $IMGFMT -r -U -c 'r -P 0x22 1m 1m' "$TEST_IMG" | _filter_qemu_= io +echo +echo "=3D=3D check TLS with authorization =3D=3D" + +nbd_server_stop + +nbd_server_start_tcp_socket \ + --object tls-creds-x509,dir=3D${tls_dir}/server1,endpoint=3Dserver,id= =3Dtls0,verify-peer=3Dyes \ + --object "authz-simple,id=3Dauthz0,identity=3DCN=3Dlocalhost,, \ + O=3DCthulu Dark Lord Enterprises client1,,L=3DR'lyeh,,C=3DSouth Paci= fic" \ + --tls-authz authz0 \ + --tls-creds tls0 \ + -f $IMGFMT "$TEST_IMG" 2>> "$TEST_DIR/server.log" + +$QEMU_IMG info --image-opts \ + --object tls-creds-x509,dir=3D${tls_dir}/client1,endpoint=3Dclient,id= =3Dtls0 \ + driver=3Dnbd,host=3D$nbd_tcp_addr,port=3D$nbd_tcp_port,tls-creds=3Dtls0 + +$QEMU_IMG info --image-opts \ + --object tls-creds-x509,dir=3D${tls_dir}/client3,endpoint=3Dclient,id= =3Dtls0 \ + driver=3Dnbd,host=3D$nbd_tcp_addr,port=3D$nbd_tcp_port,tls-creds=3Dtls0 + echo echo "=3D=3D final server log =3D=3D" cat "$TEST_DIR/server.log" diff --git a/tests/qemu-iotests/233.out b/tests/qemu-iotests/233.out index 6d45f3b2304..5acbc13b54a 100644 --- a/tests/qemu-iotests/233.out +++ b/tests/qemu-iotests/233.out @@ -6,6 +6,7 @@ Generating a self signed certificate... Generating a signed certificate... Generating a signed certificate... Generating a signed certificate... +Generating a signed certificate... =3D=3D preparing image =3D=3D Formatting 'TEST_DIR/t.IMGFMT', fmt=3DIMGFMT size=3D67108864 @@ -29,6 +30,10 @@ image: nbd://127.0.0.1:PORT file format: nbd virtual size: 64M (67108864 bytes) disk size: unavailable +image: nbd://127.0.0.1:PORT +file format: nbd +virtual size: 64M (67108864 bytes) +disk size: unavailable exports available: 1 export: '' size: 67108864 @@ -51,7 +56,13 @@ wrote 1048576/1048576 bytes at offset 1048576 read 1048576/1048576 bytes at offset 1048576 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +=3D=3D check TLS with authorization =3D=3D +qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3D10809,tls-c= reds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: So= ftware caused connection abort +qemu-img: Could not open 'driver=3Dnbd,host=3D127.0.0.1,port=3D10809,tls-c= reds=3Dtls0': Failed to read option reply: Cannot read from TLS channel: So= ftware caused connection abort + =3D=3D final server log =3D=3D qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. qemu-nbd: option negotiation failed: Verify failed: No certificate was fou= nd. +qemu-nbd: option negotiation failed: TLS x509 authz check for CN=3Dlocalho= st,O=3DCthulhu Dark Lord Enterprises client1,L=3DR'lyeh,C=3DSouth Pacific i= s denied +qemu-nbd: option negotiation failed: TLS x509 authz check for CN=3Dlocalho= st,O=3DCthulhu Dark Lord Enterprises client3,L=3DR'lyeh,C=3DSouth Pacific i= s denied *** done --=20 2.20.1 From nobody Sun Oct 5 19:25:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552066999055882.9866224513563; Fri, 8 Mar 2019 09:43:19 -0800 (PST) Received: from localhost ([127.0.0.1]:47628 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JWd-0003rx-0i for importer@patchew.org; Fri, 08 Mar 2019 12:43:15 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JTc-0001c7-ES for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2JTb-0002QM-Gz for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44748) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2JTZ-0002Md-2m; Fri, 08 Mar 2019 12:40:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5A7E23003D2A; Fri, 8 Mar 2019 17:40:04 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 083215D704; Fri, 8 Mar 2019 17:40:01 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 11:39:56 -0600 Message-Id: <20190308173958.20618-3-eblake@redhat.com> In-Reply-To: <20190308173958.20618-1-eblake@redhat.com> References: <20190308173958.20618-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Fri, 08 Mar 2019 17:40:04 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 2/4] 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 , "open list:Network Block Dev..." , Juan Quintela , Markus Armbruster , Max Reitz , "Dr. David Alan Gilbert" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" 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-list', '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' } } Reviewed-by: Eric Blake Reviewed-by: Juan Quintela Signed-off-by: Daniel P. Berrange Message-Id: <20190227162035.18543-3-berrange@redhat.com> Signed-off-by: Eric Blake --- qapi/block.json | 8 +++++++- include/block/nbd.h | 2 +- blockdev-nbd.c | 11 ++++++++--- hmp.c | 2 +- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/qapi/block.json b/qapi/block.json index 5a79d639e8c..79623088e72 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -225,6 +225,11 @@ # # @addr: Address on which to listen. # @tls-creds: (optional) ID of the TLS credentials object. Since 2.6 +# @tls-authz: ID of the QAuthZ authorization object used to validate +# the client's x509 distinguished name. This object is +# is only resolved at time of use, so can be deleted and +# recreated on the fly while the NBD server is active. +# If missing, it will default to denying access (since 4.0). # # Returns: error if the server is already running. # @@ -232,7 +237,8 @@ ## { 'command': 'nbd-server-start', 'data': { 'addr': 'SocketAddressLegacy', - '*tls-creds': 'str'} } + '*tls-creds': 'str', + '*tls-authz': 'str'} } ## # @nbd-server-add: diff --git a/include/block/nbd.h b/include/block/nbd.h index b742ec4a89b..6d05983a55f 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -332,7 +332,7 @@ void nbd_client_get(NBDClient *client); void nbd_client_put(NBDClient *client); void nbd_server_start(SocketAddress *addr, const char *tls_creds, - Error **errp); + const char *tls_authz, Error **errp); /* nbd_read * Reads @size bytes from @ioc. Returns 0 on success. diff --git a/blockdev-nbd.c b/blockdev-nbd.c index d73ac1b026a..66eebab3187 100644 --- a/blockdev-nbd.c +++ b/blockdev-nbd.c @@ -23,6 +23,7 @@ typedef struct NBDServerData { QIONetListener *listener; QCryptoTLSCreds *tlscreds; + char *tlsauthz; } NBDServerData; static NBDServerData *nbd_server; @@ -36,7 +37,7 @@ static void nbd_accept(QIONetListener *listener, QIOChann= elSocket *cioc, gpointer opaque) { qio_channel_set_name(QIO_CHANNEL(cioc), "nbd-server"); - nbd_client_new(cioc, nbd_server->tlscreds, NULL, + nbd_client_new(cioc, nbd_server->tlscreds, nbd_server->tlsauthz, nbd_blockdev_client_closed); } @@ -52,6 +53,7 @@ static void nbd_server_free(NBDServerData *server) if (server->tlscreds) { object_unref(OBJECT(server->tlscreds)); } + g_free(server->tlsauthz); g_free(server); } @@ -87,7 +89,7 @@ static QCryptoTLSCreds *nbd_get_tls_creds(const char *id,= Error **errp) 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"); @@ -117,6 +119,8 @@ void nbd_server_start(SocketAddress *addr, const char *= tls_creds, } } + nbd_server->tlsauthz =3D g_strdup(tls_authz); + qio_net_listener_set_client_func(nbd_server->listener, nbd_accept, NULL, @@ -131,11 +135,12 @@ void nbd_server_start(SocketAddress *addr, const char= *tls_creds, 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); - nbd_server_start(addr_flat, tls_creds, errp); + nbd_server_start(addr_flat, tls_creds, tls_authz, errp); qapi_free_SocketAddress(addr_flat); } diff --git a/hmp.c b/hmp.c index c2ad3f8251e..4a702d5b977 100644 --- a/hmp.c +++ b/hmp.c @@ -2373,7 +2373,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *= qdict) goto exit; } - 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; --=20 2.20.1 From nobody Sun Oct 5 19:25:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 155206691479364.00886514762703; Fri, 8 Mar 2019 09:41:54 -0800 (PST) Received: from localhost ([127.0.0.1]:47610 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JVE-0002cx-Ku for importer@patchew.org; Fri, 08 Mar 2019 12:41:48 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JTa-0001aO-HJ for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2JTZ-0002P5-Tu for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:06 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42252) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2JTZ-0002N6-Mt for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:05 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F20E730EBE76 for ; Fri, 8 Mar 2019 17:40:04 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 80A455D786; Fri, 8 Mar 2019 17:40:04 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 11:39:57 -0600 Message-Id: <20190308173958.20618-4-eblake@redhat.com> In-Reply-To: <20190308173958.20618-1-eblake@redhat.com> References: <20190308173958.20618-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Fri, 08 Mar 2019 17:40:05 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 3/4] nbd: fix outdated qapi docs syntax for tls-creds 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: Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" From: Daniel P. Berrang=C3=A9 Signed-off-by: Daniel P. Berrang=C3=A9 Message-Id: <20190227162035.18543-4-berrange@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Eric Blake --- qapi/block.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qapi/block.json b/qapi/block.json index 79623088e72..145c268bb64 100644 --- a/qapi/block.json +++ b/qapi/block.json @@ -224,7 +224,7 @@ # QEMU instance could refer to them as "nbd:HOST:PORT:exportname=3DNAME". # # @addr: Address on which to listen. -# @tls-creds: (optional) ID of the TLS credentials object. Since 2.6 +# @tls-creds: ID of the TLS credentials object (since 2.6). # @tls-authz: ID of the QAuthZ authorization object used to validate # the client's x509 distinguished name. This object is # is only resolved at time of use, so can be deleted and --=20 2.20.1 From nobody Sun Oct 5 19:25:05 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552067133039865.9235843306545; Fri, 8 Mar 2019 09:45:33 -0800 (PST) Received: from localhost ([127.0.0.1]:47666 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JYj-0005j4-2X for importer@patchew.org; Fri, 08 Mar 2019 12:45:25 -0500 Received: from eggs.gnu.org ([209.51.188.92]:41172) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h2JTf-0001fA-67 for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:12 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h2JTe-0002S8-3Z for qemu-devel@nongnu.org; Fri, 08 Mar 2019 12:40:10 -0500 Received: from mx1.redhat.com ([209.132.183.28]:43244) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h2JTb-0002Q2-JD; Fri, 08 Mar 2019 12:40:07 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE5B97E42E; Fri, 8 Mar 2019 17:40:06 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E4AD5D704; Fri, 8 Mar 2019 17:40:05 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 8 Mar 2019 11:39:58 -0600 Message-Id: <20190308173958.20618-5-eblake@redhat.com> In-Reply-To: <20190308173958.20618-1-eblake@redhat.com> References: <20190308173958.20618-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 08 Mar 2019 17:40:06 +0000 (UTC) Content-Transfer-Encoding: quoted-printable 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] [PULL 4/4] iotests: Wait for qemu to end in 223 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 , Alberto Garcia , "open list:Block layer core" , Max Reitz Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" When iotest 223 was first written, it didn't matter if we waited for the qemu process to clean up. But with the introduction of a later qemu-nbd process trying to reuse the same file, there is a race where even though the asynchronous qemu process has responded to "quit", it has not yet had time to unlock the file and exit, resulting in: -[{ "start": 0, "length": 65536, "depth": 0, "zero": false, "data": false}, -{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": tr= ue}, -{ "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": = false}] +qemu-nbd: Failed to blk_new_open 'tests/qemu-iotests/scratch/t.qcow2': Fai= led to get shared "write" lock +Is another process using the image [tests/qemu-iotests/scratch/t.qcow2]? +qemu-img: Could not open 'driver=3Dnbd,server.type=3Dunix,server.path=3Dte= sts/qemu-iotests/scratch/qemu-nbd.sock,x-dirty-bitmap=3Dqemu:dirty-bitmap:b= ': Failed to connect socket tests/qemu-iotests/scratch/qemu-nbd.sock: Conne= ction refused +./common.nbd: line 33: kill: (11122) - No such process Fixes: ddd09448 Reported-by: Alberto Garcia Signed-off-by: Eric Blake Message-Id: <20190305182908.13557-1-eblake@redhat.com> Tested-by: Alberto Garcia Reviewed-by: Kevin Wolf --- tests/qemu-iotests/223 | 1 + tests/qemu-iotests/223.out | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223 index f120a016460..c0a4f9c14b7 100755 --- a/tests/qemu-iotests/223 +++ b/tests/qemu-iotests/223 @@ -179,6 +179,7 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-rem= ove", _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return" _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return" +wait=3Dyes _cleanup_qemu echo echo "=3D=3D=3D Use qemu-nbd as server =3D=3D=3D" diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out index 6476b77ba20..95c40a17ad7 100644 --- a/tests/qemu-iotests/223.out +++ b/tests/qemu-iotests/223.out @@ -89,6 +89,7 @@ read 2097152/2097152 bytes at offset 2097152 {"return": {}} {"error": {"class": "GenericError", "desc": "NBD server not running"}} {"return": {}} +{"timestamp": {"seconds": TIMESTAMP, "microseconds": TIMESTAMP}, "event"= : "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}} =3D=3D=3D Use qemu-nbd as server =3D=3D=3D --=20 2.20.1