0.4.1
All checks were successful
release-tag / release-image (push) Successful in 2m4s
release-main / release-images (push) Successful in 3m38s

This commit is contained in:
2026-08-23 00:05:58 +02:00
parent e104e7289f
commit 1b29cbb39d
10 changed files with 137 additions and 24 deletions

View File

@@ -1,5 +1,14 @@
# Changelog
## 0.4.1 — RemoteApp PowerShell/CLIXML robustness
- RemoteApp PowerShell execution now keeps stderr separate from JSON stdout.
- Suppresses PowerShell progress/information/verbose/debug/warning streams for machine-readable RemoteApp calls.
- Forces UTF-8 console output where supported.
- JSON decoder defensively extracts the first valid JSON object/array and tolerates CLIXML/banner noise before or after the payload.
- Added regression tests for the `#< CLIXML` contamination observed on Windows PowerShell 5.1.
- Protocol remains version 4; no Master/Agent schema migration is required.
## 0.4.0 — Agent-managed RemoteApps
- Added a farm-scoped RemoteApp desired-state model to Published Resources.

View File

@@ -2,10 +2,14 @@
SessionGuard is a Go-based **RDS control plane** for Windows Remote Desktop Session Hosts. It is designed to complement Apache Guacamole: Guacamole remains the HTML5/RDP gateway, while SessionGuard provides Citrix-like broker, Director, policy, profile-lifecycle and operations functions.
**Current development version: 0.4.0 (RemoteApp control plane)**
**Current development version: 0.4.1 (RemoteApp PowerShell/CLIXML robustness)**
> SessionGuard is not an ICA/HDX implementation and does not replace the Windows RDS runtime. It deliberately reuses standard RDP/WTS, Guacamole and PocketID/OIDC.
## 0.4.1 RemoteApp robustness
Windows PowerShell auxiliary streams are now isolated from the JSON protocol used by RemoteApp discovery/reconciliation. CLIXML/progress noise no longer breaks RemoteApp status decoding.
## 0.4.0 RemoteApp control plane
- The Master can define RemoteApp desired state per Published Resource/Farm.

View File

@@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>info.hilden.sessionguard</groupId>
<artifactId>sessionguard-guacamole</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
<packaging>jar</packaging>
<properties>
<maven.compiler.release>11</maven.compiler.release>

View File

