Notes
open one at a time
1.What it can cause
Every VM with a public address takes key and password guessing from the whole internet, around the clock.
- Every VM with a public address takes key and password guessing from the whole internet, around the clock.
- One leaked or reused key is a shell in production, from anywhere.
- The logs fill with failed attempts, so the one that succeeds is hard to see.
2.Why it is wrong
Identity-based access beats network-based access. The fix is not a narrower IP list, it is removing the public port.
The fix is not a narrower IP list, it is removing the need for a public SSH port at all. IAP tunnels SSH through Google after an identity check, and all its traffic arrives from one fixed range - so the firewall narrows the network path to IAP only, and IAP narrows access to authorised identities only. Two narrow layers replacing one wide-open one. Three independent things must all be true for it to work: the iap.googleapis.com API enabled, roles/iap.tunnelResourceAccessor on the identity, and this firewall rule. roles/editor does not include the tunnel role.
The idea
Identity-based access beats network-based access. The fix is not a narrower IP list, it is removing the public port.
Learn it
- What IAP TCP forwarding is · GCP 6.1
- The three things that must all be true · GCP 6.1
3.How you would find it
gcloud compute firewall-rules list --filter="allowed.ports:22 AND sourceRanges:0.0.0.0/0"
gcloud compute firewall-rules list \ --filter="allowed.ports:22 AND sourceRanges:0.0.0.0/0"4.The change that closes it
allow INGRESS · tcp:22 · source 35.235.240.0/20 · priority 900
- As found
- allow INGRESS · tcp:22 · source 0.0.0.0/0 · target all instances
- Fixed
- allow INGRESS · tcp:22 · source 35.235.240.0/20 · priority 900
# ORDER MATTERS. You are changing how you reach the box while using that# same access to make the change. Add and verify before deleting anything. # 1. Additive. Opens nothing new - that range is only reachable after# IAP has already checked your identity.gcloud compute firewall-rules create allow-ssh-from-iap \ --network=harbour-vpc --direction=INGRESS --action=allow \ --rules=tcp:22 --source-ranges=35.235.240.0/20 --priority=900 # 2. VERIFY on every VM. Not optional - this is what stands between# "SSH is now secure" and "nobody can SSH to production".gcloud compute ssh bastion --zone=asia-southeast1-b \ --tunnel-through-iap --command="echo ok" # when it fails, this checks all three requirements at once:gcloud compute ssh bastion --zone=asia-southeast1-b \ --tunnel-through-iap --troubleshoot # 3. ONLY after every VM verifies.gcloud compute firewall-rules delete default-allow-ssh