Repository navigation
Description
Connecting GitHub to a self-hosted instance means filling in fourteen fields on GitHub and setting nine permissions and nine events. Then the admin copies seven values into environment variables, converts the private key and restarts the server. The review app and Linear take the same again. A missed event or a wrong URL shows up only later, as follow-ups that never come: in #369, app.fctl.sh's own app lacks the Status event. GitHub can create an app from a manifest that fctl fills in, and hand fctl its credentials. fctl should keep them in D1, sealed with the master key. Instance admins should then create, check and replace GitHub, the review app, Linear and (once fctl has one) a Slack app from Admin → Integrations, with no restart.
How it works now
- Configuration comes from the environment.
Config::from_env(crates/fctl-control/src/config.rs) reads every value as a Worker variable or secret, synchronously, on each request (Ctx::new,crates/fctl-control/src/ctx.rs). It also runs in 26 other places, Durable Objects among them. - What each integration needs. GitHub needs
GITHUB_APP_IDandGITHUB_APP_PRIVATE_KEY, and its slug defaults tofctl.GITHUB_CLIENT_IDandGITHUB_CLIENT_SECRETlet admins connect accounts.GITHUB_WEBHOOK_SECRETturns the webhook on, andGITHUB_DEFAULT_OWNERsets where New repository creates repositories. The review app takes three values more, Linear three, Google two and Resend two. - Standalone.
deploy/standalone/lib/config.mjspasses the names inVARS, and both private keys (whichgithubKeyconverts to PKCS#8), to the Worker as bindings when the server starts (server.mjs). So every change takes a restart (docs/self-hosting.md#3-tell-the-control-plane-about-it: "set the seven variables … and start the server again"). - Cloudflare. Values go in the instance file's
[github],[linear],[google]and[email]tables and throughcargo xtask secrets(xtask/src/deploy.rs), thencargo xtask deploy.deploy/instances/example.tomlsends people todocs/github-app.md, which doesn't exist. - The setup by hand. docs/self-hosting.md#1-create-the-app tabulates GitHub's form, nine repository permissions and nine events. Step 3 collects seven values from the app's pages. The review app (#a-review-app-optional) takes fewer. Linear (#connect-linear-optional) offers a manifest to paste into Linear, then three values to copy back.
- Keys. GitHub hands out PKCS#1 keys, which the Worker refuses (
fctl_domain::private_key::KeyError::Pkcs1). The standalone server andcargo xtask secretsconvert them. - What people see. Admin → GitHub (
Githubinweb/src/routes/admin.tsx) says "This instance has no GitHub App. Set one up … (see the self-hosting guide)". A workspace's GitHub tab says much the same (web/src/routes/workspace.tsx), and its Linear tab "Its admins set LINEAR_WEBHOOK_SECRET" (web/src/components/workspace/linear.tsx).fctl admin githubonly lists and removes workspaces' connections (crates/fctl/src/cmd/admin.rs). - What fctl checks already (
crates/fctl-control/src/github.rs).Github::key_problemfinds out whether GitHub takes the key, which the review app's status uses (api/review_app.rs).Github::subscribedreadsGET /app's events, whichcrates/fctl-control/src/triggers.rscaches per isolate so the Schedules tab can say which events fctl doesn't hear. - Sealing.
Keys::sealandopen(crates/fctl-control/src/crypto.rs) seal with AES-256-GCM under a key fromFCTL_MASTER_KEY, with associated data naming the record. They keep Claude credentials, project secrets and webhook secrets in D1 already. - The browser can't post to GitHub. The Content Security Policy allows
form-action 'self' https://accounts.google.comonly (web/public/_headers), and the manifest flow is a form that posts to github.com.
What should happen
- A D1 table of integrations whose secrets are sealed with the master key, which
Configreads (cached per isolate, read again when one changes). Where the deployment sets an integration's variables, the variables win, for that whole integration. - Admin → Integrations takes the place of Admin → GitHub. It creates the GitHub App from a manifest, and the review app from one of its own.
- fctl checks each app: GitHub takes its key, it has the events and permissions fctl uses, and its newest webhook deliveries got answers. It repairs what it can: a new webhook secret, a new key.
- An app made before can be entered by hand: ids, the key file (PKCS#1, as GitHub gives it) and secrets.
- Linear: a link that opens Linear's form with fctl's manifest in it, then a form for the three values Linear shows.
- Slack, once fctl has a Slack app (Start and steer agents from Slack, with agents that read only what they should there #620): Slack's manifest API with a configuration token, or Slack's prefilled form.
- Google sign-in and email take their values by hand on the same page.
- The CLI does all of it, with
--json. The audit log records it. Creating, replacing and forgetting an app ask to confirm it's you, where the instance asks for that (ADR 0039). - The docs start from the page and keep the variables for deployments, and
deploy/instances/example.toml's dead link goes.
Storage. A new migration, numbered after the highest (0071_id_token_keys.sql today):
CREATE TABLE IF NOT EXISTS integrations (
kind TEXT PRIMARY KEY, -- github, github_review, linear, slack, google, email
settings TEXT NOT NULL, -- JSON, nothing secret: app id, slug, client id, owner
secrets TEXT NOT NULL, -- sealed JSON (integration:<kind>): private key, client secret, webhook secret
created_by TEXT REFERENCES users(id) ON DELETE SET NULL,
created_at INTEGER NOT NULL,
updated_at INTEGER NOT NULL
);A loader reads the table once per isolate. It reads it again when a stamp kept with the instance settings moves, which each request's sign-in already reads in the same query (auth.rs). So a change reaches every isolate on its next request. The 18 files that read GitHub's or Linear's configuration go through the loader.
The GitHub manifest, filled in from FCTL_PUBLIC_URL and the guide's tables:
{
"name": "acme-fctl",
"url": "https://fctl.acme.dev",
"hook_attributes": { "url": "https://fctl.acme.dev/api/v1/github/webhook", "active": true },
"redirect_url": "https://fctl.acme.dev/api/v1/admin/integrations/github/created",
"callback_urls": ["https://fctl.acme.dev/api/v1/github/authorized"],
"setup_url": "https://fctl.acme.dev/api/v1/github/installed",
"setup_on_update": true,
"request_oauth_on_install": false,
"public": false,
"default_permissions": { "contents": "write", "pull_requests": "write", "issues": "write", "workflows": "write", "checks": "write", "administration": "write", "actions": "read", "statuses": "read", "metadata": "read" },
"default_events": ["pull_request", "check_run", "check_suite", "status", "issue_comment", "pull_request_review", "pull_request_review_comment", "issues", "release"]
}public follows the admin's choice of who may install the app. Where GitHub can't reach the instance (plain http, a private address), the webhook is off, and the page says what that costs, in the guide's words: merges and checks arrive hours late, and follow-ups don't come.
The round trip (GitHub's guide, the endpoint):
- The browser posts the manifest to
https://github.com/organizations/acme/settings/apps/new?state=…, or to/settings/apps/newfor a personal account. For the browser to allow that, either_headers'form-actiongainshttps://github.com, or the Worker serves that one page with a policy of its own, which can also name a GitHub Enterprise host. - GitHub sends the admin back to
redirect_urlwithcodeandstate. The state is signed with the master key's MAC key, names the admin and lasts an hour, as the code does. - Within the hour fctl trades the code, without authentication (
POST /app-manifests/{code}/conversions), for the app'sid,slug,client_id,client_secret,webhook_secretandpem. - fctl wraps the key in PKCS#8, in fctl-domain, so that a pasted PKCS#1 key works too. It seals and stores everything, and records
integration.github.createdin the instance's audit log.
Checks and repairs. key_problem and subscribed stay as they are, GET /app's permissions are checked against fctl's list, and GET /app/hook/deliveries gives the newest deliveries. GitHub pings the webhook as it creates the app, before fctl has the secret, so the ping gets 501 (docs/self-hosting.md#4-connect-it-to-a-workspace): fctl redelivers it once the app is stored (POST /app/hook/deliveries/{id}/attempts) and shows the answer. A new webhook secret goes to GitHub (PATCH /app/hook/config) and into D1 together (GitHub's docs). The old one still checks deliveries for a few minutes, as webhooks' previous_secret does.
Linear. No API creates a Linear OAuth app. Instead, a manifest fills in Linear's form: https://linear.app/settings/api/applications/new?manifest=<URL-encoded JSON> (Linear's docs). fctl builds that link from the guide's manifest, with this instance's addresses. The admin creates the app in Linear, then pastes its client ID, client secret and webhook signing secret into fctl. Those values are proven only when a workspace connects and Linear's first delivery comes. The page says so, and shows when the webhook last took a delivery.
Slack. fctl has no Slack app yet; its webhooks post to Slack's incoming webhooks (docs/automation.md). Once it has one, Slack does create apps from a manifest. apps.manifest.create takes the manifest and an app configuration token, which someone generates on Slack's Your Apps page and which lasts 12 hours. It returns app_id, credentials (client_id, client_secret, verification_token, signing_secret) and an oauth_authorize_url. It returns no bot token: installing the app gives one (the method, configuration tokens). fctl uses the token once and keeps nothing of it. Without a token, https://api.slack.com/apps?new_app=1&manifest_json=… opens Slack's form with the manifest in it, and the admin pastes the credentials back.
Cloudflare. The same page and table work there: the Worker writes D1, so there's nothing to deploy. Instances set up with the instance file and cargo xtask secrets keep working, since the deployment's values win. To manage an app from the page instead, an admin removes those values. Restoring D1 with Time Travel restores the credentials too.
Design and UX
Setting up GitHub should take an instance admin one page in fctl and one confirmation on GitHub: fctl fills in every field and checks the result, and nobody copies a secret or restarts a server.
Admin → Integrations replaces Admin → GitHub, so Admin keeps eight tabs. It lists GitHub, the review app, Linear, Slack (once there is one), Google sign-in and email. A configured integration is one line ("acme-fctl, owned by acme · its webhook answered 2 minutes ago") that opens to its details. An unconfigured one shows an intro.
GitHub's intro:
- Headline: "Agents that open pull requests on GitHub".
- Lead: "Create a GitHub App for Acme factory. Acme's workspaces then connect the accounts it's installed on, and agents get tokens for their project's repositories only, for an hour at a time. GitHub tells fctl what happens to pull requests through its webhook, at https://fctl.acme.dev/api/v1/github/webhook."
- Points: what it may do ("Read and write code, pull requests, issues, checks and workflows; read CI results"). What it never gets ("No organization or account permissions"). Whose it is ("It belongs to the organization you choose, whose owners can change or delete it on GitHub").
- Preview: the app as GitHub will show it, drawn: its name, "Owned by acme", and a pull request opened by acme-fctl[bot].
- Form:
- Owner: a Select of "An organization" (with its login,
acme) or "My personal account". - Name: placeholder
acme-fctl, with the hint "Agents' commits, pull requests and comments show it: acme-fctl[bot]". - Who can install it: "Only acme" ("Workspaces work in acme's repositories alone") or "Any account" ("Workspaces can connect other accounts too: someone's own, a partner's organization").
- Owner: a Select of "An organization" (with its login,
- Primary action: "Create on GitHub", with a note: "GitHub shows you the app to confirm, then brings you back here. You need to be an owner of acme on GitHub."
- The other way, as a question: "Already have an app? Enter its details."
The flow:
- GitHub shows "Create GitHub App for acme". The admin may change the name, then confirms.
- Back in fctl, a toast says "Created acme-fctl: install it on acme next". Its checks fill in as they finish: "GitHub takes its key", "Subscribed to the 9 events fctl uses", "Webhook: GitHub's ping, sent again, got 200".
- "Install it on acme" (primary) opens GitHub's install page. GitHub brings the admin back to choose a workspace's repositories, as today (
/api/v1/github/installed). - The review app's intro follows, with the two-comment thread the workspace's GitHub tab draws, and "Create on GitHub" again.
States:
- Loading: each check says "Asking GitHub…" until it has an answer, rather than a spinner over the page.
- Back without an app: "Nothing was created: GitHub's form was closed. Start again any time." (info).
- An expired code: "GitHub created acme-fctl, but its code ran out before fctl took the app's keys. Delete it on GitHub (acme's Developer settings) and create it again, or enter its details by hand."
- Another admin's request: "This came back from GitHub without a request of yours: nothing was stored."
- Set by the deployment: details, read-only, with why: "Set by the deployment (GITHUB_APP_ID and 6 more): change it where the server's environment is set, or remove those to manage it here."
- Problems, in amber with the fix: "acme-fctl isn't subscribed to Status: CI that reports commit statuses doesn't reach sessions. Tick it under the app's Permissions & events (opens GitHub)." "GitHub's last 12 deliveries got 401: the webhook secrets differ. Make a new one: fctl sets it on GitHub too."
- Not an admin: workspace admins don't see Admin. Their GitHub tab says "This instance has no GitHub App yet. Its admins create one in Admin → Integrations: ask Ada, its primary owner."
- Long lists: installations as today, and the newest five deliveries, then "Show all on GitHub".
- Forgetting an app, in the danger zone: "Forget acme-fctl? Workspaces lose their GitHub accounts, and running sessions their tokens within the hour. The app stays on GitHub, where acme's owners delete it."
CLI. Secrets come from a prompt or stdin, never a flag:
$ fctl admin integrations
GitHub acme-fctl (app 912345), owned by acme · kept in fctl · webhook answered 2m ago
Review app not set up: fctl admin github create --review
Linear set by the deployment (LINEAR_CLIENT_ID and 2 more)
Slack fctl has no Slack app yet
$ fctl admin github create --org acme --name acme-fctl
Open this link to create acme-fctl on GitHub (for you, for 10 minutes):
https://fctl.acme.dev/admin?tab=integrations&create=github&t=…
Waiting for GitHub… created acme-fctl (app 912345).
Next, install it on acme: https://github.com/apps/acme-fctl/installations/new
$ fctl admin github set --app-id 912345 --slug acme-fctl --client-id Iv23li… --private-key ./acme-fctl.private-key.pem
Client secret (GitHub: General → Client secrets): ••••
Webhook secret: ••••
✓ GitHub takes the key ✓ subscribed to the 9 events fctl uses
Saved: Acme factory's workspaces can connect acme now. No restart needed.
fctl admin github check, rotate-webhook-secret and forget, and fctl admin linear set, take --json too.
- Follow hyperstructure/design's docs:
docs/principles.md;docs/web-app/explaining.mdfor pages that set something up (a headline that names the outcome, a lead built from this place's facts, a preview of the result, one primary action, and who can act);docs/web-app/kit.mdfor controls. - Design every state before building it: the first visit, loading, errors and refusals, waiting, partial setups and long lists.
- Say what happens, plainly, and never leave someone at a disabled control without saying who can act.
- Prototype the main screens with realistic data (
cargo xtask demo's world) and review them before building the rest. - Check both themes, a phone's width, the keyboard, screen readers and reduced motion, and show screenshots in each pull request.
- Give the CLI the same care: readable output,
--json, and errors that say what to do next. - Add or update the pages of hyperstructure/design's docs for each new component, with the reasons behind its choices.
Compatibility
- D1. A new migration file. The secrets are sealed with
FCTL_MASTER_KEY, so a copy of D1 without the key can't read them, as with project secrets. - Protocol. The admin API's types for integrations and their checks go in
crates/fctl-proto, thencargo xtask gen. Methods go incrates/fctl-client, and commands incrates/fctl. - Hosts and agents don't change: they never see the apps' keys (docs/architecture.md#principles).
- Existing instances. Their variables keep working, and win.
- Release. The control plane, the web app, the CLI and the standalone image, whose
VARSstay.web/public/_headerschanges ifform-actionis the way chosen. - Docs.
docs/self-hosting.md(Connect GitHub, A review app, Connect Linear, the Settings table) anddocs/organizations.md.docs/architecture.md#data(D1 keeps the instance's integrations) anddocs/security.md(where the apps' keys are kept).docs/cli.mdanddocs/llms.txt. - Privacy policy. No change while app.fctl.sh keeps its apps in its deployment's secrets. Moving them wouldn't change fctl-site's
legal/privacy.mdeither, since an app's credentials aren't personal data.
Decisions for a person
- Who creates, replaces and forgets integrations: any instance admin, or only the primary instance owner? Are those sensitive actions?
- Do the deployment's values win per integration, as proposed, or value by value?
- Should the Worker serve the page that posts the manifest, with its own policy, which works for GitHub Enterprise too? Or should
_headersallow github.com? - May fctl take a Slack configuration token, which can create apps in the admin's Slack workspace for 12 hours? Or should it only offer Slack's prefilled form?
- Does app.fctl.sh move its own apps into D1?
- Do Google sign-in and email belong on this page, or stay with the deployment?
Refs #369
Session: https://app.fctl.sh/s/ses_01M8450BECFP8DN88R0ZP0N0MS
Activity