Run every verb, preflight and the IAP tunnel from an access token file

Closes #50 (closed)

A hosted caller holds an access token and nothing else. This runs every verb, preflight and the IAP tunnel from CLOUDSDK_AUTH_ACCESS_TOKEN_FILE alone.

Behaviour

  • Setting CLOUDSDK_AUTH_ACCESS_TOKEN_FILE selects token mode. GCP_PROJECT and GCP_ZONE are required; a missing one, or an unreadable token file, stops the run before any gcloud call.
  • No gcloud config, gcloud auth login or application default credentials in token mode.
  • Preflight validates the token with a Cloud Resource Manager testIamPermissions call and checks the IAP permission the same way. The Authorization header goes to curl on stdin, never argv. It only checks the IAP API; it never enables one.
  • The caller owns refresh. gcloud rereads the file on every call; a token lasts one hour, so a long verb needs one valid for its whole run.
  • Non-token behaviour is unchanged.

Auth path

flowchart LR
  caller["Hosted caller"] -->|"writes token, owns refresh"| tf[("token file, mode 0600")]
  caller -->|"exports GCP_PROJECT, GCP_ZONE, CLOUDSDK_AUTH_ACCESS_TOKEN_FILE"| sim["simulation.sh"]
  sim -->|"missing project, zone or file"| stop["stop with a message naming it"]
  sim --> pre["preflight"]
  pre -->|"Bearer header on stdin"| crm["Cloud Resource Manager testIamPermissions"]
  tf -->|"read by the header builder"| pre
  sim --> verbs["gcloud verbs: create, ssh, scp, snapshot, delete"]
  tf -->|"reread on every call"| verbs
  verbs --> iap["IAP tunnel to port 4252"]
  gcfg["gcloud config, auth login, ADC"] -.->|"never read in token mode"| sim

Threat matrix

Threat Control Test that goes red when the control is reverted
Run proceeds against the wrong project or zone from stale gcloud config Token mode requires GCP_PROJECT and GCP_ZONE and stops with a message naming the missing one token-selftest.sh missing project, zone and both
Token file missing or empty gives a silent fall back to ADC or an account prov_require_location stops before any gcloud call token-selftest.sh missing token file
A verb reads gcloud config or auth list in token mode Defaults come from the environment; the gcloud stub aborts on a config or auth call token-selftest.sh no-config-read cases; provider-gate.sh
New code adds an unguarded config or auth read The provider gate allows those reads only in named functions that contain prov_token_mode provider-selftest.sh injected leak and renamed guard
Token on a command line, visible in ps or shell history Header built in one printf and tr pipe and sent to curl with -H @-; the token never sits in a shell variable, so xtrace never prints it preflight-selftest.sh token never on argv or in output
An operator's CLOUDSDK_AUTH_ACCESS_TOKEN, impersonation, credential override or gcloud config swaps the identity Token mode exports the token file, drops those settings and gives gcloud an empty per-run CLOUDSDK_CONFIG (mode 0700); the IAP tunnel child and the multiplexer inherit it token-selftest.sh shadowing settings ignored (a stub gcloud records its env), IAP ProxyCommand child, multiplexer
SIM_ENV_FILE sets the token file without export, so gcloud children fall back to the config account The token file is exported once, early, for every script token-selftest.sh unexported assignment still reaches children
xtrace prints the token One-pipe header builder, no variable token-selftest.sh and preflight-selftest.sh xtrace cases
Token expires mid-up, and the startup poll spins for five minutes An auth error in the poll stops at once with the refresh step; the --iap-only path runs the login check engine-selftest.sh poll case, preflight-selftest.sh --iap-only expired token
The gate misses a digit-named or function name definition, or a config list, info or auth describe read The gate matches both definition forms, reads the extra forms, and names its one exempt helper (setup-federation.sh, a setup helper outside the lab verbs) provider-selftest.sh digit-named, keyword form, three reads, exempt entry
Expired or invalid token passes preflight A reply with an error object stops at the login step with the refresh hint preflight-selftest.sh invalid token
Preflight changes the project by enabling an API The IAP API check prints the command to run and calls nothing that writes preflight-selftest.sh no services enable
Missing IAP permission surfaces as a connection timeout later testIamPermissions for the IAP tunnel permission, with a member hint that names no gcloud account preflight-selftest.sh IAP permission absent

Evidence

Selftests: token-selftest.sh (37 checks), preflight-selftest.sh (46 cases), provider-selftest.sh (81 checks), engine-selftest.sh. Mutation proof: the new cases run against the previous head's sources go red (12 in token, 3 in preflight, 8 in provider, 3 in engine) and are green on this head.

Live, project andunn-65744190, instance sim-tkf2, caproni --no-gitlab on c2d-standard-4 (landed in us-central1-c after two stockouts), token file only, with CLOUDSDK_AUTH_IMPERSONATE_SERVICE_ACCOUNT=nobody@invalid.iam.gserviceaccount.com exported as a control:

  • Preflight: 18 of 18 passed.
  • up: passed, including the startup wait.
  • ssh through IAP printed the hostname; status --json --live returned the record.
  • down: deleted the VM; no instance, disk, address, firewall rule or snapshot named sim-tkf2 remains.
  • Without the fix, the same setting stops preflight at step 10 with gcloud's "using service account impersonation ... as nobody@invalid.iam.gserviceaccount.com".
Edited by Andrew Dunn

Merge request reports

Loading
Loading