File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,7 @@ You can run `sandbox-run bash` to spawn **interactive shell inside the sandbox**
125125#### Environment variables
126126
127127* ` BWRAP_ARGS= ` – Extra arguments passed to ` bwrap ` process; space or line-delimited (if arguments such as paths themselves contain spaces).
128+ * ` SANDBOX_RO_BIND= ` – List of additional path glob expressions to mount read-only inside the sandbox.
128129* ` VERBOSE= ` – Print full ` exec bwrap ` command line right before execution.
129130
130131
Original file line number Diff line number Diff line change @@ -34,6 +34,10 @@ format_args () {
3434formatted_cmdline=" $( format_args " $@ " ) "
3535warn () { echo " sandbox-run: $* " >&2 ; }
3636
37+ lf='
38+ '
39+ split_args_by_lf () { printf ' %s' " $1 " | case " $1 " in * $lf * ) cat ;; * ) tr ' ' ' \n' ;; esac ; }
40+
3741# RO-bind select paths
3842paths='
3943/etc/resolv.conf
@@ -51,14 +55,13 @@ paths='
5155/usr
5256'
5357
54- lf='
55- '
56- split_args_by_lf () { printf ' %s' " $1 " | case " $1 " in * $lf * ) cat ;; * ) tr ' ' ' \n' ;; esac ; }
5758# Support BWRAP_ARGS passed to the process as well as via .env file
5859prev_BWRAP_ARGS=" ${BWRAP_ARGS:- } "
5960# Init env from dotenv file
6061# shellcheck disable=SC2046
6162[ ! -e " $cwd /.env" ] || { . " $cwd /.env" ; export $( grep -Pzo ' (?m)^\w*(?==)' " $cwd /.env" | tr ' \0' ' \n' ) ; }
63+ paths=" $( split_args_by_lf " ${SANDBOX_RO_BIND:- } " | tr ' ,' ' \n' )
64+ $paths " # Add paths from SANDBOX_RO_BIND
6265IFS=" $lf " # Split args only on newline
6366# shellcheck disable=SC2046
6467set -- $( split_args_by_lf " ${BWRAP_ARGS:- } " ) $( split_args_by_lf " ${prev_BWRAP_ARGS:- } " ) " $bin " " $@ "
@@ -82,7 +85,7 @@ for var in $(env -0 |
8285 paste -z -s -d ' |' ) )$" |
8386 paste -z -s -d ' |' ) )=" |
8487 grep -Ezv -e ' ^(_|LS_COLORS|PS1)=' |
85- grep -Ezv -e ' ^(BWRAP_ARGS)=' |
88+ grep -Ezv -e ' ^(BWRAP_ARGS|SANDBOX_RO_BIND )=' |
8689 tr ' \0' ' \037' ) ; do
8790 set -- --setenv " ${var%% =* } " " ${var#* =} " " $@ "
8891done
Original file line number Diff line number Diff line change 1+ #! /bin/sh
2+ set -eu
3+
4+ . " ${0%/* } /_init.sh"
5+
6+ SANDBOX_RO_BIND=' /etc/shad*,/etc/motd*' \
7+ sandbox-run sh -c ' test -f /etc/shadow; test -f /etc/motd'
You can’t perform that action at this time.
0 commit comments