qemu-nbd: Permit TLS with Unix sockets
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
@@ -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
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.
Signed-off-by Eric Blake <[email protected]>--- 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 :|
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.
Signed-off-by Eric Blake <[email protected]>--- qemu-nbd.c | 4 ---- 1 file changed, 4 deletions(-)
Quoted 4 lines
Reviewed-by Daniel P. Berrangé <[email protected]>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
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.
Signed-off-by Eric Blake <[email protected]>--- qemu-nbd.c | 4 ---- 1 file changed, 4 deletions(-)Quoted 4 lines
Reviewed-by Daniel P. Berrangé <[email protected]>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 :|
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.cwe 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
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
Signed-off-by Eric Blake <[email protected]>--- qemu-nbd.c | 4 ---- 1 file changed, 4 deletions(-)qemu-nbd.c +0
-4@@ -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:
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