Dockerfile 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ARG BASE
  2. FROM ${BASE}
  3. ARG BASE
  4. RUN echo "Install openssh, needed for scp. Also install python3"
  5. RUN if echo "$BASE" | grep "ubuntu:"; then apt-get update -y && apt-get install -y openssh-client python3 python3-pip; fi
  6. RUN if echo "$BASE" | grep "alpine:"; then apk add openssh python3 py3-pip; fi
  7. RUN echo "Install paramiko"
  8. RUN pip3 install paramiko==3.5.1 || pip3 install --break-system-packages paramiko==3.5.1
  9. # Note - on Ubuntu, we do not create the user's home directory, pam_mkhomedir will do that
  10. # for us, and we want to test that PAM gets triggered by Tailscale SSH.
  11. RUN if echo "$BASE" | grep "ubuntu:"; then groupadd -g 10000 groupone && groupadd -g 10001 grouptwo && useradd -g 10000 -G 10001 -u 10002 testuser; fi
  12. # On Alpine, we can't configure pam_mkhomdir, so go ahead and create home directory.
  13. RUN if echo "$BASE" | grep "alpine:"; then addgroup -g 10000 groupone && addgroup -g 10001 grouptwo && adduser -u 10002 -D testuser && addgroup testuser groupone && addgroup testuser grouptwo; fi
  14. RUN if echo "$BASE" | grep "ubuntu:"; then \
  15. echo "Set up pam_mkhomedir." && \
  16. sed -i -e 's/Default: no/Default: yes/g' /usr/share/pam-configs/mkhomedir && \
  17. cat /usr/share/pam-configs/mkhomedir && \
  18. pam-auth-update --enable mkhomedir \
  19. ; fi
  20. COPY tailscaled .
  21. COPY tailssh.test .
  22. RUN chmod 755 tailscaled
  23. RUN echo "First run tests normally."
  24. RUN eval `ssh-agent -s` && TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestSSHAgentForwarding
  25. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  26. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSFTP
  27. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  28. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSCP
  29. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  30. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSSH
  31. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  32. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationParamiko
  33. RUN echo "Then run tests as non-root user testuser and make sure tests still pass."
  34. RUN touch /tmp/tailscalessh.log
  35. RUN chown testuser:groupone /tmp/tailscalessh.log
  36. RUN TAILSCALED_PATH=`pwd`tailscaled eval `su -m testuser -c ssh-agent -s` && su -m testuser -c "./tailssh.test -test.v -test.run TestSSHAgentForwarding"
  37. RUN TAILSCALED_PATH=`pwd`tailscaled su -m testuser -c "./tailssh.test -test.v -test.run TestIntegration TestDoDropPrivileges"
  38. RUN echo "Also, deny everyone access to the user's home directory and make sure non file-related tests still pass."
  39. RUN mkdir -p /home/testuser && chown testuser:groupone /home/testuser && chmod 0000 /home/testuser
  40. RUN TAILSCALED_PATH=`pwd`tailscaled SKIP_FILE_OPS=1 su -m testuser -c "./tailssh.test -test.v -test.run TestIntegrationSSH"
  41. RUN chmod 0755 /home/testuser
  42. RUN chown root:root /tmp/tailscalessh.log
  43. RUN if echo "$BASE" | grep "ubuntu:"; then \
  44. echo "Then run tests in a system that's pretending to be SELinux in enforcing mode" && \
  45. # Remove execute permissions for /usr/bin/login so that it fails.
  46. mv /usr/bin/login /tmp/login_orig && \
  47. # Use nonsense for /usr/bin/login so that it fails.
  48. # It's not the same failure mode as in SELinux, but failure is good enough for test.
  49. echo "adsfasdfasdf" > /usr/bin/login && \
  50. chmod 755 /usr/bin/login && \
  51. # Simulate getenforce command
  52. printf "#!/bin/bash\necho 'Enforcing'" > /usr/bin/getenforce && \
  53. chmod 755 /usr/bin/getenforce && \
  54. eval `ssh-agent -s` && TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestSSHAgentForwarding && \
  55. TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegration && \
  56. mv /tmp/login_orig /usr/bin/login && \
  57. rm /usr/bin/getenforce \
  58. ; fi
  59. RUN echo "Then remove the login command and make sure tests still pass."
  60. RUN rm `which login`
  61. RUN eval `ssh-agent -s` && TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestSSHAgentForwarding
  62. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  63. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSFTP
  64. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  65. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSCP
  66. RUN if echo "$BASE" | grep "ubuntu:"; then rm -Rf /home/testuser; fi
  67. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegrationSSH
  68. RUN echo "Then remove the su command and make sure tests still pass."
  69. RUN chown root:root /tmp/tailscalessh.log
  70. RUN rm `which su`
  71. RUN eval `ssh-agent -s` && TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestSSHAgentForwarding
  72. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestIntegration
  73. RUN echo "Test doDropPrivileges"
  74. RUN TAILSCALED_PATH=`pwd`tailscaled ./tailssh.test -test.v -test.run TestDoDropPrivileges