feat(security): block user home dirs and SSH/PGP key directories from workspace mount

This commit is contained in:
docker-claude 2026-04-15 08:43:09 +02:00
parent 65ac4c7011
commit c3875397b0

View file

@ -44,7 +44,7 @@ load_env() {
# ─── Workspace volume resolution ────────────────────────────────────────────── # ─── Workspace volume resolution ──────────────────────────────────────────────
# Mounts the current working directory as /workspace inside the container. # Mounts the current working directory as /workspace inside the container.
# Refuses to mount the home directory or system directories. # Refuses to mount home directories, key material, or system directories.
workspace_flag() { workspace_flag() {
local cwd local cwd
cwd="$(pwd)" cwd="$(pwd)"
@ -57,12 +57,19 @@ workspace_flag() {
/home /home
) )
# Prefix blocklist — these and any subdirectory are system internals # Prefix blocklist — block these paths and all subdirectories.
# Covers system internals and credential/key material.
local -a prefix_blocked=( local -a prefix_blocked=(
/bin /sbin /lib /lib64 /bin /sbin /lib /lib64
/etc /usr /var /etc /usr /var
/proc /sys /dev /proc /sys /dev
/boot /run /boot /run
# SSH keys
"$HOME/.ssh"
/root/.ssh
# PGP/GPG keys
"$HOME/.gnupg"
/root/.gnupg
) )
for dir in "${exact_blocked[@]}"; do for dir in "${exact_blocked[@]}"; do
@ -73,9 +80,16 @@ workspace_flag() {
fi fi
done done
# Block any user home directory directly under /home (e.g. /home/alice)
if [[ "$cwd" =~ ^/home/[^/]+$ ]]; then
error "Refusing to mount $cwd as workspace — user home directory."
error "cd into a project subdirectory first."
exit 1
fi
for dir in "${prefix_blocked[@]}"; do for dir in "${prefix_blocked[@]}"; do
if [[ "$cwd" == "$dir" || "$cwd" == "$dir/"* ]]; then if [[ "$cwd" == "$dir" || "$cwd" == "$dir/"* ]]; then
error "Refusing to mount $cwd as workspace — system directory." error "Refusing to mount $cwd as workspace — contains sensitive data."
error "cd into a project subdirectory first." error "cd into a project subdirectory first."
exit 1 exit 1
fi fi