From 66bc3722fccf07b6a445d72c62b974906dbe6d17 Mon Sep 17 00:00:00 2001 From: Lindsay Harvey Date: Wed, 20 May 2026 18:52:22 +1000 Subject: [PATCH] feat(vdi): host port range + container lifecycle hooks (#137) Contributed by @vk2amv (Lindsay). Adds two related operator features to the Docker VDI driver: 1. Bounded host port range via [vdi] port_range_start / port_range_end. Currently Docker picks an arbitrary high port for the container's RDP listener; this lets operators constrain it which matters for firewalls, reverse proxies, and identity-aware gates that need to know in advance which ports rustguac will use. Port selection inside the range is deterministic-from-username (FNV-1a hash), so reconnects from the same user get the same port. Falls through to the next port on collision. 2. Container lifecycle hook script via [vdi] container_hook_script. Called as 'up ' after Docker assigns the port, again as 'down ...' before removal. Lets deployments wire external preparation/cleanup (firewall opens, service mesh registration, identity-aware gates) without baking the logic into rustguac itself. Bounded timeout (default 10s). Script is invoked via Command::new (no shell), so no injection risk from container metadata. 3 new tests covering port-candidate behaviour. Docs in docs/configuration.md and docs/vdi.md. Thanks Lindsay. --- docs/configuration.md | 8 + docs/vdi.md | 24 +++ src/config.rs | 19 ++ src/session.rs | 28 ++- src/vdi/docker.rs | 455 +++++++++++++++++++++++++++++++++++------- 5 files changed, 461 insertions(+), 73 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 62340a6..fa80330 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -240,6 +240,10 @@ Enables VDI (Virtual Desktop Infrastructure) sessions using Docker containers. E | `default_cpu_limit` | float | `0` | Default CPU limit for containers (fractional cores, e.g. 2.0). 0 = no limit. | | `default_memory_limit` | integer | `0` | Default memory limit in MB. 0 = no limit. | | `ready_timeout_secs` | integer | `30` | Seconds to wait for xrdp to become ready in a new container. | +| `port_range_start` | integer | *(none)* | First localhost port Docker may bind VDI RDP to. Must be set with `port_range_end`. | +| `port_range_end` | integer | *(none)* | Last localhost port Docker may bind VDI RDP to. Must be set with `port_range_start`. | +| `container_hook_script` | string | *(none)* | Optional VDI container hook script. Called as `