Skip to content

Release 0.10.2

Latest

Choose a tag to compare

@nogginly nogginly released this 24 Nov 19:57
Immutable release. Only release title and notes can be modified.
aad9727

Cordon 0.10.2

Cordon is a Crystal shard that runs shell commands inside a platform-native sandbox with a configurable access policy. It works on macOS (via sandbox-exec / Seatbelt), Linux (via bwrap / Bubblewrap) and, as a preview, Windows 11 (via Microsoft's MXC wxc-exec.exe), presenting all three as a single clean API.

Changes

  • Ruby: gems from GEM_HOME and GEM_PATH - The sandbox does not inherit your environment, so gems that a version manager keeps outside Ruby's defaults were not found. chruby, for one, sets GEM_HOME to ~/.gem/ruby/<full version>, where Ruby looks in ~/.gem/ruby/<API version>. Preset::Ruby.for_executable now takes optional gem_home: and gem_path:: each directory that exists is granted read-only, and the variable is set. Nothing is read from the environment unless you pass it: for_executable(path, gem_home: ENV["GEM_HOME"]?, gem_path: ENV["GEM_PATH"]?). A directory that does not exist yet still gets the variable, but no grant. The static presets take no such arguments.
  • CLI: --ruby-gem-env - With --ruby, cordon run and cordon inspect pass their own GEM_HOME and GEM_PATH to the preset: cordon run --ruby $(which ruby) --ruby-gem-env -- ruby script.rb. It is an error without --ruby, and warns when neither variable is set. --ruby alone still reads nothing from your environment.
  • Ruby: the user gem directory is granted only if it exists - The presets granted ~/.gem unconditionally, which bwrap cannot bind when it is absent, and missed the directory RubyGems uses instead in that case, ~/.local/share/gem. They now grant whichever of the two exists. Preset::Ruby.user_gem_dirs returns them.
  • Python: for_venv activates the venv - Preset::Python.for_venv now sets VIRTUAL_ENV and puts the venv's executables directory (bin, or Scripts on Windows) first on PATH, as the venv's activate script does. Before, python3 was the venv's only if your own shell had activated it, so a sandbox started elsewhere ran the base interpreter without the venv's packages. The new path_env: argument, which defaults to your PATH, is what follows the venv's directory. The preset's PATH replaces yours on merge, as Preset::Crystal's does on macOS, so merge it last or pass your own PATH as path_env:.
  • Docs: toolchain variables - DEVELOPMENT.md now records which variables each toolchain needs in a cleared environment and why the others are left out, with the checks behind it.

Known issues

  • Preset::Crystal grants no network, so shards install and shards update need --allow-network (or allow_network in the policy). Without it, git fails to clone because its HTTPS helper cannot read /etc/ssl/openssl.cnf, which the macOS runner grants only with network access. With it they work, verified on macOS.
  • Preset::Crystal is verified on macOS with the Command Line Tools and on Ubuntu; Xcode.app installs and other Linux distributions are not yet tested. Windows is unsupported: build raises UnsupportedPlatformError.
  • Python and Ruby test suites that write temporary files need a TMPDIR the policy grants: without one, tempfile and Dir.tmpdir fall back to /tmp, which the macOS runner does not grant. Grant a directory read-write and set TMPDIR in policy.env.
  • Merging Preset::Python.for_venv with Preset::Crystal on macOS leaves only the PATH of whichever is merged last.
  • Linux: Preset::System does not grant /etc/alternatives, so on Debian-family systems tools reached through it, such as awk, editor and pager, are not found inside the sandbox.
  • macOS: a sandboxed process can create semaphores under /CRYSTAL/. Semaphore names are shared across the machine, so it could take the name another Crystal program needs for its next thread, or exhaust the system's semaphore limit. Both are denial of service, not escape; Cordon does not limit a sandboxed process's resources in any case.
  • macOS: killing a spawned command ends that process only; processes it started keep running, still sandboxed, and can hold the caller's pipes open. Linux and Windows end the whole process tree (#47).
  • Windows: MXC 1.0.0 no longer carries the "early preview, not a security boundary" warning of earlier releases, but PSEC is new and may change between Windows updates. Cordon pins the MXC version it is tested against; re-run cordon confirm after Windows updates (#41).
  • Windows: a batch file (.bat, .cmd) can only be run with shell: true, because its arguments cannot be quoted safely.
  • Windows: tested on Windows 11 Enterprise 25H2, on ARM (a VM and GitHub's Windows 11 ARM runner, with cordon.exe under x64 emulation) and on an x64 laptop, where cordon.exe runs natively. Other editions such as Windows 11 Pro are not yet tested.
  • Windows: the process security environment arrives with recent Windows 11 25H2 updates. A laptop on build 26200.8893 lacked it and gained it on 26200.9448; if check-windows.ps1 reports it unavailable, install the latest updates and check again.
  • Windows: only an x64 cordon.exe is built; ARM machines run it under emulation (#39).
  • Windows: cordon.exe is unsigned, and some endpoint security products flag the statically linked executable as suspicious (#40).
  • Windows: everything under C:\Windows is readable and executable in the sandbox without a grant (#38).
  • Windows: PowerShell 7, Git Bash, toolchains installed per user, and junctions or symlinks inside granted paths are not yet validated (#34, #35, #36).

For architecture, design decisions, and debugging workflows see DEVELOPMENT.md.