|
| 1 | +from ubuntu:latest |
| 2 | + |
| 3 | +# Install dependencies. |
| 4 | +RUN apt update -y |
| 5 | +RUN DEBIAN_FRONTEND="noninteractive" apt install -y tzdata |
| 6 | +RUN apt install -y \ |
| 7 | + git-all \ |
| 8 | + vim \ |
| 9 | + nano \ |
| 10 | + whois \ |
| 11 | + openssh-server \ |
| 12 | + curl \ |
| 13 | + apt-utils \ |
| 14 | + iputils-ping \ |
| 15 | + zsh \ |
| 16 | + tmux |
| 17 | + |
| 18 | +# Create the required users. The game master is the `git` account, and the player is the user's account |
| 19 | +RUN useradd --comment "GameMaster account" --create-home --password $(mkpasswd -m sha-512 94+wings+STRONG+mountain+35) gamemaster |
| 20 | +RUN useradd --comment "Player account" --create-home --password $(mkpasswd -m sha-512 player) --shell $(which zsh) player |
| 21 | + |
| 22 | +# Set up the player's SSH keys and copy the public key to /tmp |
| 23 | +COPY build/player_entrypoint.sh /home/player |
| 24 | +RUN chown player:player /home/player/player_entrypoint.sh |
| 25 | +RUN chmod 770 /home/player/player_entrypoint.sh |
| 26 | +RUN su -c "/home/player/player_entrypoint.sh" - player |
| 27 | +COPY build/player_zshrc.sh /home/player/.zshrc |
| 28 | +RUN chown player:player /home/player/.zshrc |
| 29 | +RUN chmod 770 /home/player/.zshrc |
| 30 | + |
| 31 | +RUN mkdir /var/run/sshd |
| 32 | +RUN echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config |
| 33 | +RUN echo 'ClientAliveCountMax 10' >> /etc/ssh/sshd_config |
| 34 | +COPY build/login_banner.txt /etc/motd |
| 35 | + |
| 36 | +# Set up the git server so that the player can run git clone gamemaster@localhost:/home/gamemaster/ctf-repo |
| 37 | +RUN git clone --bare https://github.com/ShayNehmad/make-git-better-levels.git /home/gamemaster/ctf-repo |
| 38 | +# This file adds the player's ssh public key from before |
| 39 | +COPY build/gamemaster_entrypoint.sh /home/gamemaster |
| 40 | +RUN chown gamemaster:gamemaster /home/gamemaster/gamemaster_entrypoint.sh |
| 41 | +RUN chmod 770 /home/gamemaster/gamemaster_entrypoint.sh |
| 42 | +RUN su -c "/home/gamemaster/gamemaster_entrypoint.sh" - gamemaster |
| 43 | +# Set up the hooks for the actual gameplay in the repo |
| 44 | +COPY levels/checkers /home/gamemaster/ctf-repo/hooks/checkers |
| 45 | +COPY scripts/generate-pre-receive-hook/output/pre-receive /home/gamemaster/ctf-repo/hooks |
| 46 | +# Make sure that gamemaster owns all of their files |
| 47 | +RUN chown -R gamemaster:gamemaster /home/gamemaster |
| 48 | + |
| 49 | +# Now that we're done with gamemaster's setup we can change their shell to git shell and block their home directory |
| 50 | +RUN chsh gamemaster -s $(which git-shell) |
| 51 | +RUN chmod 700 -R /home/gamemaster |
| 52 | + |
| 53 | +# Cleanup |
| 54 | +RUN rm -rf /tmp/* |
| 55 | +RUN rm -rf /home/player/player_entrypoint.sh |
| 56 | + |
| 57 | +EXPOSE 22 |
| 58 | +CMD ["/usr/sbin/sshd", "-D"] |
| 59 | + |
0 commit comments