Skip to content

Instantly share code, notes, and snippets.

@jaymecd
Last active November 10, 2021 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaymecd/94fe9a60814625b5ef2c2e95443b8e99 to your computer and use it in GitHub Desktop.
Save jaymecd/94fe9a60814625b5ef2c2e95443b8e99 to your computer and use it in GitHub Desktop.
auto remount noexec volume

start a contaniner:

$  docker run --rm -ti --privileged alpine:latest sh

next, run code within a container

setup:

$ apk --no-cache add xfsprogs util-linux 
$ dd if=/dev/zero of=/xfs.img bs=1M count=100
$ mkfs.xfs /xfs.img
$ mkdir -p /var/lib/docker
$ mount -o noexec,nodev /xfs.img /var/lib/docker

simulate git checkout:

$ cd /var/lib/docker
$ mkdir -p builds/bin
$ printf '#!/bin/sh\nset -ex\ndate\n' > builds/bin/run.sh
$ chmod +x builds/bin/run.sh
$ cd builds

run script:

$ ./bin/run.sh
sh: ./bin/run.sh: Permission denied

discover and remount noexec volume by current path:

$ findmnt -lnf -o target,options -T . | awk '$2 ~ /noexec/ {print $1}' | xargs -rt -- mount -o remount,exec
mount -o remount,exec /var/lib/docker

re-run script:

$ ./bin/run.sh
+ date
Tue Nov  9 20:06:12 UTC 2021

END

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment