Skip to content

fix: complete root updates of a system service that runs as another account - #207230

Open
fuller-stack-dev wants to merge 44 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-root-service-account-steps
Open

fuller-stack-dev wants to merge 44 commits into
openclaw:mainfrom
fuller-stack-dev:fix/update-root-service-account-steps

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Related: #204775
Follows: #206343

Status (2026-11-28): needs a maintainer decision before anything else. #207304 landed on main with a different, maintainer-directed design: root replaces only the package and restarts the unit, and the service's own boot runs as User= and owns migration. It keeps cross-account state checks refused when a shipped (published) updater drives the candidate. This PR instead makes that shipped-driver hop complete by running admission, migration, restore and the run record as the service account. The two designs now conflict in docs/install/updating.md, update-command-admit-service-account.ts and its test, so this branch does not merge as is. I have not resolved the conflict, because doing so would override the landed direction.

What Problem This Solves

A common Linux layout is a root-owned global npm package with a systemd system unit that runs the Gateway as a service account (User=openclaw, state in that account's home or the unit's OPENCLAW_STATE_DIR). Since #206343, sudo openclaw update on such an install stops before the package is replaced and prints a manual procedure. That protects the service's data, but the update never completes on its own.

User Impact

A plain sudo openclaw update now completes on this layout. Root replaces the package; every step that touches the service's state runs as the unit's account, with the unit's effective environment and --profile:

  • Before the package is replaced, the new release's update checks (config, database schemas, retired state) run as the service account against the service's state. A problem there stops the update with nothing changed.
  • After the package is replaced, root stops the unit. As the service account, the new release backs up the databases it migrates and the configuration and runs Doctor and the migrations (the existing update migrate). Root starts the unit and waits until systemd runs the new release and the service account's own openclaw gateway health reaches it.
  • Once the installed updater has exited, a transient root unit (openclaw-update-settle-<id>.service) writes the update record into the service's state as the service account (update finish), so the account's openclaw update status shows it, and retires the backup. If the installed updater put the previous package back after a later failure, that unit instead stops the service, restores its state as the service account and starts it again.

If the new release does not come ready, the state is restored as the service account (only after the unit is confirmed stopped), the step fails so the installed updater restores the previous package, and the unit starts again once that package is back. The new package is never started on restored state; if the stop or the restore cannot be confirmed, the unit stays stopped and the backup is kept, and the failure says where.

The #206343 refusal stays, with its procedure, when the steps cannot run as the account: numeric, empty or root User=; an account that does not resolve; a HOME it cannot write; no root-owned runuser; an unreadable effective environment (for example an EnvironmentFile= root cannot read) or sandboxing that hides the state; an invalid answer from the account's admission; and a caller whose state or config overlaps the service's, such as sudo env OPENCLAW_STATE_DIR=<service state> openclaw update (the installed updater would write that state as root before any candidate step runs). Each refusal names its reason. Single-account installs, units that run as the updating account, other installations and unrelated units are unchanged.

Why This Change Was Made

The installed updater cannot change, so the work sits in the two places a published updater calls into the new release: update admit before the swap and the update Doctor child (update-migrated-finalize --doctor) after it. Both reuse existing owners: unit discovery and the root-read effective environment (readSystemdServiceExecStartAsRoot), the immutable path's runuser switch (now one helper for both), the systemd identity and lifecycle owners for stop/start, and the externally supervised update migrate / restore / finish commands that already own the backup, Doctor migration, restore and run record. No new protocol, config option, flag, stored field or schema.

Trust boundary (for the service-owner and security review)

