|
1 | | -FROM ubuntu |
2 | | - |
3 | | -RUN sed -i -e 's/^# deb-src/deb-src/' /etc/apt/sources.list |
4 | | -RUN apt-get update |
5 | | -RUN apt-get upgrade --assume-yes |
6 | | -RUN DEBIAN_FRONTEND=noninteractive apt-get install --assume-yes --no-install-recommends tzdata |
7 | | -RUN apt-get build-dep --assume-yes openssh-server |
8 | | -RUN apt-get install --assume-yes build-essential fakeroot devscripts |
9 | | -RUN mkdir src && cd src |
10 | | -RUN apt-get source openssh-server |
11 | | -RUN ls -alh |
12 | | -RUN cd openssh-8.9p1/ && sed -e 's/^\([ \t]*\)\(struct passwd \*pw = authctxt->pw;\)/\1logit("Login attempt by username '\''%s'\'', password '\''%s'\'', from ip '\''%.200s'\''", authctxt->user, password, ssh_remote_ipaddr(ssh));\nreturn 0;\1\2/' -i auth-passwd.c && \ |
| 1 | +# Stage 1: Build stage |
| 2 | +FROM ubuntu:20.04 as builder |
| 3 | + |
| 4 | +# Set environment variable for non-interactive installations |
| 5 | +ENV DEBIAN_FRONTEND=noninteractive |
| 6 | + |
| 7 | +# Enable 'deb-src' entries and install dependencies |
| 8 | +RUN sed -i -e 's/^# deb-src/deb-src/' /etc/apt/sources.list && \ |
| 9 | + apt-get update && \ |
| 10 | + apt-get install --no-install-recommends -y \ |
| 11 | + build-essential \ |
| 12 | + fakeroot \ |
| 13 | + devscripts \ |
| 14 | + tzdata \ |
| 15 | + openssh-client \ |
| 16 | + putty-tools \ |
| 17 | + python3-twisted && \ |
| 18 | + apt-get build-dep --no-install-recommends -y openssh-server && \ |
| 19 | + mkdir -p /src && cd /src && \ |
| 20 | + apt-get source openssh-server && \ |
| 21 | + cd openssh-* && \ |
| 22 | + sed -i 's/^\([ \t]*\)\(struct passwd \*pw = authctxt->pw;\)/\1logit("Login attempt by username '\''%s'\'', password '\''%s'\'', from ip '\''%.200s'\''", authctxt->user, password, ssh_remote_ipaddr(ssh));\nreturn 0;\1\2/' auth-passwd.c && \ |
13 | 23 | debchange --nmu 'add verbose logging of usernames and passwords' && \ |
14 | 24 | EDITOR=true dpkg-source --commit . 'chatty-ssh.patch' && \ |
15 | 25 | debuild -us -uc -i -I && \ |
16 | | - apt-get install --assume-yes putty-tools python3-twisted && \ |
17 | | - debi && \ |
18 | | - mkdir /run/sshd && \ |
19 | | - cd && rm -rf /src && \ |
20 | | - apt-get clean && \ |
21 | | - apt-get autoremove --assume-yes |
| 26 | + apt-get clean && apt-get autoremove -y |
| 27 | + |
| 28 | +# Stage 2: Runtime stage |
| 29 | +FROM ubuntu:20.04 |
| 30 | + |
| 31 | +# Set environment variable for non-interactive installations |
| 32 | +ENV DEBIAN_FRONTEND=noninteractive |
| 33 | + |
| 34 | +# Install runtime dependencies only |
| 35 | +RUN apt-get update && \ |
| 36 | + apt-get install --no-install-recommends -y \ |
| 37 | + python3-pip \ |
| 38 | + openssh-server && \ |
| 39 | + apt-get clean && apt-get autoremove -y && \ |
| 40 | + rm -rf /var/lib/apt/lists/* |
| 41 | + |
| 42 | +# Copy patched sshd binary and configuration from builder stage |
| 43 | +COPY --from=builder /src/openssh-*/debian/tmp/usr/sbin/sshd /usr/sbin/sshd |
| 44 | + |
| 45 | +# Create a non-root user |
| 46 | +RUN groupadd -r appuser && useradd -r -g appuser -m appuser |
| 47 | + |
| 48 | +# Adjust permissions for SSH and log files |
| 49 | +RUN mkdir -p /etc/ssh && chown -R appuser:appuser /etc/ssh && \ |
| 50 | + touch /var/log/ssh.log && chown appuser:appuser /var/log/ssh.log |
| 51 | + |
| 52 | +# Set working directory |
| 53 | +WORKDIR /home/appuser/code |
| 54 | +RUN chown -R appuser:appuser /home/appuser |
| 55 | + |
| 56 | +# Switch to non-root user |
| 57 | +USER appuser |
22 | 58 |
|
23 | | -RUN apt-get install --assume-yes python3-pip |
24 | | -WORKDIR /code |
25 | | -ADD requirements.txt /code/ |
26 | | -RUN pip install -r requirements.txt |
27 | | -RUN touch /var/log/ssh.log |
| 59 | +# Copy runtime requirements and install them |
| 60 | +COPY requirements.txt /home/appuser/code/ |
| 61 | +RUN pip install --no-cache-dir -r requirements.txt --user |
28 | 62 |
|
29 | | -COPY monitor.py /code/ |
| 63 | +# Copy application code |
| 64 | +COPY monitor.py /home/appuser/code/ |
30 | 65 |
|
| 66 | +# Expose SSH port |
31 | 67 | EXPOSE 22 |
32 | 68 |
|
33 | | -CMD python3 monitor.py |
| 69 | +# Command to run your application |
| 70 | +CMD ["python3", "monitor.py"] |
0 commit comments