Skip to content

fix(sandbox): normalize staged script permissions - #7072

Merged
apurvvkumaria merged 1 commit into
NVIDIA:mainfrom
senthilr-nv:agent/normalize-staged-script-permissions
Jul 17, 2026
Merged

fix(sandbox): normalize staged script permissions#7072
apurvvkumaria merged 1 commit into
NVIDIA:mainfrom
senthilr-nv:agent/normalize-staged-script-permissions

Conversation

@senthilr-nv

@senthilr-nv senthilr-nv commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

NemoClaw now normalizes staged script permissions before Docker consumes either sandbox build context. Fresh installs under a restrictive umask no longer preserve root-only script modes that fail in later non-root image-build stages.

Related Issue

Fixes #7071

Changes

  • Normalize the copied scripts/ tree in the legacy sandbox build-context path.
  • Normalize stagedScriptsDir after the optimized path copies its required scripts.
  • Cover both paths under umask 0077, including a 0700 executable helper and 0700 parent directories.

Type of Change

  • Code change (feature, bug fix, or refactor)
  • Code change with doc updates
  • Doc only (prose changes, no code sample modifications)
  • Doc only (includes code sample changes)

Quality Gates

  • Tests added or updated for changed behavior
  • Existing tests cover changed behavior — justification:
  • Tests not applicable — justification:
  • Docs updated for user-facing behavior changes
  • Docs not applicable — justification: this only corrects internal Docker build-context modes; commands, configuration, defaults, APIs, schemas, and documented workflows are unchanged.
  • Sensitive paths changed (security, policy, credentials, preflight, onboarding, inference, runner, sandbox, or messaging)
  • Sensitive-path review completed or maintainer-approved waiver recorded — reviewer/approval link/justification: requested on this draft before it is marked ready.
  • Non-success, skipped, or missing CI check accepted by maintainer — check name, approval link, and follow-up issue:

Verification

  • PR description includes a Signed-off-by: line and every commit appears as Verified in GitHub
  • Normal pre-commit, commit-msg, and pre-push hooks passed, or npm run check:diff passed when hooks were skipped or unavailable
  • Targeted behavior tests pass for the current change set, or tests are marked not applicable above — npx vitest run --project integration test/sandbox-build-context.test.ts: 10 passed
  • Applicable broad gate passed — npm test for broad runtime/test-harness changes; npm run check for repo-wide validation/coverage changes — command/result: not run; this is a focused build-context change with direct regression coverage.
  • Quality Gates section completed with required justifications or waivers
  • No secrets, API keys, or credentials committed
  • npm run docs builds without warnings (doc changes only)
  • Doc pages follow the style guide (doc changes only)
  • New doc pages include SPDX header and frontmatter (new pages only)

Signed-off-by: Senthil Ravichandran senthilr@nvidia.com

Summary by CodeRabbit

  • Bug Fixes

    • Fixed sandbox builds so staged script files keep readable permissions even when created under restrictive system settings.
    • Improved permissions consistency for staged scripts across both optimized and legacy build staging flows.
  • Tests

    • Added/extended test coverage to validate script permissions for both staging modes when using a restrictive umask.
    • Ensures staged scripts, scripts/lib, and scripts/lib/reviewed-npm-archive.mts resolve to the expected readable permissions.

@senthilr-nv senthilr-nv added integration: openclaw OpenClaw integration behavior area: packaging Packages, images, registries, installers, or distribution area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery platform: container Affects Docker, containerd, Podman, or images labels Jul 17, 2026
@senthilr-nv senthilr-nv self-assigned this Jul 17, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4bc51303-8b78-4a61-aabc-4ba796a53669

📥 Commits

Reviewing files that changed from the base of the PR and between e2952bf and 2ae2d15.

📒 Files selected for processing (2)
  • src/lib/sandbox/build-context.ts
  • test/sandbox-build-context.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/lib/sandbox/build-context.ts
  • test/sandbox-build-context.test.ts

📝 Walkthrough

Walkthrough

