惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
爱范儿
爱范儿
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
宝玉的分享
宝玉的分享
T
Tailwind CSS Blog
博客园_首页
IT之家
IT之家
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
有赞技术团队
有赞技术团队
大猫的无限游戏
大猫的无限游戏
雷峰网
雷峰网
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 司徒正美
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
Jina AI
Jina AI
月光博客
月光博客
小众软件
小众软件
S
SegmentFault 最新的问题
量子位
阮一峰的网络日志
阮一峰的网络日志
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知

Recent Commits to openclaw:main

test: merge chat side-result checks · openclaw/openclaw@ddd2c2a test: merge cron history checks · openclaw/openclaw@f7eb746 test: merge responsive navigation shell checks · openclaw/openclaw@c2e4b47 docs(changelog): add codex oauth fixes · openclaw/openclaw@628e6cd test: merge navigation routing cases · openclaw/openclaw@5d8cecb Tests: mock channel registry bundled fallback · openclaw/openclaw@2b08233 Secrets: avoid broad web search discovery for single plugin config · openclaw/openclaw@a464f59 test: merge config view browser checks · openclaw/openclaw@20cf511 fix(status): align oauth health with runtime · openclaw/openclaw@eed7116 feat: add macOS screen snapshots for monitor preview (#67954) thanks … · openclaw/openclaw@f377db1 fix: report shared auth scopes in hello-ok (#67810) thanks @BunsDev · openclaw/openclaw@0b6c39b Auto-reply: avoid eager bundled route fallback · openclaw/openclaw@3ea1bf4 Tests: narrow session binding contract setup · openclaw/openclaw@54e4e16 fix(macOS): enable undo/redo in webchat composer text input (#34962) · openclaw/openclaw@00951dc Tests: speed up channel setup promotion · openclaw/openclaw@82b529a Docs: refresh agent instructions · openclaw/openclaw@5775fe2 fix(auth): serialize OAuth refresh across agents to fix #26322 (#67876) · openclaw/openclaw@8e79080 test: allow ollama public surface boundary test · openclaw/openclaw@7d4f1a6 Docs: add test performance guardrails · openclaw/openclaw@89706d3 Tests: restore context-engine usage proof · openclaw/openclaw@e4c4f95 Tests: slim context engine runtime coverage · openclaw/openclaw@74c198f ci: retry failed custom checkouts · openclaw/openclaw@0ee5baf test: trim duplicate provider auth onboarding cases · openclaw/openclaw@1ffc02e matrix: fix sessions_spawn --thread subagent session spawning (#67643) · openclaw/openclaw@1ce2596 test: reduce auth choice fixture churn · openclaw/openclaw@857b9cd test: mock health status config boundaries · openclaw/openclaw@9d5ab4a test: mock onboard config io boundary · openclaw/openclaw@299694d test: mock legacy state plugin boundaries · openclaw/openclaw@2713089 test: mock channel install boundaries · openclaw/openclaw@b945248 test: mock doctor preview channel boundaries · openclaw/openclaw@b1a3ad4
fix(daemon): handle sudo user-systemd gateway install fai...
vincentkoc · 2026-04-27 · via Recent Commits to openclaw:main

@@ -81,6 +81,10 @@ function assertMachineUserSystemctlArgs(args: string[], user: string, ...command

8181

expect(args).toEqual(["--machine", `${user}@`, "--user", ...command]);

8282

}

838384+

function mockEffectiveUid(uid: number) {

85+

vi.spyOn(process, "geteuid").mockReturnValue(uid);

86+

}

87+8488

async function readManagedServiceEnabled(env: NodeJS.ProcessEnv = { HOME: TEST_MANAGED_HOME }) {

8589

vi.spyOn(fs, "access").mockResolvedValue(undefined);

8690

return isSystemdServiceEnabled({ env });

@@ -190,6 +194,7 @@ describe("systemd availability", () => {

190194

});

191195192196

it("does not fall back to direct --user when machine scope fails under sudo", async () => {

197+

mockEffectiveUid(0);

193198

execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => {

194199

assertMachineUserSystemctlArgs(args, "ai", "status");

195200

cb(

@@ -205,6 +210,36 @@ describe("systemd availability", () => {

205210

await expect(isSystemdUserServiceAvailable({ SUDO_USER: "ai" })).resolves.toBe(false);

206211

expect(execFileMock).toHaveBeenCalledTimes(1);

207212

});

213+214+

it("does not let preserved USER suppress sudo-to-root machine scope", async () => {

215+

mockEffectiveUid(0);

216+

execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => {

217+

assertMachineUserSystemctlArgs(args, "debian", "status");

218+

cb(null, "", "");

219+

});

220+221+

await expect(

222+

isSystemdUserServiceAvailable({

223+

SUDO_USER: "debian",

224+

USER: "root-env-stale",

225+

LOGNAME: "root-env-stale",

226+

}),

227+

).resolves.toBe(true);

228+

expect(execFileMock).toHaveBeenCalledTimes(1);

229+

});

230+231+

it("does not let stale SUDO_USER override a sudo-u target user scope", async () => {

232+

mockEffectiveUid(1000);

233+

execFileMock.mockImplementationOnce((_cmd, args, _opts, cb) => {

234+

assertUserSystemctlArgs(args, "status");

235+

cb(null, "", "");

236+

});

237+238+

await expect(

239+

isSystemdUserServiceAvailable({ USER: "openclaw", SUDO_USER: "admin" }),

240+

).resolves.toBe(true);

241+

expect(execFileMock).toHaveBeenCalledTimes(1);

242+

});

208243

});

209244210245

describe("isSystemdServiceEnabled", () => {

@@ -907,6 +942,51 @@ describe("systemd service install and uninstall", () => {

907942

});

908943

});

909944945+

it("uses the sudo-u target user for install activation machine-scope retry", async () => {

946+

await withNodeSystemdFixture(async ({ env }) => {

947+

const installEnv = { ...env, USER: "openclaw", SUDO_USER: "admin" };

948+

execFileMock

949+

.mockImplementationOnce((_cmd, args, _opts, cb) => {

950+

assertUserSystemctlArgs(args, "status");

951+

cb(null, "", "");

952+

})

953+

.mockImplementationOnce((_cmd, args, _opts, cb) => {

954+

assertUserSystemctlArgs(args, "daemon-reload");

955+

cb(null, "", "");

956+

})

957+

.mockImplementationOnce((_cmd, args, _opts, cb) => {

958+

assertUserSystemctlArgs(args, "enable", NODE_SERVICE);

959+

cb(

960+

createExecFileError("Failed to connect to bus: No medium found", {

961+

stderr: "Failed to connect to bus: No medium found",

962+

}),

963+

"",

964+

"",

965+

);

966+

})

967+

.mockImplementationOnce((_cmd, args, _opts, cb) => {

968+

assertMachineUserSystemctlArgs(args, "openclaw", "enable", NODE_SERVICE);

969+

cb(null, "", "");

970+

})

971+

.mockImplementationOnce((_cmd, args, _opts, cb) => {

972+

assertUserSystemctlArgs(args, "restart", NODE_SERVICE);

973+

cb(null, "", "");

974+

});

975+976+

await installSystemdService({

977+

env: installEnv,

978+

stdout: { write: vi.fn() } as unknown as NodeJS.WritableStream,

979+

programArguments: ["/usr/bin/openclaw", "node", "run"],

980+

workingDirectory: "/tmp",

981+

environment: {

982+

OPENCLAW_SYSTEMD_UNIT: "openclaw-node",

983+

},

984+

});

985+986+

expect(execFileMock).toHaveBeenCalledTimes(5);

987+

});

988+

});

989+910990

it("surfaces install activation user-bus failures as systemd unavailable errors", async () => {

911991

await withNodeSystemdFixture(async ({ env }) => {

912992

vi.spyOn(os, "userInfo").mockImplementation(() => {

@@ -1066,6 +1146,7 @@ describe("systemd service control", () => {

10661146

});

1067114710681148

it("targets the sudo caller's user scope when SUDO_USER is set", async () => {

1149+

mockEffectiveUid(0);

10691150

execFileMock

10701151

.mockImplementationOnce((_cmd, args, _opts, cb) => {

10711152

assertMachineUserSystemctlArgs(args, "debian", "status");