2017-09-17 12:00:48 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import commands
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
|
|
DOCKERFILE = r"""
|
|
|
|
FROM debian:stable
|
|
|
|
RUN apt-get update
|
|
|
|
RUN \
|
2017-09-17 15:37:32 +00:00
|
|
|
apt-get install -y python2.7 openssh-server sudo rsync git && \
|
2017-09-17 12:00:48 +00:00
|
|
|
apt-get clean
|
|
|
|
RUN \
|
|
|
|
mkdir /var/run/sshd && \
|
|
|
|
echo '%sudo-nopw ALL=(ALL:ALL) NOPASSWD:ALL' > /etc/sudoers.d/001-sudo-nopw && \
|
|
|
|
echo i-am-mitogen-test-docker-image > /etc/sentinel && \
|
|
|
|
groupadd sudo-nopw && \
|
|
|
|
useradd -m has-sudo -G sudo && \
|
|
|
|
useradd -m has-sudo-pubkey -G sudo && \
|
|
|
|
useradd -m has-sudo-nopw -G sudo-nopw && \
|
|
|
|
useradd -m webapp && \
|
|
|
|
( echo 'root:x' | chpasswd; ) && \
|
|
|
|
( echo 'has-sudo:y' | chpasswd; ) && \
|
|
|
|
( echo 'has-sudo-nopw:y' | chpasswd; ) && \
|
|
|
|
mkdir ~has-sudo-pubkey/.ssh
|
|
|
|
|
2017-09-17 15:37:32 +00:00
|
|
|
COPY data/docker/has-sudo-pubkey.key.pub /home/has-sudo-pubkey/.ssh/authorized_keys
|
2017-09-17 12:00:48 +00:00
|
|
|
RUN \
|
|
|
|
chown -R has-sudo-pubkey ~has-sudo-pubkey && \
|
|
|
|
chmod -R go= ~has-sudo-pubkey
|
|
|
|
|
|
|
|
RUN sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config
|
|
|
|
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd
|
|
|
|
|
|
|
|
ENV NOTVISIBLE "in users profile"
|
|
|
|
RUN echo "export VISIBLE=now" >> /etc/profile
|
|
|
|
|
|
|
|
EXPOSE 22
|
|
|
|
CMD ["/usr/sbin/sshd", "-D"]
|
2017-12-04 20:31:19 +00:00
|
|
|
|
|
|
|
RUN apt-get install -y strace && apt-get clean && { echo '#!/bin/bash\nexec strace -ff -o /tmp/pywrap$$.trace python2.7 "$@"' > /usr/local/bin/pywrap; chmod +x /usr/local/bin/pywrap; }
|
2017-09-17 12:00:48 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
def sh(s, *args):
|
|
|
|
if args:
|
|
|
|
s %= tuple(map(commands.mkarg, args))
|
|
|
|
return shlex.split(s)
|
|
|
|
|
|
|
|
|
2017-10-30 10:36:40 +00:00
|
|
|
mydir = os.path.abspath(os.path.dirname(__file__))
|
2017-09-17 12:00:48 +00:00
|
|
|
with tempfile.NamedTemporaryFile(dir=mydir) as dockerfile_fp:
|
|
|
|
dockerfile_fp.write(DOCKERFILE)
|
|
|
|
dockerfile_fp.flush()
|
|
|
|
|
|
|
|
subprocess.check_call(sh('docker build %s -t d2mw/mitogen-test -f %s',
|
|
|
|
mydir,
|
|
|
|
dockerfile_fp.name
|
|
|
|
))
|