Dockerfile 4.6 KB

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