feat(sandbox): virtual-by-default capability model (sandbox:/env:)#372
Open
davydog187 wants to merge 1 commit into
Open
feat(sandbox): virtual-by-default capability model (sandbox:/env:)#372davydog187 wants to merge 1 commit into
davydog187 wants to merge 1 commit into
Conversation
Replace the per-path deny-list with a single virtual/host toggle: - Lua.new(sandbox: true) (default) installs the virtual os/io/loader implementations; sandbox: false installs the host ones. The choice is made once at install time (no per-call mode branch). - Lua.new(env: [...]) injects env values the sandboxed os.getenv reads; the host environment is never touched in the default sandbox. - os gains real execute/remove/rename; sandboxed remove/rename/tmpname operate on the VFS, host variants touch real disk. os.execute is denied when sandboxed. - require/loadfile/dofile resolve from the VFS (anchored at /lua/deps) when sandboxed, real disk under sandbox: false. load/loadstring compile strings in-memory in both modes. - Add Lua.write_file/3, put_dep/3, read_file/2 to seed and harvest the VFS. - Remove @default_sandbox, the :sandboxed/:exclude options, and Lua.sandbox/2; a deprecation shim maps the legacy options to :sandbox for one minor. - io is installed as an explicit library (stubbed for now; full virtualization follows) preserving the sandboxed table-of-functions shape. BREAKING: see CHANGELOG (docs rewrite follows in a later PR).
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.
Virtual-by-default, PR 2/4 — capability model
Replaces the per-path deny-list with a single virtual ↔ host toggle. The default VM is now virtual and sandboxed; opting out installs the host implementations.
API
Mechanics
osinstallsgetenv/tmpname/remove/rename/executeas virtual or host variants based onsandbox:.osgains realexecute/remove/rename. Sandboxedremove/rename/tmpnameuse the VFS;os.executeis denied. Host variants touch the real disk/shell.require/loadfile/dofileresolve from the VFS (anchored at/lua/deps) when sandboxed, real disk undersandbox: false.load/loadstringcompile strings in-memory in both modes.Lua.write_file/3,Lua.put_dep/3,Lua.read_file/2.iois now an explicit library (stubbed pending full virtualization in PR 3/4), preserving the sandboxed table-of-functions shape (io_stub_testgreen).Breaking changes
Lua.new(sandboxed:/exclude:)andLua.sandbox/2. A deprecation shim accepts the legacy options for one minor (sandboxed: []→sandbox: false) with anIO.warn.os.getenvreturns injected/nilinstead of raising;require/loadfile/dofilenow work against the VFS instead of being denied.Verification
mix test: 2606 passed (+16 new intest/lua/sandbox_test.exs), 0 failuresmix test --only lua53: 20/9/0 (no regression)mix format+mix compile --warnings-as-errors: cleansandboxed: []test sites tosandbox: false(behavior-identical)