From 4bc2fb5d03094aeab1670886331d9f43640c3960 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 30 Jun 2023 14:16:16 +0200 Subject: Implement disabling USB in VMs --- .../virtualization/configuration/VirtualizationConfiguration.java | 2 ++ .../configuration/VirtualizationConfigurationDocker.java | 6 ++++++ .../configuration/VirtualizationConfigurationQemu.java | 6 ++++++ .../configuration/VirtualizationConfigurationVirtualBox.java | 6 ++++++ .../configuration/VirtualizationConfigurationVmware.java | 6 ++++++ .../logic/ConfigurationLogicDozModServerToStatelessClient.java | 3 +-- 6 files changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java index c1895bf..d4b3058 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfiguration.java @@ -293,6 +293,8 @@ public abstract class VirtualizationConfiguration public abstract boolean addCpuCoreCount( int nrOfCores ); + public abstract void disableUsb(); + public abstract void setVirtualizerVersion( Version type ); public abstract Version getVirtualizerVersion(); diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java index 8a06b80..3163ed2 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationDocker.java @@ -165,4 +165,10 @@ public class VirtualizationConfigurationDocker extends VirtualizationConfigurati { } + @Override + public void disableUsb() + { + // Not applicable, maybe some day via USBguard? + } + } diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java index 45b4f1f..6c62a96 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationQemu.java @@ -894,4 +894,10 @@ public class VirtualizationConfigurationQemu extends VirtualizationConfiguration throw new VirtualizationConfigurationException( e.getLocalizedMessage() ); } } + + @Override + public void disableUsb() + { + new QemuUsbSpeed( ControllerUsb.Model.NONE, Usb.NONE ).apply(); + } } diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java index ebfd918..153fffa 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVirtualBox.java @@ -592,4 +592,10 @@ public class VirtualizationConfigurationVirtualBox extends VirtualizationConfigu { this.config.validate(); } + + @Override + public void disableUsb() + { + new VBoxUsbSpeed( null, Usb.NONE ).apply(); + } } diff --git a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java index d9ad129..a237674 100644 --- a/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java +++ b/src/main/java/org/openslx/virtualization/configuration/VirtualizationConfigurationVmware.java @@ -727,4 +727,10 @@ public class VirtualizationConfigurationVmware extends VirtualizationConfigurati public void validate() throws VirtualizationConfigurationException { } + + @Override + public void disableUsb() + { + new VmWareUsbSpeed( 0, Usb.NONE ).apply(); + } } diff --git a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java index 5dec3d9..2d3e861 100644 --- a/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java +++ b/src/main/java/org/openslx/virtualization/configuration/logic/ConfigurationLogicDozModServerToStatelessClient.java @@ -102,8 +102,7 @@ public class ConfigurationLogicDozModServerToStatelessClient // disable USB if necessary if ( !args.hasUsbAccess() ) { - // XXX TODO find best way to do this without explicit method - // config.setMaxUsbSpeed( UsbSpeed.NONE ); + config.disableUsb(); } } } -- cgit v1.2.3-55-g7522