2
0

Dockerfile 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. FROM alpine:3.22
  2. COPY --chown=root:root server/ssh /etc/ssh/
  3. COPY --chown=root:root server/script /opt/sshnet
  4. COPY user/sshnet /home/sshnet/.ssh
  5. RUN apk update && apk upgrade --no-cache && \
  6. apk add --no-cache syslog-ng && \
  7. # install and configure sshd
  8. apk add --no-cache openssh && \
  9. # install openssh-server-pam to allow for keyboard-interactive authentication
  10. apk add --no-cache openssh-server-pam && \
  11. # must not use * for dos2unix parameter otherwise it tries to process folders too and fails
  12. dos2unix /etc/ssh/ssh*key && \
  13. chmod 400 /etc/ssh/ssh*key && \
  14. sed -i 's/#PasswordAuthentication yes/PasswordAuthentication yes/' /etc/ssh/sshd_config && \
  15. sed -i 's/#LogLevel\s*INFO/LogLevel DEBUG3/' /etc/ssh/sshd_config && \
  16. # Set the default RSA key
  17. echo 'HostKey /etc/ssh/ssh_host_rsa_key' >> /etc/ssh/sshd_config && \
  18. echo 'TrustedUserCAKeys /etc/ssh/user-ca.pub' >> /etc/ssh/sshd_config && \
  19. chmod 646 /etc/ssh/sshd_config && \
  20. # install and configure sudo
  21. apk add --no-cache sudo && \
  22. addgroup sudo && \
  23. # allow root to run any command
  24. echo 'root ALL=(ALL) ALL' > /etc/sudoers && \
  25. # allow everyone in the 'sudo' group to run any command without a password
  26. echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
  27. # add user to run most of the integration tests
  28. adduser -D sshnet && \
  29. passwd -u sshnet && \
  30. echo 'sshnet:ssh4ever' | chpasswd && \
  31. # must not use * for dos2unix parameter otherwise it tries to process folders too and fails
  32. dos2unix /home/sshnet/.ssh/*_key* && \
  33. chown -R sshnet:sshnet /home/sshnet && \
  34. chmod -R 700 /home/sshnet/.ssh && \
  35. chmod -R 644 /home/sshnet/.ssh/authorized_keys && \
  36. # add user to administer container (update configs, restart sshd)
  37. adduser -D sshnetadm && \
  38. passwd -u sshnetadm && \
  39. echo 'sshnetadm:ssh4ever' | chpasswd && \
  40. addgroup sshnetadm sudo && \
  41. dos2unix /opt/sshnet/* && \
  42. # install shadow package; we use chage command in this package to expire/unexpire password of the sshnet user
  43. apk add --no-cache shadow && \
  44. # allow us to use telnet command; we use this in the remote port forwarding tests
  45. apk --no-cache add busybox-extras && \
  46. # install full-fledged ps command
  47. apk add --no-cache procps
  48. EXPOSE 22 22
  49. ENTRYPOINT ["/opt/sshnet/start.sh"]