Repository navigation
app: pin nested repositories and refuse unprotected worktrees in the Linux sandbox - #3364
Conversation
|
This change is careful about the default: it stays opt-in, keeps commands refused while the opt-in is off, and sets up namespace isolation with the network denied except for the network profiles and read-only mounts ordered so the workspace wins. Worktrees that point at metadata outside the workspace at startup are refused, and nested repositories found by the bounded walk get their configuration and hook files pinned read-only. Those parts look sound. Two things keep me from calling it safe in every case. First, the walk that looks for nested repositories quietly stops at its depth limit and skips dependency folders; a repository beyond that depth or inside a skipped folder is left with writable configuration and hooks even though the change promises to pin every repository and to refuse rather than protect only some. A limit that refuses is fine; a limit that silently gives up is not. Second, a worktree's pointer file is left writable. During a writable run, a command can build its own metadata in the writable scratch area and repoint the workspace at it; the ordinary Git commands the host runs afterwards would then follow that pointer and can execute a planted hook. The protection here holds only at the moment the sandbox starts, not for the whole session. Please make the depth bound refuse instead of skip and stop excluding those folders, pin the worktree pointer read-only and prevent new control files from appearing, and add coverage for deep and nested worktrees, shared directories that live outside the workspace, and pointer rewrites. Once those gaps are closed and the documentation lists the remaining limitations honestly, this is in good shape.
|
|
Both gaps are closed on head Walk bounds refuse instead of skipping. No folder is excluded any more: dependency folders and symlinked directories that resolve inside the workspace are walked, symlinks resolving outside are not followed (they are not mounted, so nothing is reachable through them), and real paths are de-duplicated. Hitting 32 directory levels or 50,000 directories throws and the command is refused with the reason, so a repository can never end up silently unpinned. Worktree pointers are frozen. A Coverage added. Unit: a repository inside Remaining limits, now in Tests on this head: 857/857, typecheck clean, conformance passing. |
|
Thanks @eXsoR65, both gaps are closed as described. The walk bounds now refuse, nothing is skipped, the worktree pointer and missing control entries are frozen read-only, and each new test fails with its fix reverted. Documenting the placeholder side effect is the right call. One piece of the coverage we asked for is still missing: a worktree whose
|
|
Added on head
One nuance worth reporting: reverting the explicit Tests on this head: 857/857, typecheck clean, conformance passing (shared-directory case included). On the multi-line comments: agreed, and note the |
|
Thanks @eXsoR65. The shared-directory tests answer the latest request, including the distinction between the specific guard and the later generic refusal. We will handle the remaining source-file split, comments and CI. We also need to close the paths the repository walk still skips on inspection errors and finish the Linux confinement check before landing.
|
|
Closed the remaining walk skips on head Inspection failures now refuse instead of being treated as "nothing here": a Coverage, both failing if the fix is reverted:
Documented in On the source-file split, comments and CI: understood, those are yours — say if you would rather I send any of them. |
|
Hi @eXsoR65, thanks for closing the walk's inspection-error gaps on the current head. Together with the earlier work, that covers what we asked: the depth and directory bounds now refuse instead of skipping, no folders are excluded, the worktree pointer and missing control entries are frozen read-only, and the deep, nested, shared-directory and pointer-rewrite cases each have a test that fails when its fix is reverted. The source split, comments and CI stay with us, and we'll finish the Linux confinement check on a host with the sandbox runtime before landing. Nothing further is needed from you.
|
6f76c40 to
b6aa02c
Compare
…Linux sandbox A writable workspace pinned only its own .git, so a nested repository or submodule could have its config and hooks changed from inside the sandbox, and a worktree pointer could name a gitdir the profile never mounted. Pin every .git under the workspace with the same read-only control entries, and refuse a worktree whose gitdir or shared directory is outside the workspace. A workspace with no repository keeps commands refused, because bwrap cannot deny creating .git by name.
…trol files Review follow-up: the nested-repository walk now refuses at its depth and directory bounds instead of skipping deeper entries and dependency folders, a worktree pointer is mounted read-only so a writable run cannot repoint the workspace at metadata it built, and control entries a repository lacks are mounted read-only from empty placeholders so they cannot be created.
Review follow-up: the unit and conformance suites now build a worktree inside the workspace whose commondir resolves outside it, and assert the refusal and its reason.
Review follow-up: a permission or I/O error while walking used to skip the directory, which could hide a repository with writable config and hooks. Missing entries still mean nothing to pin; every other inspection failure refuses the command.
b6aa02c to
81f6f5f
Compare
|
Thank you @eXsoR65. This is merged into main with your commits under your own name, so you're listed as a TensorFold contributor. It ships in the next release, credited to you in the changelog and the release notes. |
What this changes
Closes the two git gaps that kept the Linux command sandbox out of #1122. Reopened after #1699 was
closed for inactivity, refreshed onto
upstream/maind6c4cce60. The bubblewrap backend isback on top of current
main, with nested repositories pinned and worktrees that reach outside theworkspace refused. It stays opt-in (
TENSORFOLD_LINUX_SANDBOX=1); Linux commands keep failingclosed without it.
Fixes #1693.
What was broken
.gitwas pinned. A repository nested under theworkspace, or a submodule, let a sandboxed command rewrite its
configand planthooks..gitis a file (gitdir: …), the real metadata can live outside theworkspace. The profile never mounted it, and the command ran anyway — unprotected, not refused.
What it does now
.gitunder the workspace is pinned like the root: writable bind, read-onlyconfig,config.worktree,hooks,info. The walk covers dependency folders and symlinked directoriesinside the workspace, and it refuses at its bounds (32 levels, 50,000 directories) instead of
pinning a subset. A path it cannot inspect (permission denied, I/O error) also refuses, because
skipping it could hide a repository; only a missing entry means there is nothing to pin.
writable run cannot create
config.worktree,hooksorinfo..gitpointer file is mounted read-only, so a run cannot repoint the workspace atmetadata it built itself.
commondirlies outside the workspace is refused; so isa workspace with no repository, because bwrap cannot deny creating
.gitby name. Refusal returnscode 126 with the reason, and nothing runs. Both suites cover the outside-
commondircase: aworktree inside the workspace whose shared directory points outside it.
pre-change worktree handling fails "Missing expected exception"; dropping the pointer freeze fails
the conformance pointer-rewrite case, and dropping the placeholders fails the control-file case.
Receipt
6f76c40a:npm test857/857 passed, 0 failed; typecheck clean;linux-port-docsguard clean;git diff --checkclean.config/hooksread-only, worktree refusal, network denial/allowing, cancellation.pass. No distro other than Debian 13.
desktop,desktop-linux,appimage-linux,mobile,pytest,zig*,benchmark-clients).atc overlapreports no conflicting pull requests for the seven changed files,though it marks its own coverage incomplete (
otherPullRequestsLimit,pullRequestsLimit,pullFilesUnavailable,timeLimit).atc whofound no open pull request or worktree touching anyof the seven files.
Limits
mount rule.