Repository navigation
Conversation
…a namespace jail In NAMESPACE mode, SymlinkHelper's chroot setup asked for the SEMOSS py/ folder and the whole INSIGHT_CACHE_DIR to be linked, and symlinkFolder turns each into a read-write namespace mount. Both are under the SEMOSS home, so the launcher accepted them and replayed them into every user's jail. User code could then read and write other users' insight folders, and rewrite the py/ code that every python worker on the server runs, including the unjailed engine workers. enqueueOrInject now refuses any mount at, above or inside the py folder, and at or above the insight cache, comparing real paths. The launcher still binds py/ read-only, and individual insight folders are still mounted when granted. Fakechroot links and OpenShell are unchanged.
The launcher binds the worker code folder (--py-folder) into the jail and then remounts it read-only, but the remount was best-effort and its result was never checked. If it was refused, py/ stayed writable inside the jail with nothing logged, and code written there runs in every python worker on the server. _bind now checks the result with statvfs. A refused remount is retried with the mount flags the outer mount already carries (a user namespace refuses a remount that drops a locked flag such as nosuid or nodev). For a strict path, the py folder, a bind that is still writable raises EROFS and the sandbox does not start. Other read-only paths stay best-effort. The self-test now binds a strict read-only code folder and checks the interpreter can read it but not change it; unit tests cover the retry and the fatal path, which a normal kernel does not reach.
… workers The jailed worker runs as the same host user as Tomcat and every other worker on the server, and shared their PID namespace. Without /proc it could still find them with kill(pid, 0) and stop them: a probe in the jail found and SIGTERMed a stand-in Tomcat. Its root folder and the inject-root skeletons were also writable, on the host disk with no quota. - The supervisor unshares a PID namespace before forking the jail. Its first process is a small init (PID 1) that starts the worker, forwards stop signals (PID 1 ignores signals it has no handler for, so a worker that was PID 1 would ignore Java's SIGTERM), reaps orphans, and clears the namespace when the worker exits. The worker sees only itself and init; a stand-in Tomcat outside cannot be signalled (ESRCH). - On a stop signal the supervisor stops the jail and reaps it, killing it after a 5 s grace, so init is never left a zombie. Java's destroy (a SIGTERM to every process), a SIGTERM to the supervisor alone, and a worker that ignores SIGTERM all end with no processes left. - The jail root and inject-root skeletons are remounted read-only in the interpreter's own view; /tmp, rw binds and live injects stay writable. - The python worker starts in its insight folder, like the node worker, and gets HOME=/tmp when the server's HOME is not usable in the jail. The self-test checks PID 1, that an outside process cannot be signalled, the read-only root and skeleton, a writable /tmp and a writable rw inject (21/21).
Contributor
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
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.
Description
Closes three holes in the namespace sandbox (
py/sandbox_launcher.py):py/folder and the whole insight cache mounted read-write. User code could rewrite the Python code every worker on the server runs, including the unjailed engine workers, and read or write other users' insight folders.py/was best-effort and never checked, so a refused remount left it writable with nothing logged.Changes Made
SymlinkHelper.enqueueOrInjectrefuses any namespace mount at, above or insidepy/, and at or above the insight cache, comparing real paths. Individual insight folders are still mounted when granted. Fakechroot links and OpenShell are unchanged._bind/_make_read_only: a refused read-only remount is retried with the mount flags a user namespace locks (nosuid, nodev, noexec, atime), and the result is checked withstatvfs. Forpy/(the--py-folder), a bind that is still writable raisesEROFSand the sandbox does not start. Other read-only paths stay best-effort./tmp, read-write binds and live injects stay writable.HOME=/tmpwhen the server'sHOMEis not usable in the jail.How to Test
python3 py/sandbox_launcher.py --self-test(needs unprivileged user namespaces). Expected:ALL PASS (21/21). The new checks cover PID 1, an outside process that cannot be signalled, the read-only root and skeleton, a writable/tmp, a writable read-write inject and read-only worker code.cd py && python3 -m unittest testing.test_sandbox_launcher_read_only. Expected: 4 tests OK. They cover the locked-flag retry and the fatal path a normal kernel does not reach.mvn test -Dtest=SymlinkHelperUnitTests. Covers the refused mounts.nobodyCanWriteToAViewersCopyfails when run as root, because root ignores file permissions. It fails the same way ondev.Notes
sandbox-customization, which also changes read-only remounts, the sharedpy/and insight-cache mounts, and adds an opt-in PID namespace. The two take different approaches. This PR never mounts the shared folders and always uses a PID namespace. That branch mountspy/read-only, keeps sharing the whole insight cache by default, and makes the PID namespace opt-in. We should settle on one model before either merges. Expect conflicts ininject(),_self_test()andSymlinkHelper.inject()remounts the destination read-only after the bind, and that change does not reach the interpreter's copy of the mount, so viewer copies of projects stay writable. This PR does not changeinject(). The fix (a staged private read-only bind) is in the jail secrets draft PR fromPython-jail-secrets, so the two should land together._run_init,_stop_on_signal) only run in real mode and have no automated test.PR_SET_PDEATHSIGon init, plus agetppid()check right after it, would close that.fork()and itssignal.signal()calls is dropped.