@@ -25,7 +25,7 @@ import (
"github.com/example/sessionguard/internal/windowsx"
)
const Version = "0.4.0"
const Version = "0.4.1"
type App struct {
cfg config.Agent

View File

@@ -36,7 +36,7 @@ button{display:inline-flex;align-items:center;justify-content:center;gap:6px;bac
@media(max-width:720px){.agent-metrics{grid-template-columns:repeat(2,1fr)}.app-shell{display:block}.sidebar{position:fixed;left:0;top:0;transform:translateX(-102%);width:min(290px,86vw);transition:transform .2s ease;box-shadow:var(--shadow)}body.nav-open .sidebar{transform:translateX(0)}body.nav-open .mobile-overlay{display:block;position:fixed;inset:0;background:rgba(0,0,0,.48);z-index:25}.menu-toggle{display:inline-flex}.topbar{height:60px}.live-pill{display:none}.page{padding:14px}.metrics{grid-template-columns:repeat(2,1fr)}.section-heading{align-items:flex-start;flex-direction:column}.table th,.table td{white-space:nowrap}.form{padding:13px}}
@media(max-width:430px){.metrics{grid-template-columns:1fr 1fr}.metric-card,.card{min-height:88px;padding:12px}.value{font-size:22px}.topbar-actions .theme-top{display:none}}
</style></head><body>
<div class="mobile-overlay" id="mobileOverlay"></div><div class="app-shell"><aside class="sidebar" id="sidebar"><div class="brand-block"><div class="logo">SG</div><div><div class="brand-name">SessionGuard</div><div class="brand-sub">Local Agent · v0.4.0</div></div></div><nav class="nav-group"><div class="nav-label">Server</div><a class="nav-link active" href="#overview"><span class="nav-icon">⌂</span>Übersicht</a><a class="nav-link" href="#sessions-section"><span class="nav-icon">▶</span>Sitzungen</a><a class="nav-link" href="#remoteapps-section"><span class="nav-icon">◇</span>RemoteApps</a><a class="nav-link" href="#profiles-section"><span class="nav-icon">↕</span>Profil-Pipeline</a><a class="nav-link" href="#events-section"><span class="nav-icon">≋</span>Aktivitätslog</a><a class="nav-link" href="#policy-section"><span class="nav-icon">⚙</span>Lokale Policy</a></nav><div class="sidebar-spacer"></div><div class="sidebar-footer"><button class="secondary theme-toggle" id="themeToggle" type="button">◐ Theme wechseln</button><form action="/logout" method="post"><button class="ghost" style="width:100%">Abmelden</button></form></div></aside>
<div class="mobile-overlay" id="mobileOverlay"></div><div class="app-shell"><aside class="sidebar" id="sidebar"><div class="brand-block"><div class="logo">SG</div><div><div class="brand-name">SessionGuard</div><div class="brand-sub">Local Agent · v0.4.1</div></div></div><nav class="nav-group"><div class="nav-label">Server</div><a class="nav-link active" href="#overview"><span class="nav-icon">⌂</span>Übersicht</a><a class="nav-link" href="#sessions-section"><span class="nav-icon">▶</span>Sitzungen</a><a class="nav-link" href="#remoteapps-section"><span class="nav-icon">◇</span>RemoteApps</a><a class="nav-link" href="#profiles-section"><span class="nav-icon">↕</span>Profil-Pipeline</a><a class="nav-link" href="#events-section"><span class="nav-icon">≋</span>Aktivitätslog</a><a class="nav-link" href="#policy-section"><span class="nav-icon">⚙</span>Lokale Policy</a></nav><div class="sidebar-spacer"></div><div class="sidebar-footer"><button class="secondary theme-toggle" id="themeToggle" type="button">◐ Theme wechseln</button><form action="/logout" method="post"><button class="ghost" style="width:100%">Abmelden</button></form></div></aside>
<div class="app-main"><header class="topbar"><div class="topbar-left"><button class="secondary menu-toggle" id="menuToggle" type="button">☰</button><div><div class="topbar-title">Lokaler Agent</div><div class="topbar-sub" id="host">Lokaler Terminalserver</div></div></div><div class="topbar-actions"><span class="live-pill"><span class="live-dot"></span>Live · 5s</span><button class="secondary theme-top" id="themeTop" type="button">◐</button></div></header>
<main class="page"><section class="page-section" id="overview"><div class="section-heading"><div><div class="eyebrow">Local Control</div><h1>Terminalserver-Status</h1><div class="section-copy">Sitzungen, Profil-Pipeline und Master-Verbindung lokal überwachen.</div></div></div><div class="metrics agent-metrics"><div class="metric-card"><div class="metric-head"><span class="metric-label">Aktiv</span><span class="metric-icon">▶</span></div><div class="value" id="active"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">Getrennt</span><span class="metric-icon">Ⅱ</span></div><div class="value" id="disc"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">Sitzungen</span><span class="metric-icon">◎</span></div><div class="value" id="total"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">Profil-Jobs</span><span class="metric-icon">↕</span></div><div class="value" id="profileJobs"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">Cleanup</span><span class="metric-icon">⌫</span></div><div class="value" id="pending"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">RemoteApps</span><span class="metric-icon">◇</span></div><div class="value" id="remoteAppCount"></div></div><div class="metric-card"><div class="metric-head"><span class="metric-label">Master</span><span class="metric-icon">⇄</span></div><div class="value" style="font-size:14px;margin-top:14px" id="master"></div></div></div></section>
<section class="page-section" id="sessions-section"><div class="section-heading"><div><div class="eyebrow">RDS</div><h2>Sitzungen</h2><div class="section-copy">Aktive und getrennte Benutzer sowie administrative Aktionen.</div></div></div><section class="panel"><div id="sessions"></div></section></section>
@@ -44,7 +44,7 @@ button{display:inline-flex;align-items:center;justify-content:center;gap:6px;bac
<section class="page-section" id="profiles-section"><div class="section-heading"><div><div class="eyebrow">Profile</div><h2>Profil-Pipeline</h2><div class="section-copy">Backup, Restore, Retry und Cleanup-Status pro Benutzer.</div></div></div><section class="panel"><div id="profiles"></div></section></section>
<section class="page-section" id="events-section"><div class="section-heading"><div><div class="eyebrow">Telemetry</div><h2>Aktivitäts- & Audit-Log</h2><div class="section-copy">Dry-Run, Profilaktionen, Fehler und lokale Ereignisse.</div></div></div><section class="panel"><div id="events"></div></section></section>
<section class="page-section" id="policy-section"><div class="section-heading"><div><div class="eyebrow">Configuration</div><h2>Lokale Policy</h2><div class="section-copy">Fallback-Konfiguration für Profile, Sessions, Cleanup und Templates.</div></div></div><section class="panel"><div id="policy"></div></section></section>
</main></div></div><script src="/app.js?v=0.4.0"></script></body></html>`
</main></div></div><script src="/app.js?v=0.4.1"></script></body></html>`
const agentJS = `
let policyTemplates=[],profileFolders=[],lastSnapshot=null,policyDirty=false,policyLoaded=false;

View File

@@ -23,7 +23,7 @@ import (
"github.com/example/sessionguard/internal/model"
)
const Version = "0.4.0"
const Version = "0.4.1"
type App struct {
cfg config.Master

View File

@@ -37,7 +37,7 @@ button{display:inline-flex;align-items:center;justify-content:center;gap:6px;bac
@media(max-width:430px){.metrics{grid-template-columns:1fr 1fr}.metric-card,.card{min-height:88px;padding:12px}.value{font-size:22px}.topbar-actions .theme-top{display:none}}
</style></head><body>
<div class="mobile-overlay" id="mobileOverlay"></div><div class="app-shell">
<aside class="sidebar" id="sidebar"><div class="brand-block"><div class="logo">SG</div><div><div class="brand-name">SessionGuard</div><div class="brand-sub">Control Plane · v0.4.0</div></div></div>
<aside class="sidebar" id="sidebar"><div class="brand-block"><div class="logo">SG</div><div><div class="brand-name">SessionGuard</div><div class="brand-sub">Control Plane · v0.4.1</div></div></div>
<nav class="nav-group"><div class="nav-label">Übersicht</div><a class="nav-link active" href="#overview"><span class="nav-icon">⌂</span>Dashboard</a><a class="nav-link" href="#servers"><span class="nav-icon">▣</span>Terminalserver</a><a class="nav-link" href="#farms-section"><span class="nav-icon">⌘</span>Farms & Broker</a><a class="nav-link" href="#resources-section"><span class="nav-icon">◆</span>Apps & Desktops</a></nav>
<nav class="nav-group"><div class="nav-label">Betrieb</div><a class="nav-link" href="#history-section"><span class="nav-icon">↻</span>Session-Historie</a><a class="nav-link" href="#policies-section"><span class="nav-icon">≋</span>Policy-Historie</a><a class="nav-link" href="#alerts-section"><span class="nav-icon">!</span>Alerts</a><a class="nav-link" href="#audit-section"><span class="nav-icon">✓</span>Audit-Log</a></nav>
<div class="sidebar-spacer"></div><div class="sidebar-footer"><button class="secondary theme-toggle" id="themeToggle" type="button">◐ Theme wechseln</button><form action="/logout" method="post"><button class="ghost" style="width:100%">Abmelden</button></form></div></aside>
@@ -51,7 +51,7 @@ button{display:inline-flex;align-items:center;justify-content:center;gap:6px;bac
<section class="page-section" id="policies-section"><div class="section-heading"><div><div class="eyebrow">Governance</div><h2>Policy-Historie & Rollback</h2><div class="section-copy">Revisionen vergleichen und frühere Sollstände wieder aktivieren.</div></div></div><section class="panel"><div id="policyHistory" class="content"></div></section></section>
<section class="page-section" id="alerts-section"><div class="section-heading"><div><div class="eyebrow">Monitoring</div><h2>Alerts</h2><div class="section-copy">Aktive und gelöste Betriebswarnungen.</div></div></div><section class="panel"><div id="alerts" class="content"></div></section></section>
<section class="page-section" id="audit-section"><div class="section-heading"><div><div class="eyebrow">Compliance</div><h2>Audit-Log</h2><div class="section-copy">Administrative Änderungen und Aktionen revisionsfreundlich nachvollziehen.</div></div></div><section class="panel"><div id="audit" class="content"></div></section></section>
</main></div></div><div class="toast" id="toast"></div><script src="/app.js?v=0.4.0"></script></body></html>`
</main></div></div><div class="toast" id="toast"></div><script src="/app.js?v=0.4.1"></script></body></html>`
const masterJS = `
let selected=null,current=null,editorAgent=null,resourceEditID=null,policyTemplates=[],profileFolders=[],agentCache=[],farmCache=[],resourceCache=[],brokerLeases=[],policyHistory=[],me=null;const $=id=>document.getElementById(id);const esc=s=>String(s??'').replace(/[&<>"']/g,c=>({'&':'&amp;','<':'&lt;','>':'&gt;','"':'&quot;',"'":'&#39;'}[c]));function when(v){if(!v)return'';let d=new Date(v);return Number.isNaN(d.getTime())||d.getFullYear()<2000?'':d.toLocaleString('de-DE')}function bytes(n){if(!n)return'';let u=['B','KB','MB','GB','TB'],i=0;while(n>=1024&&i<u.length-1){n/=1024;i++}return n.toFixed(i>1?1:0)+' '+u[i]}function toast(t){let e=$('toast');e.textContent=t;e.style.display='block';setTimeout(()=>e.style.display='none',3000)}async function api(u,o){let r=await fetch(u,o);if(r.status===401){location='/login';return}let j=await r.json().catch(()=>({}));if(!r.ok)throw new Error(j.error||r.statusText);return j}function lines(id){return $(id).value.split('\n').map(x=>x.trim()).filter(Boolean)}

View File

@@ -0,0 +1,55 @@
package windowsx
import (
"encoding/json"
"fmt"
"strings"
)
// decodePowerShellJSON extracts the first JSON value from PowerShell stdout.
// Windows PowerShell can occasionally surround redirected output with startup,
// progress, or CLIXML noise. The command runner keeps stderr separate, but this
// parser is deliberately defensive so a valid JSON payload is not discarded
// merely because a host emits an unexpected banner before/after it.
func decodePowerShellJSON(raw string, out any) error {
raw = strings.TrimSpace(strings.TrimPrefix(raw, "\ufeff"))
if raw == "" {
raw = "[]"
}
payload, err := firstJSONValue(raw)
if err != nil {
return fmt.Errorf("no JSON value in PowerShell output: %w (output=%q)", err, raw)
}
payload = strings.TrimSpace(payload)
// Windows PowerShell/ConvertTo-Json may return a single object when only one
// item exists. RemoteApp callers always decode into a slice, so normalize it.
if strings.HasPrefix(payload, "{") {
payload = "[" + payload + "]"
}
if err := json.Unmarshal([]byte(payload), out); err != nil {
return fmt.Errorf("decode PowerShell JSON: %w (json=%q, output=%q)", err, payload, raw)
}
return nil
}
func firstJSONValue(raw string) (string, error) {
var lastErr error
for i := 0; i < len(raw); i++ {
if raw[i] != '[' && raw[i] != '{' {
continue
}
dec := json.NewDecoder(strings.NewReader(raw[i:]))
var msg json.RawMessage
if err := dec.Decode(&msg); err != nil {
lastErr = err
continue
}
return string(msg), nil
}
if lastErr == nil {
lastErr = fmt.Errorf("missing JSON object/array delimiter")
}
return "", lastErr
}

View File

@@ -0,0 +1,40 @@
package windowsx
import (
"testing"
"github.com/example/sessionguard/internal/model"
)
func TestDecodePowerShellJSONCleanArray(t *testing.T) {
var got []model.RemoteAppStatus
if err := decodePowerShellJSON(`[{"alias":"Calc","published":true}]`, &got); err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].Alias != "Calc" || !got[0].Published {
t.Fatalf("unexpected result: %#v", got)
}
}
func TestDecodePowerShellJSONSingleObject(t *testing.T) {
var got []model.RemoteAppStatus
if err := decodePowerShellJSON(`{"alias":"Calc","published":true}`, &got); err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].Alias != "Calc" {
t.Fatalf("unexpected result: %#v", got)
}
}
func TestDecodePowerShellJSONIgnoresCLIXMLNoise(t *testing.T) {
raw := "#< CLIXML\r\n" +
`[{"resource_id":"281750fc5851c7fd","alias":"Rechner","display_name":"Rechner","path":"C:\\Windows\\system32\\win32calc.exe","path_exists":true,"published":true,"managed":true,"in_sync":true}]` +
"\r\nSystem.Management.Automation.PSCustomObjectSystem.Object1Module werden fuer erstmalige Verwendung vorbereitet."
var got []model.RemoteAppStatus
if err := decodePowerShellJSON(raw, &got); err != nil {
t.Fatal(err)
}
if len(got) != 1 || got[0].Alias != "Rechner" || got[0].Path != `C:\Windows\system32\win32calc.exe` {
t.Fatalf("unexpected result: %#v", got)
}
}

View File

@@ -3,6 +3,7 @@
package windowsx
import (
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
@@ -180,29 +181,33 @@ ConvertTo-Json -InputObject @($results) -Compress -Depth 5`, payload)
}
func runPowerShellJSON(script string, out any) error {
encoded := encodePowerShell(script)
// Suppress PowerShell's auxiliary streams. On Windows PowerShell 5.1 these
// can otherwise be serialized as "#< CLIXML" when handles are redirected.
// stderr is also kept separate from stdout so progress/information records
// can never corrupt the JSON protocol used between PowerShell and the agent.
preamble := `$ProgressPreference='SilentlyContinue'
$InformationPreference='SilentlyContinue'
$VerbosePreference='SilentlyContinue'
$DebugPreference='SilentlyContinue'
$WarningPreference='SilentlyContinue'
try { [Console]::OutputEncoding = New-Object System.Text.UTF8Encoding($false) } catch {}
`
encoded := encodePowerShell(preamble + script)
cmd := exec.Command("powershell.exe", "-NoLogo", "-NoProfile", "-NonInteractive", "-ExecutionPolicy", "Bypass", "-EncodedCommand", encoded)
b, err := cmd.CombinedOutput()
var stderr bytes.Buffer
cmd.Stderr = &stderr
b, err := cmd.Output()
if err != nil {
msg := strings.TrimSpace(string(b))
msg := strings.TrimSpace(stderr.String())
if msg == "" {
msg = strings.TrimSpace(string(b))
}
if msg == "" {
msg = err.Error()
}
return fmt.Errorf("PowerShell: %s", msg)
}
raw := strings.TrimSpace(string(b))
if raw == "" {
raw = "[]"
}
// ConvertTo-Json emits an object instead of an array when there is exactly
// one item on older Windows PowerShell. Accept both forms.
if strings.HasPrefix(raw, "{") {
raw = "[" + raw + "]"
}
if err := json.Unmarshal([]byte(raw), out); err != nil {
return fmt.Errorf("decode PowerShell JSON: %w (output=%q)", err, raw)
}
return nil
return decodePowerShellJSON(string(b), out)
}
func encodePowerShell(script string) string {