Skip to content

feat(sandbox): app sandbox secrets in the fakechroot and namespace jails - #3394

Draft
ckelly17 wants to merge 2 commits into
devfrom
Python-jail-secrets
Draft

ckelly17 wants to merge 2 commits into
devfrom
Python-jail-secrets

Conversation

@ckelly17

@ckelly17 ckelly17 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

A project's SANDBOX_SECRETS / SANDBOX_SECRET_<NAME> only reached OpenShell. In the fakechroot and namespace jails, secret() raised "no sandbox secrets are available", and a project's custom code reads the .smss only for its owners. So an app had no way to give its Python a credential for the people who use it.

With this PR, the same .smss and the same secret() call work in every sandbox mode. In the jails the code gets the value itself, not a placeholder. Those jails have nothing in the request path that could swap a placeholder for the value, so the declared hosts are checked for form, so the project moves to OpenShell unchanged, but they are not enforced. The docs say so.

It also fixes a read-only mount bug in the namespace launcher that affects every live read-only inject, viewer copies of projects included.

Changes Made

  • New JailSecrets (src/prerna/util/sandbox/JailSecrets.java): when a jail loads a project, it writes the project's declared secrets to <user chroot>/<BaseFolder>/sandbox-secrets/secrets.json, keyed by project. The folder is 0700 and the file 0600. The file is written to a temp file and renamed into place, so code reading it never sees half a file. It reuses OpenShellSecrets' parser and project keys, which are now public.
  • SymlinkHelper:
    • creates the user's secrets folder when it sets up a fakechroot or namespace jail, before any project loads, and in namespace mode mounts it read-only at <BaseFolder>/sandbox-secrets
    • writes a project's secrets each time the jail loads that project
  • py/smss_secrets.py: when the secrets folder is present, the code is in a jail and reads only secrets.json. It never falls back to OpenShell's placeholders.json, which is in the shared insight cache that other users can write to. Outside a jail it reads the OpenShell file as before.
  • sandbox_launcher.inject(..., "ro"): remounting the destination read-only after the bind does not reach the interpreter's copy of the mount, so it stayed writable. inject now makes a private read-only staging bind first and binds that into the jail. The self-test checks that a write from inside a read-only grant fails with EROFS.
  • Docs: executor_sandbox.md (jail section) and sandbox_configuration.md. They say plainly that file permissions do not keep users apart in fakechroot: every user's Python runs as the same host user, and fakechroot only rewrites paths.

How to Test

  1. cd py && python3 -m unittest testing.test_smss_secrets. Expected: 6 tests OK. They include a test that a jail with no secrets.json refuses rather than reading a planted placeholders.json.
  2. python3 py/sandbox_launcher.py --self-test. Expected: ALL PASS (14/14), including "interpreter cannot write to read-only projectD (EROFS)".
  3. mvn test -Dtest='JailSecretsUnitTests,SymlinkHelperUnitTests'. nobodyCanWriteToAViewersCopy fails when run as root, because root ignores file permissions. It fails the same way on dev.
  4. By hand: declare SANDBOX_SECRETS with a value in a project's .smss, load it in a fakechroot or namespace worker, then call secret("<NAME>") from Python. Expected: the value. A user whose jail has loaded no project with secrets gets the "no sandbox secrets are available" KeyError.

Notes

  • Every user who can load the app can read its secret values from Python, and use them anywhere the jail's network reaches. Use OpenShell where that matters.
  • A user who loses access keeps the values in their chroot folder until it is removed, as OpenShell keeps a provider attached until the sandbox goes.
  • Related draft PR from fix-namespace-shared-mounts: it keeps py/ and the insight cache out of namespace jails but does not change inject(). The read-only inject fix here is what makes viewer copies read-only, so the two should land together. sandbox-customization rewrites the same branch of inject(). That branch's own self-test fails "read-only project cannot be written" with and without --require-ro, so whichever merges second should keep the staging approach from this PR when resolving the conflict.

SANDBOX_SECRETS and SANDBOX_SECRET_<NAME> only reached OpenShell. In the
fakechroot and namespace jails secret() raised "no sandbox secrets are
available", and a project's custom code reads the smss only for its
owners, so an app had no way to give its Python a credential for the
people who use it.

When a jail loads a project, JailSecrets writes its declared secrets to
<user chroot>/<BaseFolder>/sandbox-secrets/secrets.json, by project key,
owner-only. fakechroot sees it at <BaseFolder>/sandbox-secrets inside the
chroot; the namespace jail mounts the folder there read-only. secret()
reads that file first and OpenShell's placeholders after, so app code and
the .smss are the same in every mode. The jails hand over the value
itself: the hosts are checked for form, not enforced.

A read-only inject in the namespace launcher left the interpreter's copy
writable: the mount propagated at the bind, and the read-only remount
after it does not propagate. inject now binds a private read-only mount
instead, and the self-test checks that a read-only grant refuses writes.
secret() read the jail's secrets.json first and fell back to OpenShell's
placeholders.json when it was missing. A user whose jail had loaded no app
with secrets has no secrets.json, so secret() read placeholders.json from
the shared insight cache, which other users can write to.

SEMOSS now makes the user's sandbox-secrets folder when it sets up a
fakechroot or namespace jail, before any project is loaded, and the
namespace jail mounts it read-only then. secret() takes the folder as the
sign that it runs in a jail and reads only secrets.json there; outside a
jail it reads the OpenShell file as before.

The docs also say that the file permissions do not keep users apart in
fakechroot: every user's Python runs as the same host user, and fakechroot
only rewrites paths.
@snyk-io

snyk-io Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

✅ Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

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