fix(sandbox): chown /sandbox/.openclaw to sandbox user at end of build#27
Open
brycelelbach wants to merge 1 commit into
Open
fix(sandbox): chown /sandbox/.openclaw to sandbox user at end of build#27brycelelbach wants to merge 1 commit into
brycelelbach wants to merge 1 commit into
Conversation
`nemoclaw-sandbox:local` ships with `/sandbox/.openclaw/` owned by root and `openclaw.json` at mode 0444, so the openclaw process (which runs as uid 998 `sandbox` at runtime) cannot edit its own config, cannot rotate logs, and cannot read its own `openclaw.json.bak`. The control UI / dashboard then silently fails any write-back of config changes. Two contributing factors: 1. `openshell sandbox create --from Dockerfile` builds the image in an environment that doesn't always honor `USER` directives — RUN steps after line 43 can execute as root, leaving root-owned state under `.openclaw`. 2. `openclaw doctor --fix` writes `openclaw.json` with mode 0444, which blocks the runtime from rewriting its own config even when the owner is correct. Fix: at the end of the build, as root, chown `/sandbox/.openclaw` and `/sandbox/.nemoclaw` back to `sandbox:sandbox` and restore owner-write on everything under `.openclaw`. This makes the final image usable by the non-root sandbox user regardless of what the intermediate layers did. Verified on a running bryce-claw brev instance: applying the same chown + u+w inside the live agent pod let sandbox create files under `.openclaw`, write `openclaw.json`, and write into `.openclaw/logs/`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
nemoclaw-sandbox:localis being built such that/sandbox/.openclaw/ends up root-owned andopenclaw.jsonlands at mode0444. At runtime, the openclaw process runs as uid 998 (sandbox) and cannot:/sandbox/.openclaw/(directory is root-owned,drwxr-xr-x)openclaw.json(-r--r--r-- root:root)openclaw.json.bak(-rw------- root:root)/sandbox/.openclaw/logs/(drwx------ root:root).config-hashsentinel (-r--r--r-- root:root)The symptom end-users hit: the OpenClaw dashboard's config edits silently fail, and the agent can't write rotating logs.
Root cause
Two things go wrong during the build:
Interestingly, `/sandbox/.openclaw-data/` and `/sandbox/.nemoclaw/` both end up correctly `sandbox:sandbox` owned, because the openshell base layer seeds the former and the earlier `chown -R sandbox:sandbox /sandbox` (line 16) covers the latter before the USER-switched steps happen. Only `.openclaw/` is regenerated by `openclaw doctor --fix` and then not re-chowned.
Fix
Add an explicit final `USER root` → `chown -R sandbox:sandbox /sandbox/.openclaw /sandbox/.nemoclaw && chmod -R u+w /sandbox/.openclaw` → `USER sandbox` block at the end of the Dockerfile. This makes the final ownership unambiguous regardless of which intermediate RUN steps ran as root vs sandbox, and restores owner-write on the config files that `openclaw doctor` clamped to `0444`.
The alternative would be to restructure the Dockerfile to do all work as root with explicit `su sandbox -c` for the openclaw-bootstrap steps, but the defensive chown at the end is the smaller diff and works regardless of what intermediate build systems do.
Reproduction (before fix)
On a `bryce-claw` brev instance running this image via openshell:
```
$ kubectl exec -n openshell agent -- ls -la /sandbox/.openclaw/openclaw.json
-r--r--r-- 1 root root 1601 Apr 7 18:19 /sandbox/.openclaw/openclaw.json
$ kubectl exec -n openshell agent -- su sandbox -s /bin/bash -c
'printf "" >> /sandbox/.openclaw/openclaw.json'
bash: /sandbox/.openclaw/openclaw.json: Permission denied
```
Verification
Applied the equivalent of this patch (`chown -R sandbox:sandbox /sandbox/.openclaw && chmod -R u+w /sandbox/.openclaw`) inside the live agent pod. After the change:
```
$ su sandbox -s /bin/bash -c 'touch /sandbox/.openclaw/.writetest && rm /sandbox/.openclaw/.writetest'
$ su sandbox -s /bin/bash -c 'printf "" >> /sandbox/.openclaw/openclaw.json'
$ su sandbox -s /bin/bash -c 'touch /sandbox/.openclaw/logs/test.log && rm /sandbox/.openclaw/logs/test.log'
all succeed
```
Test plan