Reach every lab through IAP and stop opening SSH to the internet

Closes #43 (closed)

Every ssh and scp the engine runs now goes through Google IAP TCP forwarding, and up no longer creates a rule that opens SSH to the internet. Not for merge until the adversarial review of the diff is done: this changes a trust boundary.

flowchart LR
  caller["Caller<br/>just lab / simulation.sh"] -->|"gcloud compute ssh<br/>--tunnel-through-iap"| iap["IAP TCP forwarding<br/>needs iap.tunnelInstances.accessViaIAP"]
  iap -->|"tcp:4252 from 35.235.240.0/20"| fw{"allow-iap-ssh-4252<br/>priority 100<br/>target tag sim-lab"}
  fw --> vm["Lab VM sshd :4252"]
  net["Internet 0.0.0.0/0"] -. "no SSH rule from here" .-> fw

What changes

  • 15 call sites reach a VM: 4 in simulation.sh, 3 in openshift-local.sh, 5 in geo.sh, 2 in praefect.sh, 1 in the multiplexer. All use --tunnel-through-iap, or a start-iap-tunnel ProxyCommand for raw ssh, with the instance name as the host. Hotpatch, lab identity, docs-preview and the contrib recipes route through vm_ssh.
  • up creates one standing rule, allow-iap-ssh-4252 (35.235.240.0/20, tcp:4252, priority 100, tag sim-lab), and refuses a same-named rule with other values. Every lab carries sim-lab.
  • Preflight gains two steps (17 total): the IAP API is enabled, and the caller holds iap.tunnelInstances.accessViaIAP. The token never reaches a command line or output.
  • The engine creates no rule from 0.0.0.0/0 for SSH, and deletes or edits no existing project rule. VM-to-VM traffic on internal addresses is unchanged.

Older checkouts and the standing rules

The project rules allow-ssh-4252 (tcp:4252 from 0.0.0.0/0) and default-allow-ssh stay until the owner deletes them. While allow-ssh-4252 stands, it also admits IAP's range 35.235.240.0/20 to every VM, tagged or not, so an old lab built without sim-lab stays reachable through IAP, and from the internet, until that rule is deleted. The new rule adds nothing for such a lab; deleting the old rule is what closes it.

A caller on an older checkout also recreates allow-ssh-4252 on up, and builds labs without sim-lab. A new checkout reaches those labs only through the old rule, or after gcloud compute instances add-tags <vm> --tags=sim-lab.

Threat matrix

Cell Control Test
1. No engine path opens SSH to 0.0.0.0/0 ensure_iap_ssh_rule replaces the allow-ssh-4252 block iap-selftest.sh cell 1: stubbed gcloud records every create, none pairs 0.0.0.0/0 with an SSH port; source scan of gce/*.sh
2. IAP rule source is exactly 35.235.240.0/20, target tag only sim labs rule definition, plus refusal of a same-named rule whose source, tag, ports, extra allowed entries, sourceTags, direction, action or disabled flag differs iap-selftest.sh cell 2: twelve wrong rules and an unreadable one refused; engine-selftest.sh checks the VM carries sim-lab
3. Every ssh and scp uses IAP --tunnel-through-iap or iap_proxy_option at every site iap-selftest.sh cell 3: each call site stubbed, plus a static gate over every shell and python file in the skill, with one test per evasion form (if ssh, timeout ssh, rsync -e, trailing -p 4252, compute ssh without the flag, a borrowed flag array)
4. Full up and down work with the internet denied SSH IAP rule outranks the deny Live, below
5. SSH to the external IP times out no open rule Live, below
6. Preflight fails clearly when the IAP API or permission is missing check_iap_api, check_iap_access preflight-selftest.sh: API off, API unreadable, curl missing, permission absent, permission error, token never printed
7. A target's tunnel uses the target's own zone instance_zone reads ${STATE_ROOT}/<name>.json for geo and praefect iap-selftest.sh zone block: pointer zone differs from the target's; nine checks fail on the old head

Live proof

Project andunn-65744190, us-central1. A test-only rule sim-iap1-deny-ssh (DENY tcp:22 and tcp:4252 from 0.0.0.0/0, priority 200, tag sim-iap1 only) stood for the omnibus rig sim-iap1 from before install to teardown, and was deleted after down.

  • Cell 4: omnibus up --no-aigw, status --json --live (components read through IAP), hotpatch apply (puma and sidekiq both loaded the patched code), hotpatch verify and down all completed with the deny rule standing.
  • Cell 5: before the deny rule, nc to the external IP on 4252 connected (the old open rule); with it, 4252 and 22 both timed out, while gcloud compute ssh --tunnel-through-iap to the same VM kept working. Port 22 had no listener before the rule either.
  • gcloud compute firewall-rules describe accepts the list() format the rule check uses, and gcloud compute ssh --dry-run --tunnel-through-iap (the multiplexer command) emits a ProxyCommand.
  • Caproni and geo proof is in a comment on this MR.

Second round, after review:

  • Geo and praefect opened the tunnel in the current-pointer lab's zone. Each target now resolves its own zone from ${STATE_ROOT}/<name>.json, falling back to GCP_ZONE (instance_zone). Live: a geo pair in us-central1-f, while GCP_ZONE is us-central1-a, did geo up and geo verify with a deny rule on both VMs.
  • up checks IAP access (API enabled, permission held) with preflight's message before it creates a VM, not after a run of 255 retries. It runs once per up, geo and praefect included. SIM_SKIP_IAP_CHECK=1 skips it for conditional or per-instance grants.
  • compute scp names the sshd port with --port=4252, so the wait for a new SSH key to propagate probes 4252, not 22. With a new key and block-project-ssh-keys=TRUE on the VM, the old form hung until a 60 s timeout (failed to connect to backend); the new one completed in 7 s with no manual ssh first.
  • The static gate covers every shell and python file and rejects the wrapped, chained and array-borrowing forms listed in the matrix.

Geo live proof: sim-iapg-p and sim-iapg-s, us-central1-f, a test deny rule (DENY tcp:22 and tcp:4252, priority 200) on both from create to teardown. geo up (install, secrets copy, replication) and geo verify completed through IAP; nc to both external IPs on 22 and 4252 timed out. The pair and the rule are deleted.

Docs: operations troubleshooting row, ADR 0006, and a Security changelog entry. The skill stays under the word ceiling (40485 of 40489).

Edited by Andrew Dunn

Merge request reports

Loading
Loading