feat(cloud): a person's own GitHub connection; cloud workspaces commit, push and open PRs as them

Merged
SA
2mo ago
+12065-12

What. Settings → Personal → Connections gets a GitHub row (Connect / @login · Disconnect). Connecting authorizes the GitHub App for the person (user-to-server token).

  • Storage. github_user_connections, one row per user, tokens sealed with the existing secret box. Migration 0116_github_user_connections, drizzle-kit output, stacked on the branch's 0115.
  • Refresh. Under a per-user advisory lock, because a refresh rotates the refresh token and two concurrent wakes would otherwise lock one out. A connection GitHub rejects is removed and the workspace falls back to the App.
  • Disconnect. Deletes the row and revokes the grant.

On the box.

  • The firewall rule for github.com/api.github.com carries the creator's own token when connected (pushes and PRs are theirs, limited to what both they and the App reach), else the App installation token as today.
  • Commits carry GIT_AUTHOR_*/GIT_COMMITTER_*: the connected account's no-reply address (attributed on GitHub, passes "block pushes that expose my email"), else the Superset account's name and email. Before this, the box had no git identity and commits failed.
  • Create refuses an environment containing a repository the connected person cannot see, rather than failing at clone.

Token expiry on unattended boxes. The rule was only refreshed on wake, and the desktop only re-wakes while the workspace is open, so an agent left running or an automation's workspace lost GitHub access after the hour-long installation token expired. host-service now calls POST /api/cloud-workspaces/:id/credentials every 30 minutes with its host secret (the API derives and compares it), and the API re-applies the policy without waking anything.

Config. GH_APP_CLIENT_ID / GH_APP_CLIENT_SECRET, optional: without them the row reads "Not available on this server" and workspaces use the App's token. Added to the env examples and both deploy workflows. Repo secrets not set yet (needs the App's client secret), and the App's callback URLs need <API>/api/github/user/callback.

Verified live (dev stack, dev GitHub App, real Vercel box, 2026-09-14):

  • Connect round trip from Settings → Connections: GitHub authorize, callback 200, row stored for saddlepaddle with an expiring access token and a refresh token.
  • A box created by the connected user, committing and pushing through host-service's own git path: GitHub attributes the commit to saddlepaddle as author and committer under 14907857+saddlepaddle@users.noreply.github.com; gh api user on the box answers saddlepaddle; nothing on the box holds a token.
  • A draft PR opened from the box (superset-sh/acme-demo#3) shows author saddlepaddle; closed and the branch deleted, main untouched.
  • POST /api/cloud-workspaces/:id/credentials: the box's host secret → applied; a wrong secret and a valid secret for another workspace → 401.
  • Found and fixed while testing: the row never refreshed after connecting, because a focus refetch does not fire when returning to an Electron window; it now polls after Connect.

Also: typecheck (db, trpc, host-service, shared, api, desktop), lint, i18n (7 strings, 16 locales), sandbox lib tests, 71 settings tests; migration 0116 applied by drizzle-kit on a dev branch recreated from production.

Not verified live: the refresh timer firing on a box (it runs every 30 minutes, and a dev box cannot reach a localhost API; the route it calls is verified above); token refresh after expiry (8 hours); Disconnect's grant revocation.

Before merge: set GH_APP_CLIENT_ID and GH_APP_CLIENT_SECRET as repository secrets for preview and production, and add https://api.superset.sh/api/github/user/callback to the production App's redirect URIs.

https://claude.ai/code/session_01FK6rLzBEUiHHXZWNmpQ2BP


Summary by cubic

Adds Settings → Connections support for a person’s GitHub account, so their cloud workspaces commit, push, and open pull requests as them instead of using the organization’s GitHub App. Workspaces still fall back to the App token when no personal connection exists.

Details

  • Stores one encrypted connection per user, refreshes tokens under a per-user lock, and revokes the grant on disconnect.
  • Uses the connected account’s GitHub no-reply address for commit author and committer identity.
  • Rejects workspace creation when the connected account cannot access an environment repository, instead of waiting for clone to fail.
  • Re-applies credential rules every 30 minutes for unattended running workspaces; the host authenticates with its workspace secret and never receives the token.
  • Polls every two seconds for up to five minutes after Connect so Electron shows the connection without requiring a reload.
  • The release probe’s credentials now carry a git author too.

Rollout

  • Set GH_APP_CLIENT_ID and GH_APP_CLIENT_SECRET in preview and production, and add <API>/api/github/user/callback to the GitHub App callback URLs.
  • Apply migration 0116_github_user_connections; without the new variables, personal connections remain unavailable and workspaces use the App token.
  • The connect flow, push/PR attribution, credential endpoint authorization, and tests are verified in development; the 30-minute timer, token refresh after expiry, and disconnect revocation are not yet verified live.