From a2e9cd4f7023ff67d98395b7fc5a41cfcb23ec85 Mon Sep 17 00:00:00 2001 From: "Michael N. Lipp" Date: Tue, 20 Jun 2023 12:00:02 +0200 Subject: [PATCH] Support Spice ticket. --- .../config-sample.yaml | 2 ++ .../vmoperator/runner/qemu/Configuration.java | 3 +++ .../org/jdrupes/vmoperator/runner/qemu/Runner.java | 12 ++++++++++++ .../templates/Standard-VM-latest.ftl.yaml | 7 ++++++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml b/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml index 63152bf..3e18871 100644 --- a/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml +++ b/org.jdrupes.vmoperator.runner.qemu/config-sample.yaml @@ -95,4 +95,6 @@ # "display": # "spice": # "port": 5900 + # "ticket": (default is to disable ticketing) + # "streamingVideo": (default) # "usbRedirects": 2 diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java index d2162e9..94222d7 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Configuration.java @@ -273,6 +273,9 @@ class Configuration implements Dto { /** The port. */ public int port = 5900; + /** The ticket. */ + public String ticket; + /** The streaming video. */ public String streamingVideo; diff --git a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java index 4f20d3f..7d897d3 100644 --- a/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java +++ b/org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java @@ -310,6 +310,10 @@ public class Runner extends Component { model.put("firmwareVars", Optional.ofNullable(config.firmwareVars) .map(Object::toString).orElse(null)); model.put("vm", config.vm); + if (Optional.ofNullable(config.vm.display) + .map(d -> d.spice).map(s -> s.ticket).isPresent()) { + model.put("ticketPath", config.runtimeDir.resolve("ticket.txt")); + } // Combine template and data and parse result // (tempting, but no need to use a pipe here) @@ -342,6 +346,14 @@ public class Runner extends Component { // Files to watch for Files.deleteIfExists(config.swtpmSocket); fire(new WatchFile(config.swtpmSocket)); + + // Helper files + var ticket = Optional.ofNullable(config.vm.display) + .map(d -> d.spice).map(s -> s.ticket); + if (ticket.isPresent()) { + Files.write(config.runtimeDir.resolve("ticket.txt"), + ticket.get().getBytes()); + } } catch (IOException e) { logger.log(Level.SEVERE, e, () -> "Cannot start runner: " + e.getMessage()); diff --git a/org.jdrupes.vmoperator.runner.qemu/templates/Standard-VM-latest.ftl.yaml b/org.jdrupes.vmoperator.runner.qemu/templates/Standard-VM-latest.ftl.yaml index 822eb83..741a3ec 100644 --- a/org.jdrupes.vmoperator.runner.qemu/templates/Standard-VM-latest.ftl.yaml +++ b/org.jdrupes.vmoperator.runner.qemu/templates/Standard-VM-latest.ftl.yaml @@ -184,7 +184,12 @@ <#assign spice = vm.display.spice/> # SPICE (display, channels ...) # https://www.linux-kvm.org/page/SPICE - - [ "-spice", "port=${ spice.port?c },disable-ticketing=on\ + <#if ticketPath??> + - [ "-object", "secret,id=spiceTicket,file=${ ticketPath }" ] + + - [ "-spice", "port=${ spice.port?c }\ + <#if spice.ticket??>,password-secret=spiceTicket\ + <#else>,disable-ticketing=on\ <#if spice.streamingVideo??>,streaming-video=${ spice.streamingVideo }\ ,seamless-migration=on" ] - [ "-chardev", "spicevmc,id=vdagentdev,name=vdagent" ]