vnc: add qmp to support reload vnc tls certificates
PATCH 1/1 vnc: add qmp to support reload vnc tls certificates
QEMU loads vnc tls certificates only when vm is started. This patch provides a new qmp command to reload vnc tls certificates without restart vnc-server/VM.
--- include/ui/console.h | 1 + monitor/qmp-cmds.c | 7 +++++++ qapi/ui.json | 17 +++++++++++++++++ ui/vnc.c | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+)
include/ui/console.h +1 -0
@@ -441,6 +441,7 @@ int vnc_display_password(const char *id, const char *password);int vnc_display_pw_expire (const char *id,time_t expires);QemuOpts *vnc_parse (const char *str,Error **errp);int vnc_init_func (void *opaque,QemuOpts *opts,Error **errp); +int vnc_display_reload_cert (const char *id,Error **errp);/* input.c */ int index_from_key (const char *key,size_t key_length);
monitor/qmp-cmds.c +7 -0
@@ -287,6 +287,13 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, qmp_change_vnc_listen(target, errp); } } + +void qmp_reload_vnc_cert (Error **errp) +{ +if (vnc_display_reload_cert (NULL , errp) <0 ) { +error_setg (errp,"Reload vnc tls cert failed" ); + } +}#endif /* !CONFIG_VNC */ void qmp_change(const char *device, const char *target,
qapi/ui.json +17 -0
@@ -1179,3 +1179,20 @@ ## { 'command': 'query-display-options', 'returns': 'DisplayOptions' } + +## +# @reload-vnc-cert: +# +# Reload certificates for vnc. +# +# Returns: nothing +# +# Since: 5.2 +# +# Example: +# +# -> { "execute": "reload-vnc-cert" } +# <- { "return": {} } +# +## +{ 'command': 'reload-vnc-cert' }
ui/vnc.c +20 -0
@@ -582,6 +582,26 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp)return prev; } +int vnc_display_reload_cert (const char *id,Error **errp) +{ +VncDisplay *vd =vnc_display_find (id); + +if (!vd) { +return -EINVAL ; + } + +if (!vd->tlscreds) { +error_printf_unless_qmp ("If you want use vnc tls please enable " +"vnc tls using '-vnc tls-creds=${tls-obj-id}'.\n" ); +return -EPERM ; + } + +object_property_set_bool (OBJECT (vd->tlscreds),"loaded" , false,NULL ); +object_property_set_bool (OBJECT (vd->tlscreds),"loaded" , true,NULL ); + +return 0 ; +} +/* TODO 1) Get the queue working for IO. 2) there is some weirdness when using the -S option (the screen is grey
Signature · 1 line
2.23.0
Quoted 29 lines · Zihao Chang
QEMU loads vnc tls certificates only when vm is started. This patch provides a new qmp command to reload vnc tls certificates without restart vnc-server/VM.
Signed-off-by Zihao Chang <[email protected]>--- include/ui/console.h | 1 + monitor/qmp-cmds.c | 7 +++++++ qapi/ui.json | 17 +++++++++++++++++ ui/vnc.c | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+)include/ui/console.h +1
-0@@ -441,6 +441,7 @@ int vnc_display_password(const char *id, const char *password);int vnc_display_pw_expire (const char *id,time_t expires);QemuOpts *vnc_parse (const char *str,Error **errp);int vnc_init_func (void *opaque,QemuOpts *opts,Error **errp); +int vnc_display_reload_cert (const char *id,Error **errp);/* input.c */ int index_from_key (const char *key,size_t key_length);monitor/qmp-cmds.c +0
-0
monitor/qmp-cmds.c static void qmp_change_vnc(const char *target, bool has_arg, const char *arg, · line 294
Quoted 8 lines
monitor/qmp-cmds.c +5
-0@@ -287,6 +287,13 @@ static void qmp_change_vnc(const char *target, bool has_arg, const char *arg,qmp_change_vnc_listen (target, errp); } } + +void qmp_reload_vnc_cert (Error **errp) +{ +if (vnc_display_reload_cert (NULL , errp) <0 ) { +error_setg (errp,"Reload vnc tls cert failed" );
This error message is entirely useless at helping diagnose what failed. We need to propagate real error messages from the root cause.
Quoted 40 lines
monitor/qmp-cmds.c +2
-0+ } +}#endif /* !CONFIG_VNC */ void qmp_change(const char *device, const char *target,qapi/ui.json +17
-0@@ -1179,3 +1179,20 @@ ## { 'command': 'query-display-options', 'returns': 'DisplayOptions' } + +## +# @reload-vnc-cert: +# +# Reload certificates for vnc. +# +# Returns: nothing +# +# Since: 5.2 +# +# Example: +# +# -> { "execute": "reload-vnc-cert" } +# <- { "return": {} } +# +## +{ 'command': 'reload-vnc-cert' }ui/vnc.c +2
-0@@ -582,6 +582,26 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp)return prev; } +int vnc_display_reload_cert (const char *id,Error **errp) +{
ui/vnc.c VncInfo2List *qmp_query_vnc_servers(Error **errp) · line 596
Quoted 10 lines
ui/vnc.c +10
-0+VncDisplay *vd =vnc_display_find (id); + +if (!vd) { +return -EINVAL ; + } + +if (!vd->tlscreds) { +error_printf_unless_qmp ("If you want use vnc tls please enable " +"vnc tls using '-vnc tls-creds=${tls-obj-id}'.\n" ); +return -EPERM ;
You're passing in a 'Error' object, so use that and don't retyrn errnos
ui/vnc.c VncInfo2List *qmp_query_vnc_servers(Error **errp) · line 600
Quoted 4 lines
ui/vnc.c +4
-0+ } + +object_property_set_bool (OBJECT (vd->tlscreds),"loaded" , false,NULL ); +object_property_set_bool (OBJECT (vd->tlscreds),"loaded" , true,NULL );
This is ignoring all errors which is not at all acceptable. It means on failure to load the new certs, we're left with a broken creds object which callers will not expect.
We need to be able to do this in a safe way such that we carry on using the original TLS certs if loading the new ones fails. This can't be done using the 'loaded' property- we need an explicit API to reload things.
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 6 lines · Daniel P. Berrangé
Quoted 5 lines · Zihao Chang
QEMU loads vnc tls certificates only when vm is started. This patch provides a new qmp command to reload vnc tls certificates without restart vnc-server/VM.
Signed-off-by Zihao Chang <[email protected]>
[...]
Quoted 8 lines
Quoted 8 lines
ui/vnc.c +0
-0@@ -582,6 +582,26 @@ VncInfo2List *qmp_query_vnc_servers(Error **errp)return prev; }
Quoted 14 lines
ui/vnc.c VncInfo2List *qmp_query_vnc_servers(Error **errp) · line 596
Quoted 12 lines
ui/vnc.c +12
-0+int vnc_display_reload_cert (const char *id,Error **errp) +{ +VncDisplay *vd =vnc_display_find (id); + +if (!vd) { +return -EINVAL ; + } + +if (!vd->tlscreds) { +error_printf_unless_qmp ("If you want use vnc tls please enable " +"vnc tls using '-vnc tls-creds=${tls-obj-id}'.\n" ); +return -EPERM ;You're passing in a 'Error' object, so use that and don't retyrn errnos
Do return a value that indicates success / failure. See the big comment in include/qapi/error.h for why.
I recommend bool unless callers need to distinguish between several failures.
[...]
Quoted 11 lines · Zihao Chang
QEMU loads vnc tls certificates only when vm is started. This patch provides a new qmp command to reload vnc tls certificates without restart vnc-server/VM.
Signed-off-by Zihao Chang <[email protected]>---
+++
b/qapi/ui.jsonqapi/ui.json +0
-0@@ -1179,3 +1179,20 @@ ## { 'command': 'query-display-options',
qapi/ui.json line 1190
Quoted 10 lines
qapi/ui.json +9
-0'returns': 'DisplayOptions' } + +## +# @reload-vnc-cert: +# +# Reload certificates for vnc. +# +# Returns: nothing +# +# Since: 5.2
You've missed 5.2. The next release will be 6.0.
Quoted 8 lines
qapi/ui.json +8
-0+# +# Example: +# +# -> { "execute": "reload-vnc-cert" } +# <- { "return": {} } +# +## +{ 'command': 'reload-vnc-cert' }
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org