qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Eric Blake <eblake@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Kevin Wolf <kwolf@redhat.com>, Max Reitz <mreitz@redhat.com>
Subject: Re: [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode
Date: Mon, 19 Nov 2018 10:36:43 +0000	[thread overview]
Message-ID: <20181119103643.GG19532@redhat.com> (raw)
In-Reply-To: <5508fd21-b2e6-26d3-78f0-9ea89db10ccc@redhat.com>

On Fri, Nov 16, 2018 at 11:20:26AM -0600, Eric Blake wrote:
> On 11/16/18 9:53 AM, Daniel P. Berrangé wrote:
> > Add tests that validate it is possible to connect to an NBD server
> > running TLS mode. Also test mis-matched TLS vs non-TLS connections
> > correctly fail.
> > ---
> >   tests/qemu-iotests/233        | 99 +++++++++++++++++++++++++++++++++++
> >   tests/qemu-iotests/233.out    | 33 ++++++++++++
> >   tests/qemu-iotests/common.nbd | 47 +++++++++++++++++
> >   tests/qemu-iotests/group      |  1 +
> >   4 files changed, 180 insertions(+)
> >   create mode 100755 tests/qemu-iotests/233
> >   create mode 100644 tests/qemu-iotests/233.out
> 
> Adding tests is non-invasive, so I have no objection to taking the entire
> series in 3.1.  Do you want me to touch up the nits I found earlier, or
> should I wait for a v2?

If you're happy to touch it up, that's fine with me.

> > +
> > +$QEMU_IMG info nbd://localhost:$nbd_tcp_port
> > +
> > +echo
> > +echo "== check TLS works =="
> > +$QEMU_IMG info --image-opts \
> > +    --object tls-creds-x509,dir=${tls_dir}/client1,endpoint=client,id=tls0 \
> > +    driver=nbd,host=$nbd_tcp_addr,port=$nbd_tcp_port,tls-creds=tls0
> 
> Is it also worth reading or even writing, to ensure that more than just the
> handshake is working?

I was mostly interested in the handshake/cert stuff, but yes, we could
do some qemu-io testing too.

> > +
> > +echo
> > +echo "== check TLS with different CA fails =="
> > +$QEMU_IMG info --image-opts \
> > +    --object tls-creds-x509,dir=${tls_dir}/client2,endpoint=client,id=tls0 \
> > +    driver=nbd,host=$nbd_tcp_addr,port=$nbd_tcp_port,tls-creds=tls0
> > +
> > +# success, all done
> 
> > +== check TLS client to plain server fails ==
> > +option negotiation failed: read failed: Unexpected end-of-file before all bytes were read
> 
> Annoying message; I wonder if we can clean that up. But not this patch's
> problem.

This is a result of using the 'socat' check to poll for qemu-nbd
readiness. When socat finally succeeds in connecting & then drops
the conenction, qemu-nbd prints this message.  Personally I don't
think we need remove it unless we want to make qemu-nbd silently
by default when clients do unusual things.

> > +qemu-img: Could not open 'driver=nbd,host=127.0.0.1,port=10809,tls-creds=tls0': Denied by server for option 5 (starttls)
> > +server reported: TLS not configured
> 
> This 2-line message is better (and as such, explains why I think the message
> about early EOF should be silenced in this case).
> 
> > +
> > +== check plain client to TLS server fails ==
> > +option negotiation failed: read failed: Unexpected end-of-file before all bytes were read
> > +qemu-img: Could not open 'nbd://localhost:10809': TLS negotiation required before option 8 (structured reply)
> > +server reported: Option 0x8 not permitted before TLS
> 
> Same story about a redundant message.

Again this was the socat polling.

> 
> > +write failed (error message): Unable to write to socket: Broken pipe
> 
> Hmm - is this the client complaining that it can't send more to the server
> (that's a bug if the server hung up, since the protocol allows the client to
> change its mind and try TLS after all), or the server complaining that the
> client hung up abruptly without sending NBD_OPT_ABORT? Qemu as client either
> tries TLS right away, or knows that if the server requires TLS and the
> client has no TLS credentials then the client will never succeed, so the
> client gives up - but it SHOULD be giving up with NBD_OPT_ABORT rather than
> just disconnecting.  I'll have to play with that.  Doesn't impact your
> patch, but might spur a followup fix :)

I'm unclear if this message comes from the server or the client since
they are intermingled.


> > diff --git a/tests/qemu-iotests/common.nbd b/tests/qemu-iotests/common.nbd
> > index 61e9e90fee..0483ea7c55 100644
> > --- a/tests/qemu-iotests/common.nbd
> > +++ b/tests/qemu-iotests/common.nbd
> > @@ -20,6 +20,7 @@
> >   #
> >   nbd_unix_socket="${TEST_DIR}/qemu-nbd.sock"
> > +nbd_tcp_addr="127.0.0.1"
> 
> Should this be in your earlier patch that created common.nbd? Maybe not, as
> it doesn't get used until the functions you add here for tcp support. Still,
> I wonder if we should split the addition of tcp support separate from the
> new test.

