Skip to content

feat: read-only remote mounts (SharePoint / Google Drive) for caller-supplied folders - #17

Merged
TomasPalsson merged 2 commits into
apro-deployfrom
feat/remote-mounts
Dec 1, 2026
Merged

TomasPalsson merged 2 commits into
apro-deployfrom
feat/remote-mounts

Conversation

@TomasPalsson

@TomasPalsson TomasPalsson commented Dec 1, 2026 •

Copy link
Copy Markdown

What

Opt-in read-only remote mounts on POST /v1/exec. A caller (vitinn-ui) can show a linked SharePoint or Google Drive folder inside the sandbox at /mnt/sharepoint or /mnt/google-drive. Then ls, os.listdir, glob, open and pandas work on it, with no path rewriting.

Design and rules: docs/remote-mounts/README.md.

How

  • Request. New optional field remote_mounts: [{ path, entries: [{ path, type, size?, file? }] }].
    • An entry with file is loaded: it is a normal RequestFile the caller uploaded through /upload.
    • An entry without it is a stub.
  • Runner.
    • Builds each tree outside the workspace:
      • dirs are 0555;
      • loaded files are 0444, fetched like other input refs (egress gateway, or the pushed input cache on lambda-microvm);
      • stubs are empty files with mode 0000.
    • Binds each tree read-only (nosuid, nodev, noexec) at its path, and removes it on every exit path. A startup sweep clears leftovers.
  • Python.
    • A runner-owned sitecustomize audit hook turns an open of a stub into a clear PermissionError.
    • At exit it reports the stubs it hit between sentinel lines tied to the job's nonce. The runner strips those lines.
    • /v1/exec returns the stubs as remote_mounts_required: { read: [...] }, so the caller can approve, load and run again.

Security

  • No credentials and no network enter the sandbox. The caller reads the remote source as the signed-in viewer and applies its own approvals.
  • Loaded refs get the same checks as files[]. They go through the same authorizeRequestedFiles call. They are also in the signed execution manifest, in egress masking and in input delivery, and the runner re-derives that scope. Covered by a cross-half test with a pinned fixture on both sides.
  • The legacy no-body-hash cache-key guard covers mount refs too.
  • Strict path validation on both service and runner:
    • no .., ., leading / or backslash;
    • no control characters;
    • segment and path length caps, and depth ≤ 16;
    • no duplicates, and no file that is also a parent.
  • Mount paths must match ^/mnt/[a-z0-9-]+$ and must not be /mnt/data.
  • Limits:
    • ≤ 4 mounts, ≤ 5000 entries, and ≤ 64 loaded files;
    • files[] + loaded files ≤ 256, the runner's limit, so nothing is accepted and then rejected after enqueue.
  • A forged sentinel can only name stubs this request declared.
  • Fetches are abortable and bounded by prime_concurrency.
  • Unsupported routes fail closed: remote-bridge returns 400 remote_mounts_unsupported, and /exec/programmatic rejects the field.

LibreChat compatibility

LibreChat never sends remote_mounts, and null is treated as absent. Without the field, behaviour is byte-identical. Tests pin each part:

  • the payload keys;
  • the manifest and grant contents;
  • input delivery;
  • nsjail config and args;
  • env (PYTHONPATH unchanged);
  • stderr handling, and the response keys.

Requests without the field never create the per-job nonce.

Rollout

Deploy the runner and egress gateway before the API and worker. An old gateway does not mask mount refs, and the runner then fails closed with scope_mismatch.

Tests

Run on bun 1.4.4, as in CI:

  • api: 103 pass across the new and touched files (remote-mounts, the hook with real python3, job, v2 route, execution-manifest-request, nsjail).
  • service: 367 pass across 24 files.
  • The full api suite has only the 14 environment failures that also fail at the base (package-init/build-packages launchers, hardened secure-startup).
  • tsc: no new errors in api or service.
  • Reviewed by adversarial passes for security, LibreChat compatibility and the service/runner contract. Their findings are fixed, including a manifest scope mismatch that would have rejected every loaded mount.

Not run here: a real nsjail / Lambda MicroVM execution. Please verify on a staging runner before it goes to production.

Update: copy-on-write (c5071fe)

  • Mounts are now writable inside the jail (noexec, nosuid, nodev kept; stubs stay runner-owned 0000). The remote source is never touched.

  • After the run, each loaded file is re-hashed by its known path, and the tree is walked for new regular files. The walk uses lstat only and has a shared budget of 20,000 entries.

  • Changed and new files come back as ordinary outputs with remote_mount: {path, change: "modified" | "created"}, only when the request had remote_mounts.

  • Host-file safety. Every content read opens the file once:

    • O_NOFOLLOW|O_NONBLOCK;
    • fstat must show a regular file;
    • /proc/self/fd must resolve under the tree root;
    • parents must be real directories.

    The hash and the upload both read from that one handle. So a swapped symlink can't read outside the tree, and a FIFO (a pipe) can't hang the runner. Regression tests cover a symlinked parent dir, a symlink at a loaded path, a FIFO, and an fd that resolves outside the root.

  • Skips go into artifact_truncation (max_files, unreadable, size), never silently dropped.

  • Known small items, recorded and not fixed:

    • Oversized changed files use up handle slots, so a later small file can be recorded as unreadable.
    • A stub deleted and rewritten by the code is ignored.

…nts on /v1/exec)

Opt-in per request. A caller (vitinn-ui) sends the tree of a linked remote
folder (SharePoint, Google Drive) plus refs to files it already uploaded and
is authorized to read. The runner shows the tree read-only at /mnt/<name>:
loaded files have bytes, the rest are 0000 stubs. A Python audit hook reports
stub opens; /v1/exec returns them as remote_mounts_required so the caller can
approve, load and run again. No credentials or network enter the sandbox.

Requests without remote_mounts (LibreChat) are byte-identical: payload,
manifest, nsjail args, env and response. See docs/remote-mounts/README.md.
Mounts are now writable inside the jail (noexec, nosuid, nodev kept; stubs
stay runner-owned 0000). After the run every loaded file is re-hashed by its
known path and the tree is walked (shared 20000-entry budget) for new
regular files. Each changed file is opened once (O_NOFOLLOW|O_NONBLOCK,
fstat isFile, /proc/self/fd verified under the tree root, parents checked to
be real directories) and hashed and uploaded from that same handle, so a
swapped symlink or FIFO can never read outside the tree or hang the runner.
Outputs carry remote_mount {path, change: modified|created}; the service
passes it through only when the request had remote_mounts. Skips are
recorded in artifact_truncation, never silent.
@TomasPalsson
TomasPalsson merged commit 369337f into apro-deploy Dec 1, 2026
23 of 24 checks passed
@TomasPalsson
TomasPalsson deleted the feat/remote-mounts branch December 1, 2026 09:37
TomasPalsson added a commit that referenced this pull request Dec 2, 2026
…to v1.11.0 (#21)

* feat: read-only remote mounts (SharePoint / Google Drive) for caller-supplied folders (port of #17 to v1.11.0)

* ci: move the jail-policy baseline past remote_mounts (binds only, seccomp unchanged)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant