diff --git a/images/createDigitalOceanImage.sh b/images/createDigitalOceanImage.sh index 00a675f20..7abbcc09e 100755 --- a/images/createDigitalOceanImage.sh +++ b/images/createDigitalOceanImage.sh @@ -11,6 +11,12 @@ readonly INSTALLER_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)" readonly JSON="${INSTALLER_DIR}/node_modules/.bin/json" readonly ssh_keys="${HOME}/.ssh/id_rsa_yellowtent" +readonly scp202="scp -P 202 -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${ssh_keys}" +readonly scp22="scp -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${ssh_keys}" + +readonly ssh202="ssh -p 202 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${ssh_keys}" +readonly ssh22="ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${ssh_keys}" + installer_revision=$(git rev-parse HEAD) box_size="512mb" image_regions=(sfo1 ams3) @@ -120,7 +126,7 @@ done while true; do echo "Trying to copy init script to droplet" - if scp -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "${SCRIPT_DIR}/initializeBaseUbuntuImage.sh" root@${droplet_ip}:.; then + if $scp22 "${SCRIPT_DIR}/initializeBaseUbuntuImage.sh" root@${droplet_ip}:.; then break fi echo "Timedout, trying again in 30 seconds" @@ -128,24 +134,24 @@ while true; do done echo "Copying INFRA_VERSION" -scp -o ConnectTimeout=10 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "${SCRIPT_DIR}/../../box/setup/INFRA_VERSION" root@${droplet_ip}:. +$scp22 "${SCRIPT_DIR}/../../box/setup/INFRA_VERSION" root@${droplet_ip}:. echo "Copying installer source" cd "${INSTALLER_DIR}" -git archive --format=tar HEAD | ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "root@${droplet_ip}" "cat - > /root/installer.tar" +git archive --format=tar HEAD | $ssh22 "root@${droplet_ip}" "cat - > /root/installer.tar" echo "Executing init script" -if ! ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "root@${droplet_ip}" "/bin/bash /root/initializeBaseUbuntuImage.sh ${installer_revision}"; then +if ! $ssh22 "root@${droplet_ip}" "/bin/bash /root/initializeBaseUbuntuImage.sh ${installer_revision}"; then echo "Init script failed" exit 1 fi echo "Copy over certs" -scp -r -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "${INSTALLER_DIR}/../keys/installer/" "root@${droplet_ip}:/home/yellowtent/installer/src/certs/" -scp -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "${INSTALLER_DIR}/../keys/installer_ca/ca.crt" "root@${droplet_ip}:/home/yellowtent/installer/src/certs/" +$scp202 -r "${INSTALLER_DIR}/../keys/installer/" "root@${droplet_ip}:/home/yellowtent/installer/src/certs/" +$scp202 "${INSTALLER_DIR}/../keys/installer_ca/ca.crt" "root@${droplet_ip}:/home/yellowtent/installer/src/certs/" echo "Shutting down droplet with id : ${droplet_id}" -ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i "${ssh_keys}" "root@${droplet_ip}" "shutdown -f now" || true # shutdown sometimes terminates ssh connection immediately making this command fail +$ssh202 "root@${droplet_ip}" "shutdown -f now" || true # shutdown sometimes terminates ssh connection immediately making this command fail # wait 10 secs for actual shutdown echo "Waiting for 10 seconds for droplet to shutdown" diff --git a/images/initializeBaseUbuntuImage.sh b/images/initializeBaseUbuntuImage.sh index de937e19e..cc3adebb9 100755 --- a/images/initializeBaseUbuntuImage.sh +++ b/images/initializeBaseUbuntuImage.sh @@ -39,8 +39,7 @@ iptables -P OUTPUT ACCEPT # NOTE: keep these in sync with src/apps.js validatePortBindings # allow ssh, http, https, ping, dns iptables -I INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -iptables -A INPUT -p tcp --dport 22 -j ACCEPT -iptables -A INPUT -p tcp -m tcp -m multiport --dports 80,443,886 -j ACCEPT +iptables -A INPUT -p tcp -m tcp -m multiport --dports 80,202,443,886 -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT iptables -A INPUT -p udp --sport 53 -j ACCEPT @@ -63,7 +62,7 @@ iptables -A INPUT -j LOGGING # last rule in INPUT chain iptables -A LOGGING -m limit --limit 2/min -j LOG --log-prefix "IPTables Packet Dropped: " --log-level 7 iptables -A LOGGING -j DROP -echo "==== Install btrfs tools" +echo "==== Install btrfs tools ===" apt-get -y install btrfs-tools echo "==== Install docker ====" @@ -232,3 +231,16 @@ sync sed -e 's/^#NTP=/NTP=0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org 2.ubuntu.pool.ntp.org 3.ubuntu.pool.ntp.org/' -i /etc/systemd/timesyncd.conf timedatectl set-ntp 1 timedatectl set-timezone UTC + +echo "==== Install ssh ===" +apt-get -y install openssh-server +# https://stackoverflow.com/questions/4348166/using-with-sed on why ? must be escaped +sed -e 's/^#\?Port .*/Port 202/g' \ + -e 's/^#\?PermitRootLogin .*/PermitRootLogin without-password/g' \ + -e 's/^#\?PermitEmptyPasswords .*/PermitEmptyPasswords no/g' \ + -e 's/^#\?PasswordAuthentication .*/PasswordAuthentication no/g' \ + -i /etc/ssh/sshd_config + + # required so we can connect to this machine since port 22 is blocked by iptables by now +systemctl reload sshd +