fix: handle missing systemctl in containers (#26089)#26699
Conversation
2025351 to
d801792
Compare
|
@aisle-research-bot review |
🔒 Aisle Security AnalysisWe found 1 potential security issue(s) in this PR:
1. 🟡 Systemd service status check masks systemctl errors (false “disabled” result)
Description
This introduces an error-masking / state-confusion bug:
Concrete call paths affected (Linux):
As a result, a user-session/DBus issue or PATH/systemctl execution failure can cause the CLI to silently treat a running/enabled systemd user service as “disabled”, potentially leaving the gateway running when the user believes it has been stopped/uninstalled/reset. RecommendationTreat
export async function isSystemdServiceEnabled(args: GatewayServiceEnvArgs): Promise<boolean> {
await assertSystemdAvailable();
const serviceName = resolveSystemdServiceName(args.env ?? {});
const unitName = `${serviceName}.service`;
const res = await execSystemctl(["--user", "is-enabled", unitName]);
return res.code === 0;
}
export async function isSystemdServiceEnabled(args: GatewayServiceEnvArgs): Promise<boolean | null> {
const serviceName = resolveSystemdServiceName(args.env ?? {});
const unitName = `${serviceName}.service`;
const res = await execSystemctl(["--user", "is-enabled", unitName]);
if (res.code === 0) return true;
const detail = readSystemctlDetail(res);
// Known “not enabled” states -> false
if (/\b(disabled|static|indirect|masked)\b/i.test(detail)) return false;
// Execution/bus/session problems -> unknown
throw new Error(`systemctl is-enabled failed: ${detail || "unknown error"}`);
}Also consider using Analyzed PR: #26699 at commit Last updated on: 2026-03-02T05:41:11Z |
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org>
…w#26699) * Daemon: handle missing systemctl in containers * Daemon: harden missing-systemctl detection * Daemon tests: cover systemctl spawn failure path * Changelog: note container systemctl service-check fix * Update CHANGELOG.md * Daemon: fail closed on unknown systemctl is-enabled errors * Daemon tests: cover is-enabled unknown-error path --------- Co-authored-by: Vincent Koc <vincentkoc@ieee.org> (cherry picked from commit cda119b)
Summary
Describe the problem and fix in 2–5 bullets:
Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Security Impact (required)
Repro + Verification
Environment
Steps
Expected
Container starts successfully, application listens on port 18789
Actual (before fix)
Container crashes with error: systemctl --user unavailable: spawn systemctl ENOENT
Evidence
Attach at least one:
Before fix: The existing tests would fail in CI environments where systemctl is not available, or the code would throw unhandled errors in containers.
After fix: All tests pass:
✓ src/daemon/systemd.test.ts (17 tests)
Test Files: 1 passed (1)
Tests: 17 passed (17)
Human Verification (required)
Compatibility / Migration
Failure Recovery (if this breaks)
Risks and Mitigations
PR generated with OpenCode and MiniMax M2.5
Build plan prompt-
Implementation Plan: Fix systemctl unavailable in Docker container deployment
Issue: #26089
maybeExplainGatewayServiceStop()which attempts to check systemd status viasystemctl --user status. In Docker containers where systemctl doesn't exist, this throws an unhandled error.systemctl --user unavailable: spawn systemctl ENOENTmaybeExplainGatewayServiceStop()insrc/cli/gateway-cli/shared.tsservice.isLoaded()→isSystemdServiceEnabled()→assertSystemdAvailable()assertSystemdAvailable()triessystemctl --user status→ ENOENT in containers where systemctl doesn't existBranch Name
fix/issue-26089-systemctl-unavailable-dockerImplementation Steps
Step 1: Create branch and establish baseline
git checkout -b fix/issue-26089-systemctl-unavailable-dockerpnpm installpnpm buildpnpm checkpnpm testStep 2: Add isSystemctlPresent() function
src/daemon/systemd.ts, add new function:isSystemctlPresent()insrc/daemon/systemd.test.tsStep 3: Modify isSystemdServiceEnabled()
falsegracefully if systemctl is not available (instead of throwing)Step 4: Modify assertSystemdAvailable()
Step 5: Modify readSystemdServiceRuntime()
{ status: 'unknown', detail: '...' }instead of throwingStep 6: Modify install/uninstall functions
installSystemdService()to check systemctl availability firstuninstallSystemdService()to handle missing systemctlStep 7: Verify maybeExplainGatewayServiceStop() handles errors
src/cli/gateway-cli/shared.ts, ensure error handling aroundisLoaded()callStep 8: Run tests and verify
pnpm testpnpm tsgopnpm checkStep 9: Commit changes
pnpm buildpnpm testpnpm formatscripts/committer "Daemon: handle missing systemctl in containers" <files>Step 10: Push and create PR
git push -u fork fix/issue-26089-systemctl-unavailable-dockerCI/CD Tests to Run Locally
Before pushing:
pnpm buildpnpm tsgopnpm checkpnpm formatpnpm testpnpm protocol:checkKey Files to Modify
src/daemon/systemd.ts- AddisSystemctlPresent()and graceful error handlingsrc/daemon/systemd.test.ts- Add tests for new behaviorsrc/cli/gateway-cli/shared.ts- Handle errors inmaybeExplainGatewayServiceStop()NOT Doing (Decision)
Expected Outcome
Greptile Summary
Added
isSystemctlPresent()function to check for systemctl binary availability before attempting systemd operations, preventing crashes in containerized environments where systemctl doesn't exist.isSystemdServiceEnabled()to returnfalsegracefully when systemctl is absentreadSystemdServiceRuntime()to return statusunknownwith descriptive detail when systemctl is missinginstallSystemdService()anduninstallSystemdService()to check for systemctl presence firstassertSystemdAvailable()to provide clearer error messages distinguishing between missing binary and unavailable systemd user busConfidence Score: 5/5
Last reviewed commit: ceb08fd