Root owns the package and the unit; the unit's account owns its state. Privilege only goes down:

  • Who decides the account and environment. Root re-derives everything from systemd and NSS: the unit's User= (must be a named, resolvable, non-root account), its effective environment read as root through the existing readSystemdServiceExecStartAsRoot reader (inline Environment= and EnvironmentFile=), the --profile in its ExecStart, and whether sandboxing (RootDirectory=, BindPaths=, PrivateTmp=, ProtectHome= and similar) hides the state. Nothing the service account wrote chooses the account, unit, environment or paths.
  • How root switches. Root runs only a root-owned runuser (/usr/sbin/runuser or /sbin/runuser, regular file, owner root, not group/other-writable) with a fixed PATH and nothing else; the unit's environment reaches the account's process through an owner-only file and applies only after the switch, so loader variables such as LD_PRELOAD from the unit never affect a root process, and no environment value appears in any argv. The account runs this release's own entry point (node <root>/dist/index.js update admit|migrate|restore|finish|gateway health). Both immutable-update runuser call sites now build their argv through the same helper (unchanged argv).
  • What root hands over. A fresh root-owned directory in root's sticky /tmp (checked: real directory, owner root, sticky bit), mode 0711, holding files created with O_EXCL, then fchown to the account and fchmod 0400: only the account can read them and nobody but root can replace them. Root never reads them back. They are removed when the step ends, or by the settle unit.
  • What root reads back. Only exit statuses and the last line of bounded output (admission verdict up to 1 MiB, parsed with the same parseUpdateAdmissionVerdict the installed updater uses, exit code and candidate version cross-checked, the combined verdict revalidated; migrate/restore/finish up to 256 KiB, reading only a ^[a-z-]{1,32}$ status word). No path from the account's output is used for anything. Readiness is decided by root from /proc/<MainPID>/cmdline and its own package.json, plus the exit status of the account's gateway health.
  • What root executes as root. systemctl/D-Bus start and stop of the selected unit (through the existing captureSystemdServiceIdentity with rootServiceAccount and the systemd lifecycle owner), systemd-run for the settle unit, and the package manager the installed updater already runs. The settle unit's script is a constant in this release; its single argument is JSON of root-derived values.
  • The private stage. Installed updaters stage the candidate in a 0700 .openclaw.update-stage-* directory. For the account's admission only, root adds the traverse bit of the account's permission class (owner, primary group, others) to that one directory and restores its mode afterwards; any other ancestor the account cannot traverse makes admission refuse.
  • Stops. A stop counts only when systemd reports the unit inactive or failed and both its current and its pre-stop cgroup are empty; otherwise nothing is restored and the backup is kept.
  • When it refuses instead. Numeric/empty/root User=, unresolvable account, a HOME the account does not own and cannot write, no root-owned runuser, unreadable effective environment, sandboxed state, a caller whose state or config overlaps the service's (canonical paths, so sudo env OPENCLAW_STATE_DIR=<service state> and aliases), or any invalid answer from the account's admission. Each refusal happens in candidate admission, before the package is replaced.

Threat cases tested (unit tests at the boundary, account process replaced by a stand-in that answers as an account could): malformed verdict, admit verdict with refusal exit, verdict for another candidate, verdict that claims the account check itself, output past its bound, failed run; migrate success exit without a status word, a status word with shell metacharacters, output past its bound; restore failure; unconfirmed stop; processes surviving in the cgroup; the scheduled settle script executed against stand-ins (kept update recorded from indented output, rollback restores then restarts, restore without a status or with a populated cgroup leaves the unit stopped, same-version different-build treated as rollback); settle scheduling failure restores; unit secrets kept out of root's runuser environment and out of the settle unit's argv; handed-over files 0400 owned by the account. Each admission case was shown red by disabling its check.

Update behavior

  • Published drivers with candidate admission (2026.9.7 through 2026.11.10), package installs: reach this through the candidate's update admit and its Doctor child. Proven below with 2026.11.10.
  • What a 2026.11.10-driven hop cannot do: that updater writes its own run record, report, snapshot and diagnostics into the caller's state (/root/.openclaw with plain sudo) and finishes with its own messages. The service's run record is therefore written separately by the settle step, as the service account. The updater's closing lines still include text about root's own state ("gateway.mode is unset", "Gateway service inspection is unavailable; automatic service restart was skipped ... run openclaw update repair") although the service was restarted and verified; this text comes from the installed updater's finalization against root's state and is not changed here.
  • A main-driven hop: goes through the release path in src/update/, which this PR does not touch (it belongs to the update-path owner). Observed in the cell: the next sudo openclaw update run by the new release refuses at its own schema preflight against root's state and changes nothing. The change that path needs is in the issue thread, not here.

Evidence

Linux Docker, systemd as PID 1, root-owned global npm install of the published 2026.11.10 driver, system unit openclaw-gateway.service with User=openclaw, HOME=/var/lib/openclaw, OPENCLAW_STATE_DIR=/var/lib/openclaw/.openclaw, state seeded by the 2026.11.10 Gateway (state schema 40, agent schema 42) plus a retired delivery-queue file that exists only in the service state, a local registry serving the candidate as latest, and a 1-second /readyz probe for the whole cell. Every step runs inside the container as a script; the host only starts the container and the scripts. Candidates are packs under unpublished versions.

Cell Driver → candidate Result
Red, sudo openclaw update --yes twice 2026.11.10 → origin/main 8b36e346b45 as 2026.11.13 exit 1 both times in 49 s / 48 s, service-account-mismatch before the swap; package 2026.11.10, schemas 40/42, MainPID unchanged, 0 restarts; 0 entries under the service home not owned by openclaw; no not-ready probe during either attempt
Green, sudo openclaw update --yes 2026.11.10 → this branch bce55cc1b18 as 2026.11.26 exit 0 in 837 s, "OpenClaw updated to 2026.11.26"; schemas 40/42 → 42/45; unit running the new build (new MainPID, 0 restarts); 0 entries not owned by openclaw before, after and at the end; longest not-ready run 18 s (20 of 1,395 probes); the service account's openclaw update status shows the run succeeded, after 2026.11.26

