|
| 1 | +# Copyright (c) 2025 Red Hat, Inc. |
| 2 | +# This program and the accompanying materials are made |
| 3 | +# available under the terms of the Eclipse Public License 2.0 |
| 4 | +# which is available at https://www.eclipse.org/legal/epl-2.0/ |
| 5 | +# |
| 6 | +# SPDX-License-Identifier: EPL-2.0 |
| 7 | +# |
| 8 | + |
| 9 | +FROM quay.io/devfile/universal-developer-image:latest |
| 10 | + |
| 11 | +USER 0 |
| 12 | + |
| 13 | +RUN dnf -y install libsecret openssh-server && \ |
| 14 | + dnf -y clean all --enablerepo='*' |
| 15 | + |
| 16 | +# Step 1. Generate SSH Host keys |
| 17 | +RUN mkdir /opt/ssh |
| 18 | +RUN chmod 755 /opt/ssh |
| 19 | +RUN chown -R root:root /opt/ssh/ |
| 20 | + |
| 21 | +RUN ssh-keygen -q -N "" -t dsa -f /opt/ssh/ssh_host_dsa_key && \ |
| 22 | + ssh-keygen -q -N "" -t rsa -b 4096 -f /opt/ssh/ssh_host_rsa_key && \ |
| 23 | + ssh-keygen -q -N "" -t ecdsa -f /opt/ssh/ssh_host_ecdsa_key && \ |
| 24 | + ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_host_ed25519_key |
| 25 | + |
| 26 | +# Step 2. Configure SSH as non-root user |
| 27 | +RUN cp /etc/ssh/sshd_config /opt/ssh/ |
| 28 | + |
| 29 | +# Step 3. Fix permissions |
| 30 | +RUN chmod 644 /opt/ssh/ssh_host_* /opt/ssh/sshd_config |
| 31 | + |
| 32 | +# Use non-privileged port, set user authorized keys, disable strict checks |
| 33 | +RUN sed -i \ |
| 34 | +-e 's|#Port 22|Port 2022|' \ |
| 35 | +-e 's|AuthorizedKeysFile .ssh/authorized_keys|AuthorizedKeysFile /home/user/ssh/authorized_keys|' \ |
| 36 | +-e 's|#StrictModes yes|StrictModes=no|' \ |
| 37 | +-e 's|#PidFile /var/run/sshd.pid|PidFile /tmp/sshd.pid|' \ |
| 38 | +-e 's|#LogLevel INFO|LogLevel DEBUG3|' \ |
| 39 | + /opt/ssh/sshd_config |
| 40 | + |
| 41 | +# Provide new path containing host keys |
| 42 | +RUN sed -i \ |
| 43 | +-e 's|#HostKey /etc/ssh/ssh_host_rsa_key|HostKey /opt/ssh/ssh_host_rsa_key|' \ |
| 44 | +-e 's|#HostKey /etc/ssh/ssh_host_ecdsa_key|HostKey /opt/ssh/ssh_host_ecdsa_key|' \ |
| 45 | +-e 's|#HostKey /etc/ssh/ssh_host_ed25519_key|HostKey /opt/ssh/ssh_host_ed25519_key|' \ |
| 46 | + /opt/ssh/sshd_config |
| 47 | + |
| 48 | +# Prepare SSH Keys |
| 49 | +RUN ssh-keygen -q -N "" -t ed25519 -f /opt/ssh/ssh_client_ed25519_key |
| 50 | +RUN chmod 644 /opt/ssh/ssh_client_* |
| 51 | + |
| 52 | +# Add script to start and stop the service |
| 53 | +COPY --chown=0:0 /build/scripts/sshd.start / |
| 54 | + |
| 55 | +RUN mkdir /opt/www |
| 56 | +COPY /build/scripts/server.js /opt/www/ |
| 57 | + |
| 58 | +ENV USER_NAME=dev |
| 59 | + |
| 60 | +EXPOSE 2022 3400 |
| 61 | + |
| 62 | +USER 10001 |
0 commit comments