Daemon: harden WSL2 systemctl install checks (#39294)

* Daemon: harden WSL2 systemctl install checks

* Changelog: note WSL2 daemon install hardening

* Daemon: tighten systemctl failure classification
This commit is contained in:
Vincent Koc
2026-03-07 19:43:19 -05:00
committed by GitHub
parent f195af0b22
commit a56841b98c
7 changed files with 286 additions and 1 deletions

View File

@@ -278,6 +278,37 @@ function isSystemdUnitNotEnabled(detail: string): boolean {
);
}
function isSystemctlBusUnavailable(detail: string): boolean {
if (!detail) {
return false;
}
const normalized = detail.toLowerCase();
return (
normalized.includes("failed to connect to bus") ||
normalized.includes("failed to connect to user scope bus") ||
normalized.includes("dbus_session_bus_address") ||
normalized.includes("xdg_runtime_dir") ||
normalized.includes("no medium found")
);
}
function isGenericSystemctlIsEnabledFailure(detail: string): boolean {
if (!detail) {
return false;
}
const normalized = detail.toLowerCase().trim();
return (
normalized.startsWith("command failed: systemctl") &&
normalized.includes(" is-enabled ") &&
!normalized.includes("permission denied") &&
!normalized.includes("access denied") &&
!normalized.includes("no space left") &&
!normalized.includes("read-only file system") &&
!normalized.includes("out of memory") &&
!normalized.includes("cannot allocate memory")
);
}
function resolveSystemctlDirectUserScopeArgs(): string[] {
return ["--user"];
}
@@ -538,7 +569,12 @@ export async function isSystemdServiceEnabled(args: GatewayServiceEnvArgs): Prom
return true;
}
const detail = readSystemctlDetail(res);
if (isSystemctlMissing(detail) || isSystemdUnitNotEnabled(detail)) {
if (
isSystemctlMissing(detail) ||
isSystemdUnitNotEnabled(detail) ||
isSystemctlBusUnavailable(detail) ||
isGenericSystemctlIsEnabledFailure(detail)
) {
return false;
}
throw new Error(`systemctl is-enabled unavailable: ${detail || "unknown error"}`.trim());