Skip to content

Commit 34066ff

Browse files
committed
Add opencode pairing runbook and opencode-link CLI helper
opencode web's username/password sign-in has a known upstream auth loop (anomalyco/opencode#19920). Document the one-time pairing-link flow (open from the web terminal or mint locally with opencode-link), which signs the browser in with a 30-day session cookie. The link is minted where the user is already authenticated - never in GitHub Actions.
1 parent 84b6fa2 commit 34066ff

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

‎docs/workstation.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,20 @@ scripts/workstation opencode main
164164

165165
Browse to either URL and accept the self-signed certificate warning. Both apps run plain on localhost; Caddy terminates TLS and authenticates the browser, so the workstation stores only a bcrypt hash of the password. The plaintext password is kept in the Google Cloud Secret Manager secret `workstation-NAME-web-terminal-password`. The workflow identity can create this secret and append versions, but cannot read its values. Use Secret Manager in the Google Cloud console to see the active password.
166166

167+
opencode keeps its own sign-in, whose username/password prompt has a known upstream auth loop ([#19920](https://github.com/anomalyco/opencode/issues/19920)). Sign the browser in with a **one-time pairing link** instead — from your laptop:
168+
169+
```sh
170+
scripts/workstation opencode-link main --project PROJECT --zone ZONE
171+
```
172+
173+
or from inside the workstation (web terminal at `:8443`), as `developer`:
174+
175+
```sh
176+
~/.opencode/bin/opencode pair --url https://EXTERNAL_IP:8444
177+
```
178+
179+
Open the printed link within 5 minutes (single use); Caddy asks for `workstation` + the shared password once more, then opencode signs the browser in with a 30-day session cookie. Rotating the browser-apps password signs opencode sessions out.
180+
167181
`start` rotates the password after a stopped VM resumes; `web-terminal` and `opencode` rotate it on demand. `create` without those flags keeps both ports closed. Browser access is public on ports 8443 and 8444 when enabled; protect the Google Cloud project and Secret Manager permissions and avoid leaving expensive API credentials in unattended sessions. Consider narrowing the firewall source range when practical.
168182

169183
## Provisioning and ownership

‎scripts/workstation‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ usage() { cat <<'HELP'
1818
Usage: workstation COMMAND [NAME] [--project PROJECT] [--zone ZONE]
1919
workstation create [NAME] [--machine-type TYPE] [--web-terminal|--opencode] [--environment NAME[,NAME...]]
2020
workstation configure [NAME] --environment NAME[,NAME...]
21-
Commands: create, configure, idle-shutdown, opencode, start, stop, list, shell, config-ssh, web-terminal, destroy
21+
Commands: create, configure, idle-shutdown, opencode, opencode-link, start, stop, list, shell, config-ssh, web-terminal, destroy
2222
web-terminal enables the code-server browser editor; opencode enables the opencode web UI.
2323
Both are served by Caddy on https://IP:8443 and :8444 behind one browser-apps password.
24+
opencode-link prints a one-time pairing link that signs the browser into opencode web.
2425
configure applies one or more environments (comma-separated) from environments/NAME.sh, in order.
2526
idle-shutdown installs the auto-shutdown watchdog (also run automatically after setup).
2627
Default name: main. Default machine type: e2-standard-2.
@@ -39,7 +40,7 @@ while (($#)); do
3940
--web-terminal) WEB=true; shift;;
4041
--opencode) OPENCODE=true; shift;;
4142
--yes) YES=true; shift;;
42-
create|configure|idle-shutdown|opencode|start|stop|list|shell|config-ssh|web-terminal|destroy) [[ -z "$ACTION" ]] || die 'Duplicate command'; ACTION="$1"; shift;;
43+
create|configure|idle-shutdown|opencode|opencode-link|start|stop|list|shell|config-ssh|web-terminal|destroy) [[ -z "$ACTION" ]] || die 'Duplicate command'; ACTION="$1"; shift;;
4344
-*) die "Unknown option $1";;
4445
*) NAME="$1"; shift;;
4546
esac
@@ -299,7 +300,18 @@ case "$ACTION" in
299300
shell) [[ "$(status)" == RUNNING ]] || die 'Workstation not running'; gcloud compute ssh "$INSTANCE" "${GCLOUD_ARGS[@]}";;
300301
config-ssh) gcloud compute config-ssh --project "$PROJECT";;
301302
web-terminal) ensure_browser_app_tag web-terminal; rotate;;
302-
opencode) ensure_browser_app_tag opencode; rotate;;
303+
opencode) ensure_browser_app_tag opencode; rotate;;
304+
opencode-link)
305+
[[ "$(status)" == RUNNING ]] || die 'Workstation not running'
306+
ensure_setup
307+
ip="$(field 'networkInterfaces[0].accessConfigs[0].natIP')"
308+
[[ -n "$ip" ]] || die 'No external IP'
309+
link="$(gcloud compute ssh "$INSTANCE" "${GCLOUD_ARGS[@]}" --quiet \
310+
--command "timeout 20 sudo -u developer /home/developer/.opencode/bin/opencode pair --url https://$ip:8444" 2>/dev/null |
311+
grep -oE "https://$ip:8444/auth/connect/[A-Za-z0-9_-]+" | head -1)"
312+
[[ -n "$link" ]] || die 'Could not generate an opencode pairing link (is opencode running?)'
313+
echo "opencode link: $link (one-time, expires in 5 minutes)"
314+
;;
303315
list)
304316
gcloud compute instances list --project "$PROJECT" --format='csv[no-heading](name,status,machineType.basename(),zone.basename(),networkInterfaces[0].accessConfigs[0].natIP,tags.items,labels.managed-workstation)' |
305317
while IFS=, read -r instance state machine zone ip tags managed; do

0 commit comments

Comments
 (0)