Files
attack-defense-platform/services/blogpost/Dockerfile
T

73 lines
2.3 KiB
Docker
Raw Normal View History

2025-10-11 12:42:26 +07:00
# Dockerfile
# python:3.11-slim-bookworm (Debian 12, supported) — bullseye is EOL and its
# apt repos 404, so we build on the current stable slim image instead.
FROM python:3.11-slim-bookworm
2025-10-10 22:34:43 +07:00
2025-10-11 12:42:26 +07:00
# Build-time args
ARG PASSWORD
2025-10-10 22:34:43 +07:00
WORKDIR /app
2025-10-11 12:42:26 +07:00
# Prevent interactive prompts during apt installs
ENV DEBIAN_FRONTEND=noninteractive
ENV DB_PATH=/data/app.db
# Allow apt on hosts whose clock is past GPG key expiry (2026+)
COPY apt-insecure.conf /etc/apt/apt.conf.d/99gemastik-insecure
2025-10-11 12:42:26 +07:00
# Install packages we need (exiftool, sqlite3, sshd, build tools, editor)
RUN apt-get -o Acquire::AllowInsecureRepositories=true update && \
apt-get -y --allow-unauthenticated install --no-install-recommends \
2025-10-11 12:42:26 +07:00
libimage-exiftool-perl \
sqlite3 \
openssh-server \
build-essential \
bash \
nano \
vim \
curl \
wget \
netcat-openbsd \
git \
python3-pip \
2025-10-11 12:42:26 +07:00
&& rm -rf /var/lib/apt/lists/*
# Create an unprivileged user for running the app / SSH access
RUN useradd -m -d /home/ctfuser -s /bin/bash ctfuser \
&& if [ -n "${PASSWORD}" ]; then echo "ctfuser:${PASSWORD}" | chpasswd; fi
# Copy application and requirements
COPY chall/requirements.txt /app/
2025-10-10 22:34:43 +07:00
RUN pip install --no-cache-dir -r /app/requirements.txt
2025-10-11 12:42:26 +07:00
COPY chall/ .
2025-10-10 22:34:43 +07:00
2025-10-11 12:42:26 +07:00
# Ensure entrypoint exists and is executable (keeps your existing entrypoint.sh)
RUN chmod +x /app/entrypoint.sh || true
2025-10-10 22:34:43 +07:00
2025-10-11 12:42:26 +07:00
# Create needed directories and set permissions
RUN mkdir -p /data /app/uploads /run/sshd /notes \
&& chown -R ctfuser:ctfuser /app /app/uploads /notes \
&& chmod 755 /app \
&& chmod 777 /app/uploads
# (intentionally NOT chowning /data here; we’ll fix /data at runtime in case it’s a bind mount)
# Create the flag file with safe perms (will be overwritten at runtime if FLAG is set)
RUN touch /flag.txt && chown root:root /flag.txt && chmod 644 /flag.txt
# Configure basic sshd options
RUN echo "PasswordAuthentication yes" >> /etc/ssh/sshd_config && \
echo "PermitRootLogin no" >> /etc/ssh/sshd_config && \
echo "AllowUsers ctfuser" >> /etc/ssh/sshd_config && \
echo "PermitEmptyPasswords no" >> /etc/ssh/sshd_config
# Generate host keys and make sure /run/sshd exists
RUN ssh-keygen -A || true
RUN mkdir -p /run/sshd && chmod 755 /run/sshd
# Expose app and ssh ports
2025-10-10 22:34:43 +07:00
EXPOSE 8000
2025-10-11 12:42:26 +07:00
EXPOSE 22
2025-10-10 22:34:43 +07:00
2025-10-11 12:42:26 +07:00
USER root
2025-10-10 22:34:43 +07:00
CMD ["/app/entrypoint.sh"]