Sandbox build-context staging now normalizes read permissions for scripts in both legacy and optimized paths. Tests create restrictive source modes and verify staged script directories and files remain mode 755 under umask 0077.

Changes

Sandbox script permissions

Layer / File(s) Summary
Normalize staged scripts
src/lib/sandbox/build-context.ts
Both legacy and optimized staging paths apply normalizeReadModesForDockerCopy to staged script content.
Verify restrictive-umask staging
test/sandbox-build-context.test.ts
Fixtures use mode 700, and tests verify mode 755 for staged scripts under umask 0077 in both staging paths.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: bug-fix

Suggested reviewers: cv

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: normalizing staged script permissions in sandbox build contexts.
Linked Issues check ✅ Passed The patch normalizes staged scripts in both legacy and optimized paths and adds umask 0077 regression tests, matching #7071.
Out of Scope Changes check ✅ Passed The changes are limited to the sandbox build-context fix and related tests; no unrelated scope appears introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

PR Review Advisor — Informational

Advisor assessment: Informational / high confidence
Next action: No advisor follow-up needed.
Findings: 0 blockers · 0 warnings · 0 suggestions
Status: No actionable findings remain in the canonical review ledger.

Model lanes

  • GPT-5.6 Terra (primary): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Nemotron 3 Ultra (second opinion): Completed · high confidence · 0 blockers · 0 warnings · 0 suggestions
  • Model comparison: normalized findings match; normalized E2E selections differ; severity counts match.

Nemotron output stays in workflow artifacts and does not change the assessment above.

E2E guidance

Advisory only. E2E / PR Gate selects and runs jobs independently.

Recommended E2E: None

1 optional E2E recommendation
  • rebuild-openclaw

Workflow run details

This automated review informs maintainers. Warnings and suggestions do not require a response. A maintainer decides whether to merge.

@senthilr-nv

senthilr-nv commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator Author

Additional Brev validation :

  • Tested commit e2952bf.
  • Created a fresh checkout under umask 0077; scripts/, scripts/lib/, and scripts/lib/reviewed-npm-archive.mts were all verified as mode 0700 at the source.
  • Ran the interactive default OpenClaw Express onboarding through actual BuildKit sandbox creation.
  • Build completed all 70 runtime stages. The helper COPY and subsequent stages succeeded, the image exported, the sandbox reached Ready, and the dashboard became live.
  • A disposable provider fixture was used only to reach sandbox creation; this was not counted as an inference-quality E2E.
  • Cleanup completed: sandbox, provider, mock process, and generated image were removed.

This reproduces the restrictive source-permission precondition and validates the staged-script normalization in a real sandbox build.

@senthilr-nv
senthilr-nv marked this pull request as ready for review July 17, 2026 04:26
Signed-off-by: Senthil Ravichandran <senthilr@nvidia.com>
@senthilr-nv
senthilr-nv force-pushed the agent/normalize-staged-script-permissions branch from e2952bf to 2ae2d15 Compare July 17, 2026 04:31
@apurvvkumaria apurvvkumaria self-assigned this Jul 17, 2026

@apurvvkumaria apurvvkumaria left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Security-sensitive maintainer review complete at exact head 2ae2d15. The restrictive-umask fix covers both staging paths; mode normalization preserves executability, adds no write bits, does not follow symlinks, and remains confined beneath the private build context. Exact-head CI, CodeQL, DCO, advisor, and protected E2E are green; no unresolved threads or actionable findings remain.

@apurvvkumaria
apurvvkumaria merged commit c133beb into NVIDIA:main Jul 17, 2026
66 checks passed
senthilr-nv added a commit that referenced this pull request Jul 25, 2026
<!-- markdownlint-disable MD041 -->
## Summary

A normal `0002` checkout can stage executable Docker payloads as `0775`,
so the exact metadata gate added by #7486 aborts a sandbox replacement
build. This change clears group and other write bits while preserving
owner write and executable intent, so permissive and restrictive source
modes both produce canonical Docker payload modes without weakening the
gate.

## Changes

