From 08f95e73d4db33794e77624f46177bea38629fa0 Mon Sep 17 00:00:00 2001 From: "OpenGenesis (MPL 2.0)" <153564363+opengenesislink@users.noreply.github.com> Date: Fri, 23 Oct 2026 17:01:09 +0200 Subject: [PATCH] feat(oglvoice): dedicated WebRTC media deployment (PR #285) * feat(oglvoice): dedicated WebRTC voice vServer deployment and ICE configuration * docs(oglvoice): align dedicated host sample with existing nexverse tenant --- .../Voice/OglVoiceRegionDiscoveryModule.cs | 14 +- .../oglvoice-media/deploy/Caddyfile.example | 28 ++++ services/oglvoice-media/deploy/README.md | 148 ++++++++++++++++++ services/oglvoice-media/deploy/compose.yaml | 12 ++ .../deploy/livekit.yaml.example | 13 ++ .../oglvoice-media/deploy/media.env.example | 11 ++ .../deploy/oglvoice-media.service | 23 +++ services/oglvoice-media/ice_config_test.go | 49 ++++++ services/oglvoice-media/media.go | 15 +- services/oglvoice-media/security.go | 18 +++ 10 files changed, 329 insertions(+), 2 deletions(-) create mode 100644 services/oglvoice-media/deploy/Caddyfile.example create mode 100644 services/oglvoice-media/deploy/README.md create mode 100644 services/oglvoice-media/deploy/compose.yaml create mode 100644 services/oglvoice-media/deploy/livekit.yaml.example create mode 100644 services/oglvoice-media/deploy/media.env.example create mode 100644 services/oglvoice-media/deploy/oglvoice-media.service create mode 100644 services/oglvoice-media/ice_config_test.go diff --git a/NexVerse/RegionModules/Voice/OglVoiceRegionDiscoveryModule.cs b/NexVerse/RegionModules/Voice/OglVoiceRegionDiscoveryModule.cs index ef0a607a..affaf407 100644 --- a/NexVerse/RegionModules/Voice/OglVoiceRegionDiscoveryModule.cs +++ b/NexVerse/RegionModules/Voice/OglVoiceRegionDiscoveryModule.cs @@ -35,6 +35,9 @@ namespace NexVerse.RegionModules.Voice private int m_Disposed; // Log readiness transitions only, not every periodic discovery poll. private int m_ViewerProviderState = -1; + // Only report changes in HTTP error state. A disabled ROBUST route + // must not flood the simulator log every discovery interval. + private int m_LastDiscoveryHttpError; private OglVoiceProviderDescriptor m_Current; private DateTimeOffset m_LastRefresh; @@ -199,7 +202,14 @@ namespace NexVerse.RegionModules.Voice { Volatile.Write(ref m_Current, null); Interlocked.Exchange(ref m_ViewerProviderState, -1); - m_Log.WarnFormat("[OGL-VOICE]: Provider-Discovery abgelehnt (HTTP {0}).", (int)response.StatusCode); + int status = (int)response.StatusCode; + if (Interlocked.Exchange(ref m_LastDiscoveryHttpError, status) != status) + { + if (status == 404) + m_Log.Warn("[OGL-VOICE]: Provider-Discovery HTTP 404: ROBUST registriert /internal/oglvoice/v1/provider nur bei [OGLVoice] Enabled=true. AuthorityUrl, NodeAgent PeerUrl und den ROBUST-Listener pruefen. Wiederholte 404-Meldungen werden bis zum Statuswechsel unterdrueckt."); + else + m_Log.WarnFormat("[OGL-VOICE]: Provider-Discovery abgelehnt (HTTP {0}).", status); + } return; } @@ -220,6 +230,8 @@ namespace NexVerse.RegionModules.Voice throw new InvalidOperationException("Empty provider descriptor"); provider.Validate(); + if (Interlocked.Exchange(ref m_LastDiscoveryHttpError, 0) != 0) + m_Log.Info("[OGL-VOICE]: Provider-Discovery HTTP-Zugriff wiederhergestellt."); Volatile.Write(ref m_Current, provider); m_LastRefresh = DateTimeOffset.UtcNow; bool viewerReady = provider.viewer_capability == "firestorm-webrtc-v1" && diff --git a/services/oglvoice-media/deploy/Caddyfile.example b/services/oglvoice-media/deploy/Caddyfile.example new file mode 100644 index 00000000..ac011626 --- /dev/null +++ b/services/oglvoice-media/deploy/Caddyfile.example @@ -0,0 +1,28 @@ +# Copy to /etc/caddy/Caddyfile, replace the simulator IP/CIDR first. +# Prefer a WireGuard subnet. Do NOT allow 0.0.0.0/0 to /internal/webrtc/. +# Caddy obtains a public TLS certificate for voice.opengenesislink.de. +voice.opengenesislink.de { + @authorized_exchange { + path /internal/webrtc/v1/exchange + method POST + remote_ip REPLACE_WITH_TRUSTED_SIMULATOR_IP_OR_CIDR + } + + handle @authorized_exchange { + reverse_proxy 127.0.0.1:19098 + } + + handle /internal/webrtc/* { + respond "forbidden" 403 + } + + handle /healthz { + reverse_proxy 127.0.0.1:19098 + } + + # LiveKit WebSocket signalling (HTTPS/WSS) is public to authorized + # LiveKit clients; no admin key or signing secret is published here. + handle { + reverse_proxy 127.0.0.1:7880 + } +} diff --git a/services/oglvoice-media/deploy/README.md b/services/oglvoice-media/deploy/README.md new file mode 100644 index 00000000..d15cecd0 --- /dev/null +++ b/services/oglvoice-media/deploy/README.md @@ -0,0 +1,148 @@ +# OpenGenesisLINK OGLVoice 2.0 — dedicated voice.opengenesislink.de vServer + +**Status: Deployment scaffolding; not an installed or production-validated Voice system.** +The C# OGLVoice region discovery and Firestorm CAPS adapters already exist in the main server. +This deployment supplies a separate **Pion WebRTC media bridge** and **LiveKit SFU**. It does +not install or modify ROBUST, and it must not be mistaken for a voice-enabled production release +until tested with real Firestorm viewers. + +## Request and media paths + +1. Simulator `[NexVerseNodeAgent]` polls its trusted **ROBUST** listener at + `/internal/oglvoice/v1/provider`. This is **not a media-server endpoint**. + HTTP 404 means ROBUST is not publishing that path (often `[OGLVoice] Enabled=false`), + or the NodeAgent `PeerUrl` points to the wrong HTTP listener/reverse proxy. +2. ROBUST returns an HMAC-signed provider descriptor with the Firestorm MediaGatewayUrl. +3. Firestorm sends voice LLSD through the simulator CAPS. Simulator validates authenticated + avatar session, region/parcel voice permission, and Hypergrid admission. +4. Simulator signs a media exchange using its NexBus node shared key. Caddy on + `voice.opengenesislink.de` permits only trusted simulator IPs to + `POST /internal/webrtc/v1/exchange`; the bridge checks node ACL/HMAC/nonces. +5. The bridge terminates Firestorm Pion WebRTC and feeds Opus into LiveKit. LiveKit and + Pion media packets are **UDP**, not Web traffic; Caddy cannot proxy their UDP ICE ports. + +## Debian 13 dedicated host: installation steps + +Prerequisites: a DNS A/AAAA record for `voice.opengenesislink.de` on this **new vServer**, +a public reachable IP, firewall control, Go version required by `go.mod`, `libopus-dev`, +`pkg-config`, `libopus0`, Docker Compose and Caddy. Use recent security-patched releases. +For the media bridge, prefer direct host deployment rather than bridged Docker NAT. + +```bash +sudo apt-get update +sudo apt-get install -y ca-certificates git golang-go pkg-config libopus-dev libopus0 caddy docker.io docker-compose-plugin +sudo useradd --system --no-create-home --shell /usr/sbin/nologin oglvoice +sudo install -d -m 0750 -o oglvoice -g oglvoice /opt/oglvoice /etc/oglvoice +git clone https://github.com/opengenesislink/opengenesislinkserver.git /opt/oglvoice/source +cd /opt/oglvoice/source/services/oglvoice-media +go build -tags nolibopusfile -trimpath -o /tmp/oglvoice-media . +sudo install -m 0755 -o root -g root /tmp/oglvoice-media /opt/oglvoice/oglvoice-media +``` + +**Go version:** Debian's `golang-go` may be older than the `go` directive in +`services/oglvoice-media/go.mod`. Verify `go version` and install the supported upstream +toolchain as required, rather than changing dependency versions arbitrarily. + +Copy `deploy/livekit.yaml.example` to `/etc/oglvoice/livekit.yaml`; choose a strong +LiveKit API key and random API secret (at least 32 bytes). Put **exactly the same** +key and secret in `/etc/oglvoice/media.env` (based on `deploy/media.env.example`). +Keep the existing grid tenant `nexverse` for Stadt NexVerse (or use separate tenant IDs for other grids). Replace NodeId and the **existing** NexBus shared key with your actual simulator values. +For multiple simulators add a separate `nodes` entry per NodeId, using each node's +real shared key. Never expose a LiveKit signing secret to a viewer. + +```bash +sudo chown root:oglvoice /etc/oglvoice/livekit.yaml +sudo chmod 0640 /etc/oglvoice/livekit.yaml +sudo chown root:oglvoice /etc/oglvoice/media.env +sudo chmod 0640 /etc/oglvoice/media.env +``` + +Copy `deploy/compose.yaml` to `/opt/oglvoice/compose.yaml`, then create +`/opt/oglvoice/.env` with `LIVEKIT_TAG=`. +Do not use `latest` for production; verify image version compatibility and pin it. +`sudo docker compose -f /opt/oglvoice/compose.yaml up -d` starts LiveKit with +host networking and the local YAML configuration. + +Install `deploy/oglvoice-media.service` at `/etc/systemd/system/oglvoice-media.service`: +```bash +sudo systemctl daemon-reload +sudo systemctl enable --now oglvoice-media +sudo systemctl status oglvoice-media +curl -fsS http://127.0.0.1:19098/healthz +``` + +Replace `REPLACE_WITH_TRUSTED_SIMULATOR_IP_OR_CIDR` in `deploy/Caddyfile.example` +with the **actual** simulator public source address or VPN CIDR. Use individual IPs or +the restricted WireGuard subnet, not an Internet-wide CIDR. If Caddy is behind another +proxy, ensure its `remote_ip` evaluation refers to the actual authenticated origin. +Copy to `/etc/caddy/Caddyfile`, run `caddy validate --config /etc/caddy/Caddyfile` +and reload Caddy. TLS and DNS must resolve correctly before enabling Firestorm. + +### Firewall: different independent transports + +| Endpoint | TCP | UDP | Access | +| --- | --- | --- | --- | +| Caddy HTTPS/WSS + ACME | 443, 80 | — | Public | +| Pion WebRTC Firestorm | — | 40000–40999 | Public | +| LiveKit ICE TCP | 7881 | — | Public | +| LiveKit ICE UDP multiplex | — | 7882 | Public | +| LiveKit embedded TURN/UDP | — | 3478 | Public | +| LiveKit HTTP API | 7880 | — | Local/proxy only | +| OGL media bridge HTTP | 19098 | — | Loopback only | + +Expose UDP ICE directly on the **voice vServer**, not through the ROBUST HTTP server. +Pion's port range is configurable by `OGLVOICE_WEBRTC_PORT_MIN/MAX` and is fail-closed +for invalid ranges; the example allocates 1000 ports. Larger deployments need capacity +and port-exhaustion testing. NAT requires correct public ICE candidates. TURN/TLS on 443 +needs further deployment design (often a dedicated TURN hostname/certificate); UDP TURN +alone does **not** guarantee connectivity across restrictive enterprise firewalls. + +## ROBUST and simulator setup + +On the grid ROBUST's **active** `Robust.HG.ini` or `Robust.ini` (not only the +`.example` file), set: + +```ini +[OGLVoice] + Enabled = true + Mode = "GridAuthority" + ServiceUrl = "https://voice.opengenesislink.de" + TenantId = "nexverse" + IncludeHypergridGuests = true + EnableFirestormGateway = true + MediaGatewayUrl = "https://voice.opengenesislink.de/internal/webrtc/v1/exchange" + EnableSessionAuthority = false +``` + +`EnableSessionAuthority` is a separate optional ROBUST LiveKit-token endpoint +and is not necessary to activate the external Go Media Bridge; LiveKit signing +keys remain on the media vServer. With `Mode=GridManaged` the simulator discovers +the provider from ROBUST using `[NexVerseNodeAgent]` (not from the voice hostname). +Set its `PeerUrl` to the **reachable actual ROBUST listener** and its NodeId/SharedKey +to match the media ACL. Restart ROBUST so the discovery handler is registered; +restart simulator(s) as required to register viewer CAPS. + +**Before enabling the gateway**, verify `/healthz`, HTTPS routing, the bridge logs, +LiveKit process, TLS certificates, and the private trusted ROBUST discovery. +A non-signed public `curl` request to the ROBUST discovery path should return +401 (not 404) once the route is actually registered. A GET to the media exchange +returns 403 via Caddy (only trusted POSTs are proxied); this is by design. +Do **not** treat a HTTP 200 at `/healthz` as proof of audio. + +### End-to-end acceptance + +Run two unmodified Firestorm OpenSim WebRTC-enabled viewers with avatars on one +voice-enabled parcel. Test bidirectional Opus audio, mixed simultaneous speakers, +distance/panning, mic mute/PTT, on-screen speaking indicators, region crossing, +Hypergrid access, logout/reconnect and unauthorized NodeId rejection. +Check LiveKit and bridge logs plus UDP connection tracking under load. +Never claim productive WebRTC voice solely from a passing CI build. + +### Troubleshooting the historical HTTP 404 + +The simulator logs the first HTTP 404 when ROBUST does not register provider discovery; +further identical responses are quiet until the HTTP status changes. This only +reduces log noise — it **does not** enable voice or mask a changing error state. +Inspect active ROBUST `[OGLVoice]`, NodeAgent `PeerUrl`, proxy routing and the +listening host/port. HTTP 401 means the correct handler is present but authentication +or HMAC key verification failed; do not disable authentication to silence the log. diff --git a/services/oglvoice-media/deploy/compose.yaml b/services/oglvoice-media/deploy/compose.yaml new file mode 100644 index 00000000..d64f8659 --- /dev/null +++ b/services/oglvoice-media/deploy/compose.yaml @@ -0,0 +1,12 @@ +# Dedicated vServer, Linux host networking is required for ICE. +# Set LIVEKIT_TAG to a tested/pinned release in the local .env file. +services: + livekit: + image: livekit/livekit-server:${LIVEKIT_TAG:?set a pinned LIVEKIT_TAG in .env} + restart: unless-stopped + network_mode: host + command: ["--config", "/etc/livekit/livekit.yaml"] + volumes: + - /etc/oglvoice/livekit.yaml:/etc/livekit/livekit.yaml:ro + security_opt: + - no-new-privileges:true diff --git a/services/oglvoice-media/deploy/livekit.yaml.example b/services/oglvoice-media/deploy/livekit.yaml.example new file mode 100644 index 00000000..47f0d90c --- /dev/null +++ b/services/oglvoice-media/deploy/livekit.yaml.example @@ -0,0 +1,13 @@ +# Copy to /etc/oglvoice/livekit.yaml, set chmod 0600 and replace credentials. +# Do not commit the populated configuration to source control. +port: 7880 +log_level: info +rtc: + tcp_port: 7881 + udp_port: 7882 + use_external_ip: true +turn: + enabled: true + udp_port: 3478 +keys: + REPLACE_WITH_OGLVOICE_API_KEY: REPLACE_WITH_LONG_RANDOM_LIVEKIT_SECRET diff --git a/services/oglvoice-media/deploy/media.env.example b/services/oglvoice-media/deploy/media.env.example new file mode 100644 index 00000000..23c6ab00 --- /dev/null +++ b/services/oglvoice-media/deploy/media.env.example @@ -0,0 +1,11 @@ +# EXAMPLE ONLY. Copy to /etc/oglvoice/media.env (chmod 0600; owner oglvoice). +# Use the ACTUAL simulator [NexVerseNodeAgent] NodeId and SharedKey values. +# The first-party tenant has unlimited sessions, by deliberate server policy. +OGLVOICE_MEDIA_BIND=127.0.0.1:19098 +OGLVOICE_LIVEKIT_URL=ws://127.0.0.1:7880 +OGLVOICE_LIVEKIT_API_KEY=REPLACE_WITH_OGLVOICE_API_KEY +OGLVOICE_LIVEKIT_API_SECRET=REPLACE_WITH_LONG_RANDOM_LIVEKIT_SECRET +OGLVOICE_WEBRTC_STUN_URLS=stun:stun.l.google.com:19302 +OGLVOICE_WEBRTC_PORT_MIN=40000 +OGLVOICE_WEBRTC_PORT_MAX=40999 +OGLVOICE_MEDIA_ACL_JSON='{"nodes":{"REPLACE_WITH_REAL_NODE_ID":{"secret":"REPLACE_WITH_REAL_NEXBUS_SHARED_KEY_MINIMUM_32_BYTES","tenant":"nexverse"}},"tenants":{"nexverse":{"max_sessions":0,"max_regions":0}}}' diff --git a/services/oglvoice-media/deploy/oglvoice-media.service b/services/oglvoice-media/deploy/oglvoice-media.service new file mode 100644 index 00000000..64539ed3 --- /dev/null +++ b/services/oglvoice-media/deploy/oglvoice-media.service @@ -0,0 +1,23 @@ +[Unit] +Description=OpenGenesisLINK OGLVoice Firestorm WebRTC Media Bridge +Wants=network-online.target +After=network-online.target + +[Service] +Type=simple +User=oglvoice +Group=oglvoice +WorkingDirectory=/opt/oglvoice +EnvironmentFile=/etc/oglvoice/media.env +ExecStart=/opt/oglvoice/oglvoice-media +Restart=on-failure +RestartSec=5 +NoNewPrivileges=true +PrivateTmp=true +ProtectSystem=strict +ProtectHome=true +LimitNOFILE=65535 +UMask=0077 + +[Install] +WantedBy=multi-user.target diff --git a/services/oglvoice-media/ice_config_test.go b/services/oglvoice-media/ice_config_test.go new file mode 100644 index 00000000..d77dd327 --- /dev/null +++ b/services/oglvoice-media/ice_config_test.go @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MPL-2.0 +package main + +import ( + "strings" + "testing" +) + +func setMediaTestEnv(t *testing.T) { + t.Helper() + t.Setenv("OGLVOICE_MEDIA_ACL_JSON", `{"nodes":{"sim-01":{"secret":"abcdefghijklmnopqrstuvwxyz0123456789","tenant":"ogl"}},"tenants":{"ogl":{"max_sessions":0,"max_regions":0}}}`) + t.Setenv("OGLVOICE_LIVEKIT_URL", "ws://127.0.0.1:7880") + t.Setenv("OGLVOICE_LIVEKIT_API_KEY", "test-only") + t.Setenv("OGLVOICE_LIVEKIT_API_SECRET", strings.Repeat("z", 40)) +} + +func TestDedicatedWebRTCPortRange(t *testing.T) { + setMediaTestEnv(t) + t.Setenv("OGLVOICE_WEBRTC_PORT_MIN", "40000") + t.Setenv("OGLVOICE_WEBRTC_PORT_MAX", "40999") + cfg, err := loadConfig() + if err != nil { t.Fatal(err) } + if cfg.WebRTCPortMin != 40000 || cfg.WebRTCPortMax != 40999 { + t.Fatalf("unexpected WebRTC ports: %d-%d", cfg.WebRTCPortMin, cfg.WebRTCPortMax) + } + pc, err := newViewerPeerConnection(cfg, nil) + if err != nil { t.Fatal(err) } + _ = pc.Close() +} + +func TestDedicatedWebRTCPortRangeRejectsInvalid(t *testing.T) { + for _, tc := range []struct{ name, min, max string }{ + {"one-sided", "40000", ""}, + {"reversed", "41000", "40000"}, + {"too-small", "40000", "40002"}, + {"system-port", "80", "1000"}, + {"overflow", "40000", "65536"}, + {"non-numeric", "abc", "41000"}, + } { + t.Run(tc.name, func(t *testing.T) { + setMediaTestEnv(t) + t.Setenv("OGLVOICE_WEBRTC_PORT_MIN", tc.min) + t.Setenv("OGLVOICE_WEBRTC_PORT_MAX", tc.max) + if _, err := loadConfig(); err == nil { + t.Fatal("invalid UDP port range accepted") + } + }) + } +} diff --git a/services/oglvoice-media/media.go b/services/oglvoice-media/media.go index 24e2180e..a83fc442 100644 --- a/services/oglvoice-media/media.go +++ b/services/oglvoice-media/media.go @@ -49,6 +49,19 @@ func roomID(a admission) string { strings.ReplaceAll(strings.ToLower(a.RegionID), "-", "") } +// A dedicated media host needs bounded, firewallable UDP sockets for Firestorm ICE. +func newViewerPeerConnection(cfg config, iceServers []webrtc.ICEServer) (*webrtc.PeerConnection, error) { + configuration := webrtc.Configuration{ICEServers: iceServers} + if cfg.WebRTCPortMin == 0 { + return webrtc.NewPeerConnection(configuration) + } + settings := webrtc.SettingEngine{} + if err := settings.SetEphemeralUDPPortRange(cfg.WebRTCPortMin, cfg.WebRTCPortMax); err != nil { + return nil, err + } + return webrtc.NewAPI(webrtc.WithSettingEngine(settings)).NewPeerConnection(configuration) +} + func startPeer(cfg config, a admission, id string, onClose func()) (*peerState, error) { p := &peerState{id: id, admission: a, onClose: onClose, lastSeen: time.Now()} p.touch() @@ -59,7 +72,7 @@ func startPeer(cfg config, a admission, id string, onClose func()) (*peerState, iceServers = append(iceServers, webrtc.ICEServer{URLs: []string{trimmed}}) } } - pc, err := webrtc.NewPeerConnection(webrtc.Configuration{ICEServers: iceServers}) + pc, err := newViewerPeerConnection(cfg, iceServers) if err != nil { return nil, fmt.Errorf("Pion: %w", err) } p.pc = pc diff --git a/services/oglvoice-media/security.go b/services/oglvoice-media/security.go index 7368d00c..453a8021 100644 --- a/services/oglvoice-media/security.go +++ b/services/oglvoice-media/security.go @@ -50,6 +50,8 @@ type config struct { LiveKitSecret string `json:"-"` Bind string `json:"-"` PublicURL string `json:"-"` + WebRTCPortMin uint16 `json:"-"` + WebRTCPortMax uint16 `json:"-"` } func loadConfig() (config, error) { @@ -67,6 +69,22 @@ func loadConfig() (config, error) { if cfg.LiveKitURL == "" || cfg.LiveKitKey == "" || len(cfg.LiveKitSecret) < 32 { return cfg, errors.New("LiveKit URL/API credentials missing or too short") } + // Constrain Pion ICE sockets to a firewallable range on a dedicated vServer. + // Both values must be present; default retains the existing behavior. + rawMin := strings.TrimSpace(os.Getenv("OGLVOICE_WEBRTC_PORT_MIN")) + rawMax := strings.TrimSpace(os.Getenv("OGLVOICE_WEBRTC_PORT_MAX")) + if rawMin != "" || rawMax != "" { + if rawMin == "" || rawMax == "" { + return cfg, errors.New("OGLVOICE_WEBRTC_PORT_MIN and MAX must be set together") + } + minPort, minErr := strconv.ParseUint(rawMin, 10, 16) + maxPort, maxErr := strconv.ParseUint(rawMax, 10, 16) + if minErr != nil || maxErr != nil || minPort < 1024 || + maxPort < minPort || maxPort-minPort < 63 { + return cfg, errors.New("OGLVoice WebRTC UDP port range invalid (require at least 64 ports, min >=1024)") + } + cfg.WebRTCPortMin, cfg.WebRTCPortMax = uint16(minPort), uint16(maxPort) + } if len(cfg.Nodes) == 0 || len(cfg.Tenants) == 0 { return cfg, errors.New("media node ACL and tenant registry must not be empty") }