52 lines
1.5 KiB
YAML
Raw Normal View History

2025-02-13 13:55:41 +01:00
name: Emergency ssh
description: "Verify that an emergency ssh connection can be established."
inputs:
workspace:
description: "The constellation workspace directory."
required: true
kubeconfig:
description: "The kubeconfig file for the cluster."
required: true
runs:
using: "composite"
steps:
- name: Test emergency ssh
shell: bash
env:
KUBECONFIG: ${{ inputs.kubeconfig }}
run: |
# Activate emergency ssh access to the cluster
2025-02-18 15:30:51 +01:00
pushd ./constellation-terraform
2025-02-13 13:55:41 +01:00
echo "emergency_ssh = true" >> terraform.tfvars
terraform apply -auto-approve
lb="$(terraform output -raw loadbalancer_address)"
2025-02-18 15:30:51 +01:00
popd
2025-02-13 13:55:41 +01:00
# write ssh config
cat > ssh_config <<EOF
Host $lb
ProxyJump none
2025-02-13 16:44:01 +01:00
Host *
2025-02-20 15:55:26 +01:00
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
2025-02-13 16:44:01 +01:00
IdentityFile ./access-key
PreferredAuthentications publickey
CertificateFile=constellation_cert.pub
User root
ProxyJump $lb
2025-02-13 13:55:41 +01:00
EOF
2025-02-18 16:23:35 +01:00
cat ssh_config
2025-02-13 13:55:41 +01:00
# generate and try keypair
ssh-keygen -t ecdsa -q -N "" -f ./access-key
constellation ssh --debug --key ./access-key.pub
internalIPs="$(kubectl get nodes -o=jsonpath='{.items[*].status.addresses}' | jq -r '.[] | select(.type == "InternalIP") | .address')"
2025-02-20 14:14:08 +01:00
for ip in $internalIPs; do
2025-02-18 16:23:35 +01:00
echo "Trying connection to $ip over $lb"
ssh -F ssh_config -o BatchMode=yes $ip true
2025-02-13 13:55:41 +01:00
done