Skip to content

Commit 77a1c4d

Browse files
authored
Patch ec2-connect script (#279)
## Description The current script fails with an openssl issue ``` ubuntu@bastion:~$ ./ec2-connect.sh i-0b473ed23cdbe9ebd Connecting to instance ubuntu@i-0b473ed23cdbe9ebd OpenSSL version mismatch. Built against 30000020, you have 30500060 ``` We're not totally sure what the issue is, but ankur had AI patch up the script and this seems to work. See [slack thread](https://braintrustdata.slack.com/archives/C08G0934WG1/p1781995810259459?thread_ts=1781741949.780009&cid=C08G0934WG1) for more context. <!-- Help the reviewer understand what you changed and what the expected behavior is now --> <!-- Include exact details of what customers need to do, or what they should expect, if anything --> ## Testing <!-- Describe how and what you tested. Include screenshots or videos as needed --> Tried in prod.
1 parent a043e04 commit 77a1c4d

1 file changed

Lines changed: 31 additions & 5 deletions

File tree

modules/remote-support/bastion-user-data.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,39 @@ EOF
5151

5252
cat <<'EOF' > /home/ubuntu/ec2-connect.sh
5353
#!/bin/bash
54+
set -euo pipefail
5455
56+
instance_id="$1"
5557
os_user="ubuntu"
56-
echo "Connecting to instance $os_user@$1"
57-
aws ec2-instance-connect ssh \
58-
--instance-id "$1" \
59-
--os-user "$os_user" \
60-
--connection-type direct
58+
59+
tmpdir="$(mktemp -d)"
60+
trap 'rm -rf "$tmpdir"' EXIT
61+
62+
key="$tmpdir/eic_key"
63+
ssh-keygen -q -t ed25519 -N "" -f "$key"
64+
65+
az="$(aws ec2 describe-instances \
66+
--instance-ids "$instance_id" \
67+
--query 'Reservations[0].Instances[0].Placement.AvailabilityZone' \
68+
--output text)"
69+
70+
aws ec2-instance-connect send-ssh-public-key \
71+
--instance-id "$instance_id" \
72+
--instance-os-user "$os_user" \
73+
--availability-zone "$az" \
74+
--ssh-public-key "file://$key.pub" >/dev/null
75+
76+
77+
private_ip="$(aws ec2 describe-instances \
78+
--instance-ids "$instance_id" \
79+
--query 'Reservations[0].Instances[0].PrivateIpAddress' \
80+
--output text)"
81+
82+
echo "Connecting to instance $os_user@$instance_id ($private_ip)"
83+
/usr/bin/ssh \
84+
-i "$key" \
85+
-o StrictHostKeyChecking=no \
86+
"$os_user@$private_ip"
6187
EOF
6288

6389
chmod +x /home/ubuntu/*.sh

0 commit comments

Comments
 (0)