@@ -76,6 +76,19 @@ check_devcontainer_cli() {
7676 fi
7777}
7878
79+ check_no_sys_admin () {
80+ local workspace=" ${1:- .} "
81+ local dc_json=" $workspace /.devcontainer/devcontainer.json"
82+ [[ -f " $dc_json " ]] || return 0
83+ if jq -e \
84+ ' .runArgs[]? | select(test("SYS_ADMIN"))' \
85+ " $dc_json " > /dev/null 2>&1 ; then
86+ log_error " SYS_ADMIN capability detected in runArgs."
87+ log_error " This defeats the read-only .devcontainer mount."
88+ exit 1
89+ fi
90+ }
91+
7992get_workspace_folder () {
8093 echo " ${1:- $(pwd)} "
8194}
@@ -101,19 +114,20 @@ extract_mounts_to_file() {
101114 custom_mounts=$( jq -c '
102115 .mounts // [] | map(
103116 select(
104- (startswith("source=claude-code-bashhistory-") | not) and
105- (startswith("source=claude-code-config-") | not) and
106- (startswith("source=claude-code-gh-") | not) and
107- (startswith("source=${localEnv:HOME}/.gitconfig,") | not) and
108- # Security: read-only .devcontainer mount prevents container escape on rebuild
109- (startswith("source=${localWorkspaceFolder}/.devcontainer,") | not)
117+ (contains("target=/commandhistory,") | not) and
118+ (contains("target=/home/vscode/.claude,") | not) and
119+ (contains("target=/home/vscode/.config/gh,") | not) and
120+ (contains("target=/home/vscode/.gitconfig,") | not) and
121+ (contains("target=/workspace/.devcontainer,") | not)
110122 )
111123 ) | if length > 0 then . else empty end
112124 ' " $devcontainer_json " 2> /dev/null) || true
113125
114126 if [[ -n " $custom_mounts " ]]; then
115127 echo " $custom_mounts " > " $temp_file "
116128 echo " $temp_file "
129+ else
130+ rm -f " $temp_file "
117131 fi
118132}
119133
@@ -207,6 +221,7 @@ cmd_up() {
207221 workspace_folder=" $( get_workspace_folder " ${1:- } " ) "
208222
209223 check_devcontainer_cli
224+ check_no_sys_admin " $workspace_folder "
210225 log_info " Starting devcontainer in $workspace_folder ..."
211226
212227 devcontainer up --workspace-folder " $workspace_folder "
@@ -218,6 +233,7 @@ cmd_rebuild() {
218233 workspace_folder=" $( get_workspace_folder " ${1:- } " ) "
219234
220235 check_devcontainer_cli
236+ check_no_sys_admin " $workspace_folder "
221237 log_info " Rebuilding devcontainer in $workspace_folder ..."
222238
223239 devcontainer up --workspace-folder " $workspace_folder " --remove-existing-container
0 commit comments