Yeah, I wanted the earlier patch to be a plain refactor of existing
functionality, not adding anything new.

> >   nbd_pid_file="${TEST_DIR}/qemu-nbd.pid"
> >   function nbd_server_stop()
> > @@ -62,3 +63,49 @@ function nbd_server_start_unix_socket()
> >       $QEMU_NBD -v -t -k "$nbd_unix_socket" $@ &
> >       nbd_server_wait_for_unix_socket $!
> >   }
> > +
> > +function nbd_server_set_tcp_port()
> > +{
> > +    for port in `seq 10809 10909`
> > +    do
> > +	socat TCP:$nbd_tcp_addr:$port STDIO < /dev/null 1>/dev/null 2>&1
> 
> This is the first use of socat in iotests.  Might not be the most portable,
> but I don't know if I have better ideas. nbdkit.git/tests/test-ip.sh greps
> the output of 'ss -ltn' to locate free ports, but I don't know if ss is any
> better than socat.

'ss' is a Linux specific command IIUC since it is part of 'iproute',
while 'socat' is in fact available more or less everywhere:

  https://repology.org/metapackage/socat1/versions


> > +        if test $? != 0
> > +	then
> > +	    nbd_tcp_port=$port

Opps, a stray <tab> here

> > +            return
> > +        fi
> > +    done
> > +
> > +    echo "Cannot find free TCP port for nbd in range 10809-10909"
> > +    exit 1
> 
> Should we skip instead of fail in this case? Would we do well picking a
> larger port range?

Yes, we could simply skip. I figure 100 ports is fine, since tests are
normally run on a largely idle system.

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

  parent reply	other threads:[~2018-11-19 10:36 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-16 15:53 [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 1/6 for-3.1] nbd: fix whitespace in server error message Daniel P. Berrangé
2018-11-16 16:01   ` Eric Blake
2018-11-19 16:29     ` Philippe Mathieu-Daudé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 2/6 for-3.1] nbd: stop waiting for a NBD response with NBD_CMD_DISC Daniel P. Berrangé
2018-11-16 16:08   ` Eric Blake
2018-11-18  2:19   ` Eric Blake
2018-11-19 10:23     ` Daniel P. Berrangé
2018-11-19 14:24       ` Eric Blake
2018-11-19 13:47     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 3/6] tests: pull qemu-nbd iotest helpers into common.nbd file Daniel P. Berrangé
2018-11-16 16:11   ` Eric Blake
2018-11-16 21:41   ` Eric Blake
2018-11-16 21:43     ` Eric Blake
2018-11-19 10:24       ` Daniel P. Berrangé
2018-11-18  3:01   ` Eric Blake
2018-11-19 10:24     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 4/6] tests: check if qemu-nbd is still alive before waiting Daniel P. Berrangé
2018-11-16 16:24   ` Eric Blake
2018-11-19 10:26     ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 5/6] tests: add iotests helpers for dealing with TLS certificates Daniel P. Berrangé
2018-11-16 16:39   ` Eric Blake
2018-11-19 10:27     ` Daniel P. Berrangé
2018-11-19 11:04       ` Max Reitz
2018-11-19 14:27         ` Eric Blake
2018-11-19 14:32           ` Daniel P. Berrangé
2018-11-16 15:53 ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-16 17:20   ` Eric Blake
2018-11-17 21:31     ` Eric Blake
2018-11-19 10:37       ` Daniel P. Berrangé
2018-11-19 17:00         ` Eric Blake
2018-11-20  9:40           ` Daniel P. Berrangé
2018-11-19 10:36     ` Daniel P. Berrangé [this message]
2018-11-17 20:49   ` Eric Blake
2018-11-17 22:31     ` Eric Blake
2018-11-17 22:32     ` [Qemu-devel] [PATCH 1.5/6] nbd/server: Ignore write errors when replying to NBD_OPT_ABORT Eric Blake
2018-11-19 10:39       ` Daniel P. Berrangé
2018-11-19 10:39     ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Daniel P. Berrangé
2018-11-18  2:24   ` [Qemu-devel] [PATCH 7/6] iotests: Also test I/O over NBD TLS Eric Blake
2018-11-19 10:40     ` Daniel P. Berrangé
2018-11-19 17:11       ` Eric Blake
2018-11-19 17:04   ` [Qemu-devel] [PATCH 6/6] tests: exercise NBD server in TLS mode Eric Blake
2018-11-20 17:27   ` Kevin Wolf
2018-11-20 17:45     ` Eric Blake
2018-11-20 17:53       ` Daniel P. Berrangé
2018-11-20 18:22         ` Eric Blake
2018-11-20 21:56           ` Kevin Wolf
2018-11-21  9:30           ` Daniel P. Berrangé
2018-11-18  2:39 ` [Qemu-devel] [PATCH 0/6] Misc fixes to NBD Eric Blake
2018-11-27 15:42 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181119103643.GG19532@redhat.com \
    --to=berrange@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).