Which account ran each state step (process owner from a 250 ms process sampler in the green cell):

Step Owner
Candidate update admit launched by the installed updater root
update admit against the service's state (through runuser) openclaw
update migrate --backup-root /var/lib/openclaw/.openclaw-update/system-service-<id>/native openclaw
gateway health --json readiness check openclaw
update finish (settle unit, after the updater exited) openclaw

Admission validated the service's own state: its warning names /var/lib/openclaw/.openclaw/delivery-queue/seeded.json, a file that exists only there. The backup lived under the service home owned by openclaw and was removed by update finish (82 entries after the update, 65 at the end).

Recordings (terminal, 4x speed):

Further cells (same harness; "head11" is bce55cc1b18 as 2026.11.26, "final" is 444eabf6394 as 2026.11.29, "base" is origin/main 8b36e346b45 as 2026.11.13):

Cell Result
final, green exit 0 in 703 s; schemas 40/42 → 42/45; 0 entries under the service home not owned by openclaw before, after and at the end; longest not-ready run 17 s; admit, migrate, gateway health --json --port 18789 and update finish ran as openclaw; the account's openclaw update status shows succeeded, after 2026.11.29. Recording: https://github.com/user-attachments/assets/e39bb502-1615-49c5-b37c-8bd1633babdf
head11, new build refuses to start (ExecStartPre fails on the candidate) exit 1 in 1,482 s; package rolled back to 2026.11.10, state restored to schema 40, unit serving 2026.11.10 again. Outage about 12 minutes because readiness waited its full 10 minutes while systemd restarted the unit 289 times; later commits restore after five restarts. One root-owned openclaw.sqlite.seal appeared in the service state in this path only; it is written by a clean SQLite close of a root process, and the root processes in this path include the installed updater's own rollback steps. The writer was not proven.
head11, custom unit name (company-gateway.service) exit 0 in 985 s; 0 entries not owned by openclaw; every state step as openclaw
head11, ExecStart … --profile prod gateway --port 18789 exit 1 in 1,419 s, state restored: the account's health check used the profile's default port, not the unit's --port. Fixed in a later commit (health now passes the unit's --port); the final rerun of this cell did not run (see below).
head11, no root-owned runuser exit 1 in 36 s: "Automatic update as the service account is not possible: no root-owned runuser was found. Nothing was changed"; 0 entries not owned by openclaw
head11, numeric User=997 exit 1 in 36 s: "the unit's User= (997) is not a named service account. Nothing was changed"
head11 and base, sudo env OPENCLAW_STATE_DIR=<service state> openclaw update head: refused twice, package and Gateway unchanged. Both head and base leave the same 10 then 16 root-owned files (log, failure reports, diagnostics zip) in the service state: the 2026.11.10 updater writes them before any candidate step runs. The head refusal says so and prints the chown to give them back.
head11 and base, service account runs openclaw update itself exit 1 in 1–2 s on both (it cannot replace a root-owned package); nothing changed
head11 and base, a second unit for another state directory on the same install head: exit 0 in 787 s, selected unit updated; base: refused (service-account-mismatch). The second unit's state is not handled by either.
root-run unit with root's own state head11 run invalid (harness bug, fixed); base: exit 1, runtime-artifact-publication ("Cannot replace …"), unrelated to this change. Final rerun did not run.

The final reruns of the failure, --profile, root-unit and explicit-state cells were stopped before they started when #207304 landed.

Raw output: red, attempt 1 (base)
Phase: staging
Phase: finished