- Clear group and other write bits in
`normalizeReadModesForDockerCopy()` before adding the read, traverse,
and executable permissions required by Docker.
- Cover optimized and legacy staging with `0775` directory and
executable fixtures plus a `0664` non-executable fixture. The tests
assert exact staged modes of `0755` and `0644`.
- Retain coverage that normalizes restrictive `0700` directories and
executables plus `0600` ordinary files.
- Confirm the regression history: #3664 introduced read-mode
normalization, #7072 applied it to scripts with restrictive-mode
coverage, #7332 added `patch-bundled-npm-tar.mts`, and #7486 made its
preserved `0775` mode fail the exact `0755` assertion.
- Validate the fix on Brev instance `nc-july26` from base SHA
`3b2f6d557`. A transactional rebuild with `0775` and `0664` source
inputs completed the strict payload metadata stage, replacement
creation, state restore, policy restore, and deployment health checks.

## Type of Change

- [x] Code change (feature, bug fix, or refactor)
- [ ] Code change with doc updates
- [ ] Doc only (prose changes, no code sample modifications)
- [ ] Doc only (includes code sample changes)

## Quality Gates

- [x] Tests added or updated for changed behavior
- [ ] Existing tests cover changed behavior — justification:
- [ ] Tests not applicable — justification:
- [ ] Docs updated for user-facing behavior changes
- [x] Docs not applicable — justification: The fix restores the existing
staged-payload permission contract and does not change commands,
configuration, or supported workflows.
- [x] Sensitive paths changed (security, policy, credentials, preflight,
onboarding, inference, runner, sandbox, or messaging)
- [ ] Sensitive-path review completed or maintainer-approved waiver
recorded — reviewer/approval link/justification:
- [ ] Non-success, skipped, or missing CI check accepted by maintainer —
check name, approval link, and follow-up issue:

## Documentation Writer Review

- [x] Documentation writer subagent reviewed the completed changes
- Result: `no-docs-needed`
- Evidence: No documentation files changed. The fix restores canonical
staged modes without changing commands, configuration, or supported
workflows. The reviewer found no actionable wording issues.
- Agent: Codex Desktop
<!-- docs-review-head-sha: 14967c5 -->
<!-- docs-review-agents-blob-sha: 9c9b36d -->

## DGX Station Hardware Evidence

- [ ] Tested on DGX Station
- Tested commit:
- Station profile/scenario:
- Result:
- Supporting evidence:

## Verification

- [x] PR description includes a `Signed-off-by:` line and every commit
appears as `Verified` in GitHub
- [x] Normal `pre-commit`, `commit-msg`, and `pre-push` hooks passed, or
`npm run check:diff` passed when hooks were skipped or unavailable
- [x] Targeted behavior tests pass for the current change set, or tests
are marked not applicable above — `npx vitest run
test/sandbox-build-context.test.ts
src/lib/onboard/build-context-stage.test.ts
src/lib/actions/sandbox/rebuild-managed-image-preparation.test.ts`
(22/22 passed); `npm run typecheck:cli` passed; Brev `nc-july26` rebuild
passed the strict Docker payload metadata stage and completed
successfully.
- [ ] Applicable broad gate passed — `npm test` for broad
runtime/test-harness changes; `npm run check` for repo-wide
validation/coverage changes — command/result:
- [x] Quality Gates section completed with required justifications or
waivers
- [x] No secrets, API keys, or credentials committed
- [ ] `npm run docs` builds without warnings (doc changes only)
- [ ] Doc pages follow the [style
guide](https://github.com/NVIDIA/NemoClaw/blob/main/docs/CONTRIBUTING.md)
(doc changes only)
- [ ] New doc pages include SPDX header and frontmatter (new pages only)

---
Signed-off-by: Senthil Ravichandran <senthilr@nvidia.com>

Signed-off-by: Senthil Ravichandran <senthilr@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: packaging Packages, images, registries, installers, or distribution area: sandbox OpenShell sandbox lifecycle, runtime, config, or recovery integration: openclaw OpenClaw integration behavior platform: container Affects Docker, containerd, Podman, or images

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(sandbox): normalize staged script permissions under restrictive umask

3 participants