Skip to contentSkip to conversation

qemu-nbd: Permit TLS with Unix sockets

PATCH Superseded Eric Blake 3 participants 6 messages Jun 26, 2019 – Jun 27, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

PATCH 1/1 qemu-nbd: Permit TLS with Unix sockets

Although you generally won't use encryption with a Unix socket (after all, everything is local, so why waste the CPU power), there are situations in testsuites where Unix sockets are much nicer than TCP sockets. Since nbdkit allows encryption over both types of sockets, it makes sense for qemu-nbd to do likewise.

---
 qemu-nbd.c | 4 ----
 1 file changed, 4 deletions(-)
qemu-nbd.c +0 -4
index a8cb39e51043..ddfb6815fb69 100644
@@ -931,10 +931,6 @@ int main(int argc, char **argv)
     }
 
     if (tlscredsid) {
-        if (sockpath) {
-            error_report("TLS is only supported with IPv4/IPv6");
-            exit(EXIT_FAILURE);
-        }
         if (device) {
             error_report("TLS is not supported with a host device");
             exit(EXIT_FAILURE);
Signature · 1 line
2.20.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Eric Blake

Although you generally won't use encryption with a Unix socket (after all, everything is local, so why waste the CPU power), there are situations in testsuites where Unix sockets are much nicer than TCP sockets. Since nbdkit allows encryption over both types of sockets, it makes sense for qemu-nbd to do likewise.

---
 qemu-nbd.c | 4 ----
 1 file changed, 4 deletions(-)

Do you need something on the client side too ?

Regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#2 lore raw
Quoted 12 lines · Daniel P. Berrangé
Quoted 10 lines · Eric Blake

Although you generally won't use encryption with a Unix socket (after all, everything is local, so why waste the CPU power), there are situations in testsuites where Unix sockets are much nicer than TCP sockets. Since nbdkit allows encryption over both types of sockets, it makes sense for qemu-nbd to do likewise.

---
 qemu-nbd.c | 4 ----
 1 file changed, 4 deletions(-)
Quoted 4 lines

Do you need something on the client side too ?

The proposal that Rich is working on for standardized NBD URIs [1] says that we need a patch to support nbds://host/export and nbds+unix://export?socket=/path as ways to request an encrypted client connection with default encryption parameters. For anything more complex, we have to use --imageopts and request an encrypted connection by parts - but the QAPI schema already permits us to pass in an 'tls-creds' parameter for both TCP and Unix sockets, so no, I don't think we need any client side changes at this point.

I do, however, plan to test that 'qemu-nbd --list -k socket --tls...' works (I think it does, and it can be used even without this patch against nbdkit as server...), prior to taking this patch through my NBD tree.

[1] https://lists.debian.org/nbd/2019/06/msg00011.html

Quoted 5 lines

Regards,
Daniel

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#3 lore raw
Quoted 18 lines · Eric Blake
Quoted 12 lines · Daniel P. Berrangé
Quoted 10 lines · Eric Blake

Although you generally won't use encryption with a Unix socket (after all, everything is local, so why waste the CPU power), there are situations in testsuites where Unix sockets are much nicer than TCP sockets. Since nbdkit allows encryption over both types of sockets, it makes sense for qemu-nbd to do likewise.

---
 qemu-nbd.c | 4 ----
 1 file changed, 4 deletions(-)
Quoted 4 lines

Do you need something on the client side too ?

Quoted 8 lines

The proposal that Rich is working on for standardized NBD URIs [1] says that we need a patch to support nbds://host/export and nbds+unix://export?socket=/path as ways to request an encrypted client connection with default encryption parameters. For anything more complex, we have to use --imageopts and request an encrypted connection by parts - but the QAPI schema already permits us to pass in an 'tls-creds' parameter for both TCP and Unix sockets, so no, I don't think we need any client side changes at this point.

The QAPI schema isn't what I was thinking about.... in block/nbd.c we have the same restriction you lifted here

        tlscreds = nbd_get_tls_creds(s->tlscredsid, errp);
        if (!tlscreds) {
            goto error;
        }

        /* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
        if (s->saddr->type != SOCKET_ADDRESS_TYPE_INET) {
            error_setg(errp, "TLS only supported over IP sockets");
            goto error;
        }

For client side we would also need to allow a 'tls-hostname' parameter in BlockdevOptionsNbd, so that the client can pass a hostname to use for validating the x509 certificate, the same way we allow for live migration.

Regards,
Daniel

Signature · 3 lines
|: 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 :|
author
#4 lore raw
Quoted 11 lines · Daniel P. Berrangé
Quoted 11 lines
Quoted 2 lines

Do you need something on the client side too ?

The proposal that Rich is working on for standardized NBD URIs [1] says that we need a patch to support nbds://host/export and nbds+unix://export?socket=/path as ways to request an encrypted client connection with default encryption parameters. For anything more complex, we have to use --imageopts and request an encrypted connection by parts - but the QAPI schema already permits us to pass in an 'tls-creds' parameter for both TCP and Unix sockets, so no, I don't think we need any client side changes at this point.

Okay, I just tested that pre-patch, qemu-nbd --list refuses to connect, but post-patch it works:

$ ./qemu-nbd -r -k /tmp/nbdsock --object \
  tls-creds-psk,id=tls0,endpoint=server,dir=/home/eblake/libnbd/tests \
  --tls-creds tls0 -f raw -x / ./file
$ qemu-nbd --list -k /tmp/nbdsock --object \

tls-creds-psk,id=tls0,endpoint=client,dir=/home/eblake/libnbd/tests,username=eblake \
--tls-creds tls0
qemu-nbd: TLS is only supported with IPv4/IPv6

$ ./qemu-nbd --list -k /tmp/nbdsock --object \

tls-creds-psk,id=tls0,endpoint=client,dir=/home/eblake/libnbd/tests,username=eblake \
--tls-creds tls0
exports available: 1
...

Quoted 4 lines

The QAPI schema isn't what I was thinking about.... in block/nbd.c we have the same restriction you lifted here

Quoted 10 lines
        tlscreds = nbd_get_tls_creds(s->tlscredsid, errp);
        if (!tlscreds) {
            goto error;
        }

        /* TODO SOCKET_ADDRESS_KIND_FD where fd has AF_INET or AF_INET6 */
        if (s->saddr->type != SOCKET_ADDRESS_TYPE_INET) {
            error_setg(errp, "TLS only supported over IP sockets");
            goto error;
        }

Oh. Yeah, I'll have to fix that; it's different than qemu-nbd --list.

Quoted 5 lines

For client side we would also need to allow a 'tls-hostname' parameter in BlockdevOptionsNbd, so that the client can pass a hostname to use for validating the x509 certificate, the same way we allow for live migration.

Okay, v2 coming up later, once I've done more integration testing.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
Acked-by on v1 1/1
#5 lore raw
In reply to Eric Blake
Quoted 5 lines · Eric Blake

Although you generally won't use encryption with a Unix socket (after all, everything is local, so why waste the CPU power), there are situations in testsuites where Unix sockets are much nicer than TCP sockets. Since nbdkit allows encryption over both types of sockets, it makes sense for qemu-nbd to do likewise.

Also it's somewhat useful if using a separate tunnel process (openssh for one can do this now).

Quoted 22 lines
---
 qemu-nbd.c | 4 ----
 1 file changed, 4 deletions(-)
qemu-nbd.c +0 -4
index a8cb39e51043..ddfb6815fb69 100644
@@ -931,10 +931,6 @@ int main(int argc, char **argv)
     }
 
     if (tlscredsid) {
-        if (sockpath) {
-            error_report("TLS is only supported with IPv4/IPv6");
-            exit(EXIT_FAILURE);
-        }
         if (device) {
             error_report("TLS is not supported with a host device");
             exit(EXIT_FAILURE);
Signature · 1 line
2.20.1

The patch looks very simple, just removing an unnecessary restriction, so:

If we could have the same change on the qemu client side that would be great because we could use it here:

https://github.com/libguestfs/nbdkit/blob/e0d324683c86455a2fe62e97d57f1313cad9c9f3/tests/functions.sh.in#L133

Rich.

Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org