⚠️ OpenClaw update failed: service-account-mismatch.
Report: /root/.openclaw/update-reports/ca513eef-d900-4c09-a2b5-9ef87c17fd58.md
Read report (shell): cat -- /root/.openclaw/update-reports/ca513eef-d900-4c09-a2b5-9ef87c17fd58.md
Cause: service-failed
Update mode: npm
Update safety checks ran in the candidate updater (2026.11.13).
Admission checks: managed-service-account: refuse.
Phases: requested (22.8s) → staging (13.6s)
Failed: staging
Failed: candidate-admission — [{"name":"managed-service-account","status":"refuse","detail":"Gateway service openclaw-gateway.service runs as openclaw, but this update runs as root and would back up and check root's own state instead of the service's."}]
Failed: service-account-mismatch — Exit code: 1; Gateway service openclaw-gateway.service runs as openclaw, but this update runs as root and would back up and check root
Failing check candidate-admission (service-account-mismatch): Gateway service openclaw-gateway.service runs as openclaw, but this update runs as root and would back up and check root's own state instead of the service's.
Failing check update (update-failed)
Warning: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
Nothing was changed: the package, the service state and the running Gateway are as they were. Update this system service by hand (https://docs.openclaw.ai/install/updating#linux-system-service-run-by-another-account). First make a verified backup of its state as openclaw: sudo -u openclaw env HOME=/var/lib/openclaw OPENCLAW_STATE_DIR=/var/lib/openclaw/.openclaw openclaw backup create --verify --output /var/lib/openclaw. Then run sudo npm install -g [email protected] --allow-scripts=openclaw and sudo systemc
Raw output: green, tail
Post-install doctor reported a recoverable update-time repair warning after the package install was verified; continuing with post-core plugin convergence.
Run openclaw doctor --fix to finish deferred repairs.
      Docs: https://docs.openclaw.ai/cli/doctor/running#understanding-findings
    - SECURITY WARNING: Recorded Gateway service runtime: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
      Next step: Upgrade the service Node.js runtime, then refresh the managed Gateway runtime selection and restart it. Compatible older Node remains usable.
      Docs: https://docs.openclaw.ai/cli/doctor/running#understanding-findings
    - gateway.mode is unset; gateway start will be blocked.
      Location: gateway.mode
      Next step: Run `openclaw configure` and set Gateway mode (local/remote), or `openclaw config set gateway.mode local`.
      Docs: https://docs.openclaw.ai/gateway/configuration
    │
    └  Doctor complete.
    Doctor: maintenance finish
    Doctor: maintenance release
    [update] Doctor changed config key: meta.
    [update] Doctor changed config key: plugins.
    [update] Doctor changed config key: wizard.
    [update] Doctor migration: Recorded webhook listener decisions; removed pins will not be recreated.
    core/doctor/node-runtime: SECURITY WARNING: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
    core/doctor/node-runtime: SECURITY WARNING: Recorded Gateway service runtime: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
    core/doctor/gateway-config: gateway.mode is unset; gateway start will be blocked.
    Post-install doctor reported a recoverable update-time repair warning after the package install was verified; continuing with post-core plugin convergence.
Gateway service inspection is unavailable; automatic service restart was skipped. Any recorded service definition was left unchanged; inspect it with `openclaw gateway status --deep`. Stop the Gateway through its owner (`openclaw gateway stop --force` for the managed service), then run `openclaw update repair`.
Deferred Doctor inspections did not complete after restart (Gateway readiness was not verified). Run `openclaw doctor --lint --all --severity-min info` to inspect them.
Finishing update: checking package backup retention and cleanup.
Updating plugins...
No plugin updates needed.
✅ OpenClaw updated to 2026.11.26.
Next: After confirming the update and your conversations are healthy, preview retained migration originals eligible for permanent cleanup with `openclaw update cleanup --dry-run` for state `/root/.openclaw`. Before applying cleanup, stop the Gateway first (`openclaw gateway stop --force`). Use the same profile, state, and config settings.
Warning: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
Warning: Doctor will migrate or archive retired state with original bytes preserved: /var/lib/openclaw/.openclaw/delivery-queue/seeded.json
Warning: core/doctor/node-runtime: SECURITY WARNING: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
Warning: core/doctor/node-runtime: SECURITY WARNING: Recorded Gateway service runtime: Node.js 24.20.0 is below the recommended security patch level. TLS may trust certificates signed with keys compromised in the October 2026 eMudhra incident. Upgrade to Node 24.22.1+ on the 24.x line or Node 26.12.1+.
Warning: core/doctor/gateway-config: gateway.mode is unset; gateway start will be blocked.
Warning: EXDEV during package backup rename; using a verified rollback copy.
Warning: Gateway service inspection is unavailable; automatic service restart was skipped. Any recorded service definition was left unchanged; inspect it with `openclaw gateway status --deep`. Stop the Gateway through its owner (`openclaw gateway stop --force` for the managed service), then run `openclaw update repair`.
Warning: Deferred Doctor inspections did not complete after restart (Gateway readiness was not verified). Run `openclaw doctor --lint --all --severity-min info` to inspect them.
Update backup cleanup removed 0 items (0 logical bytes, 0 MiB). Kept 3 the updater still needs.
04:00:14 [infra:temp-artifacts] Runtime retained at /usr/local/lib/openclaw-update-runtime-ThcsjZ: worker generation settled; cleanup deferred to the next eligible update or openclaw doctor --fix
exit 0 in 837s

Which commit the proof covers. Red: 8b36e346b45. Green: bce55cc1b18 and the final 444eabf6394. Commits after 444eabf6394 change only uncertain-cleanup handling of account health runs (they no longer count as ready) and a merge of main; those are covered by unit tests, not cells.

Tests

  • src/cli/update-cli/update-command-admit.service-account.test.ts (whole file audited): the fix: refuse root updates of a system service that runs as another account #206343 refusal cases now assert the fallback reason; new cases run admission through a runuser stand-in that answers as an account could: admits with the account's verdict (argv, a trusted runuser environment without unit secrets, the unit environment in an owner-only 0400 file, handoff removed, root's own state untouched), passes on the account's refusal, and refuses for malformed output, an admit verdict with a refusal exit status, another candidate's verdict, a verdict claiming the account check, output past its bound, and a failed run; falls back for non-root, numeric User=, unresolvable account, unwritable HOME, unreadable environment, overlapping config, a state directory inside the service's, and sandboxed state. The overlap cases were shown red with the check disabled. No cases removed.
  • src/cli/update-cli/update-command-service-account-activation.test.ts (new): the activation through the production entry with systemd stand-ins and a real process for /proc identity: success (Linux), restore and never start the candidate after a failed or malformed migration, unconfirmed stop, surviving cgroup processes, unit not serving the candidate, account health failure (Linux), settle scheduling failure (Linux); and the scheduled settle script executed in a VM context with stand-ins (kept, rolled back, restore without status, populated cgroup, same-version different build, start-mode rollback). The JSON-framing and newline cases were shown red.
  • Also run and passing: update-command-admit.test.ts, update-migrated-finalize.worker.test.ts, update-command-service-maintenance*.test.ts, systemd-service-files.scope.test.ts, systemd-scope.identity.test.ts, systemd-service-identity.test.ts, update-immutable-activation.test.ts and update-immutable-build.test.ts (Linux-only cases skip on macOS), test/scripts/update-restart-module-outcome.test.ts.
  • node scripts/check-changed.mjs: format, lint, typecheck and guards pass; the dead-export scan fails only on an export already unused on main (AgentHarnessSideQuestionRequest). Session identity ratchet: OK.
  • Autoreview, Codex route (gpt-6.1-sol, thinking high), --max-priority P2, branch mode against origin/main, owners and callers as source context: 27 passes on successive heads. Each finding was fixed in its own commit (among them: verifying the activation before retiring the backup, restoring at once on a crash loop, verifying the cgroup hierarchy before treating a missing group as empty, the unit's --port and retitled Gateways, admission answering before the installed updater's deadline, settling only after the Doctor child and its account work end, an unescaped NUL in the settle script, and fencing everything on uncertain process cleanup). The pass on 3d79ecace73 (this branch before the last main merge) is scoped-clean. Two findings were declined with reasons: the settle step uses the restored previous package's update restore (receipt and backup schemas are byte-identical in published 2026.11.10), and a failed update finish leaves the verified candidate serving with the backup kept.
  • Test-line budget: +1,309 net lines against main, covered by config/test-lines-allocations/207230-service-account-update-steps.txt (909). The cases are the hostile-account answers, fallback blockers, the settle script run against stand-ins, the shared cgroup owner on unified, hybrid and legacy hierarchies, and serving-release identity.
  • CI on the last pushed head before the conflict: the only failures were inherited from main (an iOS protocol-coverage allowlist entry and an unformatted UI file, both failing on main itself).

Not proven

  • Drivers other than 2026.11.10 were traced from the admission contract, not run. Git installs do not run candidate admission and are unchanged.
  • The rollback branch of the settle step (installed updater restores the previous package after the Doctor child succeeded) is covered by executing the settle script against stand-ins, not by a cell.
  • pnpm/Bun installs, KillMode=process survivors and EnvironmentFile= units were not run in a cell; the custom-unit, --profile and numeric-User= variants are listed below as they complete.
  • The settle step's own output goes to its unit's journal, not to the updater's output.
  • No macOS or Windows (Linux systemd only).

…count

When root updates a package whose selected systemd system unit runs it as
another account, candidate admission now runs as that account against the
unit's state, and the post-activation Doctor child stops the unit, runs the
account's own update migrate, starts the unit, verifies it serves the new
build, and records the run with update finish. A failure restores the state
as the account and starts the unit again once the previous package is back.
The openclaw#206343 refusal stays as the fallback when the account cannot be used.
Address review: root's runuser now runs with a trusted environment and the
unit's environment reaches the account's process through an owner-only
handoff file, so loader variables never reach a root process. Restores
require a confirmed stop, and the run record and backup retirement wait
until the installed updater has settled the package, restoring the state
as the account if that updater put the previous package back.
…lapping selectors

Address review: an unscheduled settle step keeps the backup instead of
retiring it early, a caller whose state or config overlaps the service's
(by canonical path) stays on the refusal, and the serving entry is found
after runtime options in the unit's command.
…updater

Address review: the transient settle step reads the account's bounded
status word before restarting or retiring anything, keeps the backup when
the installed updater outlives its deadline, and the activation fixture
runs the release entry the way a unit does.
When the settle step cannot be scheduled, restore the account's state
instead of reporting success, since a later package restore by the
installed updater would otherwise pair the previous package with migrated
state.
…cgroups

Address review: migrate, restore and finish print Doctor output before an
indented JSON result, so the final object is parsed; a stop counts only
when the unit is inactive and its cgroup is empty, in both the Doctor child
and the settle step. Hand files over under root's sticky /tmp, which the
account can traverse, and show a bounded line of the account's error when
its admission fails.
… admission

Installed updaters stage the candidate in a 0700 directory. For the
account's own admission, root adds only the traverse bit to its own
ancestors that lack it and restores each mode afterwards. The settle step
now parses the final JSON result like the Doctor child, checks the current
and captured cgroup, and an unconfirmed first stop no longer starts the
new package. Tests run the scheduled settle script against stand-ins.
…count's class

Address review: root no longer adds traverse bits to arbitrary private
ancestors. Only the installed updater's .openclaw.update-stage-* directory
gets the traverse bit of the permission class the account falls in, and a
staged release under any other directory the account cannot enter refuses.
…pped restart

Root's own service inspection cannot read a unit that runs as another
account. When that unit already serves this release because its account's
steps ran earlier in the update, the warning now says so instead of
claiming the restart was skipped and pointing at update repair.
… HOME

Address review: the account keeps its update backup under the unit's HOME,
so admission now checks that HOME is a directory the account owns and can
write, instead of failing the migration after the service was stopped.
Address review: the settle step treats a package whose build differs from
the candidate's as the restored previous package, so a same-version
replacement restores the account's state instead of retiring the backup.
…when settling

Address review: the settle step follows the installation path the unit
uses, so a release-slot rollback that moves the link back is seen as the
previous package.
The Docker cell showed the skipped-restart warning still comes from another
finalization path, so the hook did not change what operators see. Keep the
lint fix it carried.
Address review: the transient settle step is scheduled after the unit is
confirmed stopped and before the account's migration, so if this process
ends early, for example at the installed updater's deadline, the state is
still reconciled once that updater exits. A migration that never backed
anything up left the state unchanged, so the previous package may start.
Root-run test fixtures give the stand-in account its HOME.
@clawsweeper

clawsweeper Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime cli CLI command changes size: XL labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. labels Nov 28, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 28, 2026
obviyus added a commit that referenced this pull request Nov 28, 2026
- Run only the recorded runtime's version probe as User= with a sanitized environment; refuse before replacement with its cause and next step.
- Reuse the byte-identical systemd-service-account-command helper from #207230 without its bridge orchestration.
- Use blocking systemctl restart before checking activity, rather than observing a queued RestartUnit job.
- Focused source proof: 19 tests pass; scoped formatting and lint pass. Root never runs service state maintenance.

Co-authored-by: Jason (Json) <[email protected]>
obviyus added a commit that referenced this pull request Nov 28, 2026
## What Problem This Solves

A root-owned global OpenClaw package can serve a systemd system unit running as another account (`User=`). Updating it as root must not run state work against `/root` or write the service account's state as root. Today the cross-account candidate refuses and prints a manual procedure.

## User Impact

For a positively identified matching system unit, `sudo openclaw update --yes` replaces only the package as root and restarts the existing unit. Its own boot, running as `User=`, owns migrations and plugin convergence. Root does not run Doctor, finalize, snapshots, config/RPC/run writes, or update-report persistence.

The CLI requires systemd to report the unit active and prints `systemctl status <unit>` and `journalctl -u <unit>` without claiming readiness. The existing HTTP readiness helper needs the service's TLS configuration; root must not open that state, so this path uses the systemd-active fallback instead of assuming HTTP. A failed restart or inactive unit fails the CLI. `--no-restart` explicitly reports that the package still needs activation. The saved update channel is not changed by this package-only path.

## Why This Change Was Made

This follows the maintainer-directed package/state ownership split: root owns package replacement; the service owns state at boot. The branch occurs before update state setup and reuses #206343's installation/unit identification, the existing staged package installer, and the blocking systemctl owner. A state-free `runuser ... <recorded runtime> --version` probe runs as `User=` before replacement, with a sanitized launch environment; failure or an incompatible version refuses with its cause and next step. No service-controlled runtime is executed as root. The manual-procedure shell formatter and its obsolete tests are removed; shipped-candidate and non-root cross-account state checks remain refused, with a working documented manual recovery route for older installed updaters.

Scope boundary: the remaining frozen bridge state readers are not migrated or orchestrated here; they stay for their shipped contracts until the first-hop floor permits bridge deletion. launchd, Windows, and single-account update paths are unchanged.

Thanks to @fuller-stack-dev for #206343's system-account identification and #207230's 33-line `src/daemon/systemd-service-account-command.ts` helper. The original helper functions and synchronous argv API remain unchanged at the same path. The only addition is a 23-line NSS login-name resolver: systemd accepts numeric `User=1001`, but `runuser -u` requires its login name. None of #207230's bridge orchestration is inherited, and its branch remains untouched. The helper contribution is credited with the verified GitHub noreply co-author trailer.

Author pr-simplify completed: one reused identification and package operation, no new persisted records, statuses, phases, leases, notices, retries, flags, or triggers. Against `dfd17d025fe0`: production net **+227 lines**, test net **+189**, docs net **+23**. The positive production net is the complete package/runtime-check/restart operation replacing a refusal, plus the command helper and numeric-account resolution. No state-maintenance or bridge orchestration is added.

## Evidence

- Red on the unchanged main source (`dfd17d025fe0`): the new real `updateCommand` boundary regression reached the forbidden root state-setup tripwire instead of replacing the package/restarting the unit.
- Final head `18627bcd4b65641eb80a69a774b3e0d01a97ae6c`: source regressions passed with the repository wrappers under both the pinned Bun fork (11 tests) and Node (21 tests including candidate admission), 94.11 s combined wall time. The earlier full focused selection, including unchanged `src/update/cli.test.ts`, passed 64 tests on `c8bd81b367df0fd02389453b6cc54eea7d755207`.
- Scoped Oxfmt and type-aware Oxlint checks pass on the three repaired files (19.71 s); earlier scoped formatting and lint cover the unchanged files.
- Unit proof covers default root state and explicit service-state selectors, account-isolated version-probe argv/environment, numeric UID-to-login resolution and mismatched NSS rejection, incompatible recorded Node and exact probe failures before replacement, blocking restart completion, restart failure/inactive units, and `--no-restart`. Package installation, NSS lookup, the version-probe subprocess, and native service operations are mocked at their existing I/O boundaries; this is not live systemd proof.
- No existing system-unit-with-`User=` proof harness was found. `ci-published-driver-update.yml` / `scripts/e2e/lib/upgrade-survivor/native-systemd.mjs` uses `systemctl --user`, not system units. No hosted container run is claimed. Proof is unit tests plus PR CI.
- Full builds/type checks are left to hosted CI per the host constraint. First-head CI: https://github.com/openclaw/openclaw/actions/runs/46119231572 — architecture failed on the untouched `ui/src/pages/skill-workshop/action-presentation.ts` ↔ `skill-workshop-page.tsx` Madge cycle; runtime import-cycle and Kysely checks passed.
- Prior-head CI (`6804c4623254ca899dcab5d01f794f2f58ae3057`): https://github.com/openclaw/openclaw/actions/runs/46120628365 caught a fixture bug: its Bun shard made `process.execPath` describe a Bun service, so the intended Node-engine refusal did not apply. The fixture now records `/usr/bin/node` independently of the runner, preserving every refusal assertion. The two unnecessary deferred type arguments were also removed. Final-head CI is pending; no local full build or third review is claimed.
- Local ClawSweeper completed two rounds. Its TLS/legacy-recovery findings and then its service-runtime/queued-restart findings were repaired. The latter now uses the maintainer-approved state-free account probe and blocking systemctl restart. No third review is claimed; the package-only/no-root-state contract and unit+CI proof scope are the maintainer-selected direction.

Related: #204775, #206343. No release branch changes.

Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@clawsweeper clawsweeper Bot removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 28, 2026
@obviyus

obviyus commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for #206343. Your systemd-service-account-command.ts helper is reused as-is in #207304, which also credits you as co-author.

#207304 is the direction we're taking for this layout, so I'd suggest closing this PR:

  • Updates driven by the current updater: sudo openclaw update replaces only the package as root, then restarts the unit. The service's own boot runs as User= and owns migrations and plugin convergence, so root never touches service state.
  • Hops driven by an older shipped updater: these keep fix: refuse root updates of a system service that runs as another account #206343's refusal and its documented manual procedure. That's the one case this PR completes, and it does it by running admission, migration, restore and the run record as the service account inside the shipped-driver bridge. We're deliberately not growing the bridge: it's slated for deletion once a first-hop cutoff version is set, and users on older updaters then get one manual step.

If you see a case on this layout that #207304 still gets wrong, a failing repro against current main would be very welcome as a new issue or PR.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 29, 2026
…law#207304)

## What Problem This Solves

A root-owned global OpenClaw package can serve a systemd system unit running as another account (`User=`). Updating it as root must not run state work against `/root` or write the service account's state as root. Today the cross-account candidate refuses and prints a manual procedure.

## User Impact

For a positively identified matching system unit, `sudo openclaw update --yes` replaces only the package as root and restarts the existing unit. Its own boot, running as `User=`, owns migrations and plugin convergence. Root does not run Doctor, finalize, snapshots, config/RPC/run writes, or update-report persistence.

The CLI requires systemd to report the unit active and prints `systemctl status <unit>` and `journalctl -u <unit>` without claiming readiness. The existing HTTP readiness helper needs the service's TLS configuration; root must not open that state, so this path uses the systemd-active fallback instead of assuming HTTP. A failed restart or inactive unit fails the CLI. `--no-restart` explicitly reports that the package still needs activation. The saved update channel is not changed by this package-only path.

## Why This Change Was Made

This follows the maintainer-directed package/state ownership split: root owns package replacement; the service owns state at boot. The branch occurs before update state setup and reuses openclaw#206343's installation/unit identification, the existing staged package installer, and the blocking systemctl owner. A state-free `runuser ... <recorded runtime> --version` probe runs as `User=` before replacement, with a sanitized launch environment; failure or an incompatible version refuses with its cause and next step. No service-controlled runtime is executed as root. The manual-procedure shell formatter and its obsolete tests are removed; shipped-candidate and non-root cross-account state checks remain refused, with a working documented manual recovery route for older installed updaters.

Scope boundary: the remaining frozen bridge state readers are not migrated or orchestrated here; they stay for their shipped contracts until the first-hop floor permits bridge deletion. launchd, Windows, and single-account update paths are unchanged.

Thanks to @fuller-stack-dev for openclaw#206343's system-account identification and openclaw#207230's 33-line `src/daemon/systemd-service-account-command.ts` helper. The original helper functions and synchronous argv API remain unchanged at the same path. The only addition is a 23-line NSS login-name resolver: systemd accepts numeric `User=1001`, but `runuser -u` requires its login name. None of openclaw#207230's bridge orchestration is inherited, and its branch remains untouched. The helper contribution is credited with the verified GitHub noreply co-author trailer.

Author pr-simplify completed: one reused identification and package operation, no new persisted records, statuses, phases, leases, notices, retries, flags, or triggers. Against `5d0834dfe163`: production net **+227 lines**, test net **+189**, docs net **+23**. The positive production net is the complete package/runtime-check/restart operation replacing a refusal, plus the command helper and numeric-account resolution. No state-maintenance or bridge orchestration is added.

## Evidence

- Red on the unchanged main source (`5d0834dfe163`): the new real `updateCommand` boundary regression reached the forbidden root state-setup tripwire instead of replacing the package/restarting the unit.
- Final head `18627bcd4b65641eb80a69a774b3e0d01a97ae6c`: source regressions passed with the repository wrappers under both the pinned Bun fork (11 tests) and Node (21 tests including candidate admission), 94.11 s combined wall time. The earlier full focused selection, including unchanged `src/update/cli.test.ts`, passed 64 tests on `c8bd81b367df0fd02389453b6cc54eea7d755207`.
- Scoped Oxfmt and type-aware Oxlint checks pass on the three repaired files (19.71 s); earlier scoped formatting and lint cover the unchanged files.
- Unit proof covers default root state and explicit service-state selectors, account-isolated version-probe argv/environment, numeric UID-to-login resolution and mismatched NSS rejection, incompatible recorded Node and exact probe failures before replacement, blocking restart completion, restart failure/inactive units, and `--no-restart`. Package installation, NSS lookup, the version-probe subprocess, and native service operations are mocked at their existing I/O boundaries; this is not live systemd proof.
- No existing system-unit-with-`User=` proof harness was found. `ci-published-driver-update.yml` / `scripts/e2e/lib/upgrade-survivor/native-systemd.mjs` uses `systemctl --user`, not system units. No hosted container run is claimed. Proof is unit tests plus PR CI.
- Full builds/type checks are left to hosted CI per the host constraint. First-head CI: https://github.com/openclaw/openclaw/actions/runs/46119231572 — architecture failed on the untouched `ui/src/pages/skill-workshop/action-presentation.ts` ↔ `skill-workshop-page.tsx` Madge cycle; runtime import-cycle and Kysely checks passed.
- Prior-head CI (`6804c4623254ca899dcab5d01f794f2f58ae3057`): https://github.com/openclaw/openclaw/actions/runs/46120628365 caught a fixture bug: its Bun shard made `process.execPath` describe a Bun service, so the intended Node-engine refusal did not apply. The fixture now records `/usr/bin/node` independently of the runner, preserving every refusal assertion. The two unnecessary deferred type arguments were also removed. Final-head CI is pending; no local full build or third review is claimed.
- Local ClawSweeper completed two rounds. Its TLS/legacy-recovery findings and then its service-runtime/queued-restart findings were repaired. The latter now uses the maintainer-approved state-free account probe and blocking systemctl restart. No third review is claimed; the package-only/no-root-state contract and unit+CI proof scope are the maintainer-selected direction.

Related: openclaw#204775, openclaw#206343. No release branch changes.

Co-authored-by: Jason (Json) <[email protected]>
Co-authored-by: Ayaan Zaidi <[email protected]>
@obviyus

obviyus commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Following up: #207304 landed and covers this layout for updates driven by the current updater, and #208629 fixed the manual first-hop procedure. Nothing here still needs to land, so I'd suggest closing this PR.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation gateway Gateway runtime impact:ux-friction User-facing flow adds avoidable confusion or support burden without fully blocking progress. P2 Normal backlog priority with limited blast radius. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants