Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Streamline startup #612

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ RUN echo 'tmpfs /run/dojofs tmpfs defaults,mode=755,shared 0 0' > /etc/fstab &&
echo '/data/homes /run/homefs none defaults,bind,nosuid 0 0' >> /etc/fstab

RUN ln -s /opt/pwn.college/etc/systemd/system/pwn.college.service /etc/systemd/system/pwn.college.service && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.init.service /etc/systemd/system/pwn.college.init.service && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.backup.service /etc/systemd/system/pwn.college.backup.service && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.backup.timer /etc/systemd/system/pwn.college.backup.timer && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.cachewarmer.service /etc/systemd/system/pwn.college.cachewarmer.service && \
Expand All @@ -44,6 +45,7 @@ RUN ln -s /opt/pwn.college/etc/systemd/system/pwn.college.service /etc/systemd/s
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.imagepuller.timer /etc/systemd/system/pwn.college.imagepuller.timer && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.cloud.backup.service /etc/systemd/system/pwn.college.cloud.backup.service && \
ln -s /opt/pwn.college/etc/systemd/system/pwn.college.cloud.backup.timer /etc/systemd/system/pwn.college.cloud.backup.timer && \
ln -s /etc/systemd/system/pwn.college.init.service /etc/systemd/system/multi-user.target.wants/pwn.college.init.service && \
ln -s /etc/systemd/system/pwn.college.service /etc/systemd/system/multi-user.target.wants/pwn.college.service && \
ln -s /etc/systemd/system/pwn.college.backup.timer /etc/systemd/system/timers.target.wants/pwn.college.backup.timer && \
ln -s /etc/systemd/system/pwn.college.cachewarmer.timer /etc/systemd/system/timers.target.wants/pwn.college.cachewarmer.timer && \
Expand All @@ -58,4 +60,4 @@ RUN find /opt/pwn.college/dojo -type f -exec ln -s {} /usr/bin/ \;
EXPOSE 22
EXPOSE 80
EXPOSE 443
CMD ["dojo", "init"]
CMD ["/usr/bin/systemd"]
18 changes: 5 additions & 13 deletions dojo/dojo
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ fi
DOCKER_ARGS=${DOCKER_ARGS:--i}
[ -t 0 ] && DOCKER_ARGS="-t $DOCKER_ARGS"

if [ "$ACTION" != "init" ] && [ -f /data/config.env ]; then
. /data/config.env
fi
[ -f /data/config.env ] && . /data/config.env

case "$ACTION" in
# HELP: up: bring the dojo up
"up")
echo "[+] Starting the dojo. If this is the first start, the challenge"
echo "[+} container will be built, which will take a very long time."
dojo sync
dojo compose up -d --build --remove-orphans "$@"
;;
Expand Down Expand Up @@ -124,11 +124,12 @@ case "$ACTION" in

# HELP: logs: display dojo logs
"logs")
journalctl -u pwn.college -f --no-tail
journalctl -u pwn.college.* -f --no-tail
zardus marked this conversation as resolved.
Show resolved Hide resolved
;;

# HELP: wait: wait for the dojo to finish starting
"wait")
sleep 10
dojo logs | while IFS= read -r line; do
echo "$line"
case "$line" in
Expand All @@ -142,15 +143,6 @@ case "$ACTION" in
done
;;

# HELP: init: main entry point for the docker image
"init")
echo "[+] Initializing dojo."
dojo-init
echo "[+] Starting systemd. If this is the first start, the challenge container"
echo " will be built, which will take a very long time."
exec /usr/bin/systemd
;;

# HELP: help: displays this help
"help")
echo "Usage: $0 COMMAND [ ARG ]"
Expand Down
9 changes: 9 additions & 0 deletions dojo/dojo-init
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/bin/sh

echo "[+] Checking /data mount properties..."
data_mnt_opts="$(findmnt -n -o OPTIONS /data)"
if [ "$?" -ne 0 ]; then
echo '[!] Data mount does not exist. Please start the dojo with a data mount (`-v /data:/data`).'
Expand Down Expand Up @@ -65,12 +66,15 @@ define MAC_USERNAME
define MAC_KEY_FILE
define MAC_GUEST_CONTROL_FILE

echo "[+] Sourcing config.env..."
mv /data/.config.env /data/config.env
. /data/config.env

echo "[+] Creating workspace directories..."
mkdir -p /data/workspace/nix
mkdir -p /data/workspacefs/bin

echo "[+] Configuring homes..."
mkdir -p /data/homes
if [ "$(findmnt -n -o FSTYPE /data/homes)" != "btrfs" ] && [ "$(findmnt -n -o FSTYPE /data)" != "btrfs" ]; then
if [ ! -f /data/homes/btrfs.img ]; then
Expand All @@ -82,6 +86,7 @@ if [ "$(findmnt -n -o FSTYPE /data/homes)" != "btrfs" ] && [ "$(findmnt -n -o FS
fi
btrfs quota enable /data/homes

echo "[+] Configuring ssh..."
if [ ! -d /data/ssh_host_keys ]; then
mkdir -p /data/ssh_host_keys
rm /etc/ssh/ssh_host_*_key*
Expand All @@ -95,16 +100,20 @@ for file in $(ls /data/ssh_host_keys/*); do
cp -a $file /etc/ssh
done

echo "[+] Configuring backup keys..."
if [ ! -z ${BACKUP_AES_KEY_FILE+x} ] && [ ! -f ${BACKUP_AES_KEY_FILE} ]
then
openssl rand 214 > "${BACKUP_AES_KEY_FILE}"
fi

echo "[+] Setting kernel parameters..."
sysctl -w kernel.pty.max=1048576
echo core > /proc/sys/kernel/core_pattern

echo "[+] Configuring dojo nodes..."
dojo-node refresh

echo "[+] Configuring firewalling..."
iptables -N DOCKER-USER
iptables -I DOCKER-USER -i workspace_net -j DROP
for host in $(cat /opt/pwn.college/user_firewall.allowed); do
Expand Down
15 changes: 15 additions & 0 deletions etc/systemd/system/pwn.college.init.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=pwn.college initialization service
Before=docker.service
Before=containerd.service
Before=sysinit.target
DefaultDependencies=no

[Service]
Type=oneshot
RemainAfterExit=true
WorkingDirectory=/opt/pwn.college
ExecStart=/usr/bin/dojo-init

[Install]
WantedBy=sysinit.target
1 change: 1 addition & 0 deletions etc/systemd/system/pwn.college.service
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Description=pwn.college docker compose service
Requires=docker.service
After=docker.service
After=pwn.college.init.service

[Service]
Type=oneshot
Expand Down
Loading