Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/calibration/scripts/tc_jail_lib.sh # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / calibration / scripts / tc_jail_lib.sh` 96 lines ยท 3813 bytes Raw Blame History 1 # SPDX-License-Identifier: Apache-2.0 2 # Copyright 2026 Drake Stapleton (AIEN / aien-dev) 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # Turing calibration (CAL-0 / EXP-001): shared bubblewrap jail helpers. 17 # Sourced by candidate_env.sh, evaluator_env.sh, generate_sealed_data.sh and 18 # test_blinding.sh. calibration/docs/BLINDING_PROTOCOL.md explains the design. 19 # 20 # The jails are ALLOWLISTS: the new mount namespace starts empty and only the 21 # paths bound here exist inside it. A path that is not bound (for example the 22 # sealed root inside the Candidate Environment) does not exist for any process 23 # in the jail. Enforcement is the Linux kernel (mount + user + pid + net 24 # namespaces via /usr/bin/bwrap, no sudo). It covers every process launched 25 # through a wrapper; it does not cover a process of the same uid that is started 26 # outside a wrapper (see BLINDING_PROTOCOL.md section 5 for the uid upgrade). 27 28 TC_SEALED_ROOT="${TC_SEALED_ROOT:-$HOME/aien-data/turing-cal/sealed}" 29 TC_EVAL_ROOT="${TC_EVAL_ROOT:-$HOME/aien-data/turing-cal/eval}" 30 TC_BWRAP="${TC_BWRAP:-/usr/bin/bwrap}" 31 32 tc_die() { echo "tc-jail: $*" >&2; exit 3; } 33 34 tc_real() { realpath -m -- "$1"; } 35 36 # tc_overlaps A B: true when A equals B, or one contains the other. 37 tc_overlaps() { 38 local a b 39 a="$(tc_real "$1")" 40 b="$(tc_real "$2")" 41 [ "$a" = "$b" ] && return 0 42 case "$a/" in "$b"/*) return 0 ;; esac 43 case "$b/" in "$a"/*) return 0 ;; esac 44 return 1 45 } 46 47 # tc_refuse_hidden PATH LABEL: refuse to bind a path that overlaps a hidden root. 48 tc_refuse_hidden() { 49 local p="$1" label="$2" h 50 shift 2 51 for h in "$@"; do 52 if tc_overlaps "$p" "$h"; then 53 tc_die "refusing to bind $label '$p': it overlaps hidden path '$h'" 54 fi 55 done 56 } 57 58 # Base system: read-only /usr and /etc, merged-usr symlinks, private /proc, 59 # minimal /dev, empty /tmp and HOME, no user namespaces inside, all namespaces 60 # unshared (network included), killed with the parent, new session (no tty 61 # injection). Output: one argument per line in TC_ARGS (bash array). 62 tc_base_args() { 63 TC_ARGS=( 64 --unshare-all --unshare-user --disable-userns 65 --die-with-parent --new-session 66 --ro-bind /usr /usr 67 --ro-bind /etc /etc 68 --proc /proc 69 --dev /dev 70 --tmpfs /tmp 71 --tmpfs /home 72 --dir "$HOME" 73 --setenv HOME "$HOME" 74 --setenv PATH /usr/local/bin:/usr/bin:/bin 75 --unsetenv SSH_AUTH_SOCK 76 --unsetenv DBUS_SESSION_BUS_ADDRESS 77 ) 78 local l 79 for l in bin sbin lib lib32 lib64 libx32; do 80 if [ -L "/$l" ]; then 81 TC_ARGS+=(--symlink "$(readlink "/$l")" "/$l") 82 elif [ -d "/$l" ]; then 83 TC_ARGS+=(--ro-bind "/$l" "/$l") 84 fi 85 done 86 } 87 88 tc_ro() { [ -e "$1" ] || tc_die "missing path '$1'"; TC_ARGS+=(--ro-bind "$(tc_real "$1")" "$(tc_real "$1")"); } 89 tc_rw() { [ -e "$1" ] || tc_die "missing path '$1'"; TC_ARGS+=(--bind "$(tc_real "$1")" "$(tc_real "$1")"); } 90 91 tc_have_bwrap() { 92 [ -x "$TC_BWRAP" ] || tc_die "bubblewrap not found at $TC_BWRAP" 93 "$TC_BWRAP" --unshare-all --unshare-user --disable-userns --ro-bind /usr /usr \ 94 --symlink usr/bin /bin --symlink usr/lib /lib /usr/bin/true 2>/dev/null || 95 tc_die "bubblewrap cannot create an unprivileged sandbox on this host" 96 }