@@ -23,6 +23,41 @@ steps:
2323 cat /workspace/.ssh/google_compute_engine.pub > /workspace/gcb_ssh_key.pub
2424 waitFor : ["-"]
2525
26+ - name : " gcr.io/google.com/cloudsdktool/cloud-sdk"
27+ id : " cleanup-old-keys"
28+ entrypoint : " bash"
29+ args :
30+ - " -c"
31+ - |
32+ #!/bin/bash
33+ set -e
34+
35+ echo "Fetching OS Login SSH keys..."
36+ echo "Removing all keys."
37+ echo "---------------------------------------------------------------------"
38+
39+ FINGERPRINTS_TO_DELETE=$(gcloud compute os-login ssh-keys list \
40+ --format="value(fingerprint)")
41+
42+ echo "Keys to delete: $FINGERPRINTS_TO_DELETE"
43+
44+ if [ -z "$FINGERPRINTS_TO_DELETE" ]; then
45+ echo "No keys found to delete. Nothing to do."
46+ exit 0
47+ fi
48+
49+ while IFS= read -r FINGERPRINT; do
50+ if [ -n "$FINGERPRINT" ]; then
51+ echo "Deleting key with fingerprint: ${FINGERPRINT}"
52+ gcloud compute os-login ssh-keys remove \
53+ --key="${FINGERPRINT}" \
54+ --quiet || true
55+ fi
56+ done <<< "$FINGERPRINTS_TO_DELETE"
57+
58+ echo "---------------------------------------------------------------------"
59+ echo "Cleanup complete."
60+
2661 # Step 1 Create a GCE VM to run the tests.
2762 # The VM is created in the same zone as the buckets to test rapid storage features.
2863 # It's given the 'cloud-platform' scope to allow it to access GCS and other services.
@@ -80,6 +115,7 @@ steps:
80115 waitFor :
81116 - " create-vm"
82117 - " generate-ssh-key"
118+ - " cleanup-old-keys"
83119
84120 - name : " gcr.io/google.com/cloudsdktool/cloud-sdk"
85121 id : " cleanup-ssh-key"
0 commit comments