I'm attempting to setup a system that automatically creates a new sandbox on a ssh login to use as a temporary jump box into my server. So to do this I was wonder how to setup lxc to spin up a new shell in the container once there is a ssh connection then destroy that container after the session is closed.
What would be the best way to go about this?
EDIT:
Thanks to everyone that has placed their input. I have been able to devise the method to do this same setup as follows:
/etc/ssh/sshd_config:
match group ssh
forceCommand sudo docker run --rm -t -i busybox /bin/sh
What this does is forces the user session to instantly go into a busybox container then delete the changes on exit. One could change or create their own image and specify this in place of busybox. Though this is included here since the only thing the default busybox container offers is wget and telnet which is good enough for most OOB testing/jump-boxes and this was the use case goal with this design.
ForceCommand lxc-create -f $container_configpath -n jailshel
to the /etc/ssh/sshd_config is a given but how does this destroy the container when the ssh session is closed?ForceCommand sh -i ( readonly con='-n jailshel'; trap 'lxc-destroy $con' EXIT $andtherest ; lxc-create -f $container_configpath $con )
or something. Run it as a child of some process that will exit when a connection quits and execute lxc-destroy in a trap.