Repository navigation
feat: run the control plane without Cloudflare, in one container - #123
Merged
kalaspuff merged 9 commits intoOct 20, 2026
Merged
Conversation
The sign-in cookies are __Host- cookies, which browsers take only with Secure, from a secure origin. An instance at http://192.168.1.20:8787 set them without Secure, so browsers dropped them and nobody could sign in from the web app. Where cookies can't be Secure (fctl_domain::cookies::secure: plain http outside localhost and loopback addresses), they are now named without the prefix: fctl, fctl-oauth and fctl-2fa. Instances on https and localhost keep the names they had.
deploy/standalone/server.mjs runs the Worker and the web app, as built for Cloudflare, on workerd through Miniflare, with the bindings wrangler.toml gives wrangler dev and its state (D1, every Durable Object) in FCTL_DATA_DIR. It does what Cloudflare does around the Worker: - applies the D1 migrations as it starts (wrangler d1 migrations apply --local, so d1_migrations records them); - sets CF-Connecting-IP from the connection, or from X-Forwarded-For behind FCTL_TRUST_PROXY proxies, and drops what clients must not set: CF-*, MF-* (which steer Miniflare) and /cdn-cgi/ (Miniflare's pages); - runs the hourly cron trigger, which Miniflare doesn't. It reads the Worker's variables and secrets from the environment (or <NAME>_FILE), makes a master key in the data directory and a setup link when they aren't given, holds a lock on the data directory so that a second server can't run the same Durable Objects, stops cleanly on SIGTERM, and exits when workerd stops answering. It is an npm workspace with its own Biome config and node --test tests.
`cargo xtask serve` builds the Worker and the web app for production and runs the standalone control plane from the checkout, as its container does, with its state in .fctl-serve/. `cargo xtask dev --server <url>` runs the host (and with --smoke, the session) against a control plane that already runs there, bootstrapping the dev owner with the dev setup token, instead of starting wrangler dev; CI uses it on the image. `cargo xtask check` runs the standalone server's Biome check and tests.
…bernetes examples deploy/standalone/Dockerfile builds ghcr.io/hyperstructure/fctl-control from the repository: the Worker and the web app on the build machine's platform, then a Node.js image with wrangler, Miniflare and workerd for the target's, running server.mjs under tini as the node user, with its state in /data. compose.yaml runs it with Docker Compose; kubernetes.yaml runs it as a StatefulSet of one (two servers on the same state would run the same sessions), read-only, with probes, a Service and an Ingress.
…release CI's "Standalone image" job builds the image, starts it on a fresh volume and runs `cargo xtask dev --smoke --server` against it, then checks that it stops cleanly. The Release workflow publishes it for amd64 and arm64 as ghcr.io/hyperstructure/fctl-control:<version>, with :<major>.<minor> and :latest when the release is the newest they cover.
docs/self-hosting.md now has two ways to run the control plane, on your own machine or cluster (Docker, Kubernetes, a clone) and on Cloudflare, followed by what is the same for both. ADR 0026 records why the standalone control plane is the same Worker on workerd rather than a native port; architecture, security and development say what it does and how to work on it.
kalaspuff
approved these changes
Oct 20, 2026
kalaspuff
deleted the
fctl/64-make-it-possible-to-self-host-fctl-contr
branch
October 20, 2026 11:14
kalaspuff
pushed a commit
that referenced
this pull request
Oct 20, 2026
Follows #125. The self-hosting guide's example of a new standalone server's first log (added in #123) says it applies 13 database migrations. #125, merged right after, added `0014_workspace_skip_invites.sql`, so a server started from `main` applies 14. This updates that line; nothing else in the guide counts migrations. ## Verification `FCTL_SETUP_TOKEN=dev-setup-token cargo xtask serve` with a new data directory, on a tree that is this branch's (`main` with #123 and #125, plus this line), logs `Applied 14 database migrations`. On the same tree, `cargo xtask dev --smoke --server http://localhost:8787` passed, `fctl workspaces set --skip-invites on|off` worked against that server, and `cargo xtask check` passed. Session: https://app.fctl.sh/s/ses_01M5CCM54M0DDN4RFRH5J5C0KW Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Running your own fctl took a Cloudflare account with a domain on it, Wrangler signed in and an API token with five permissions. That's right for app.fctl.sh, but a lot to ask of someone who wants to try fctl on a spare machine, a homelab or a Kubernetes cluster they already run. Now the control plane also runs as one container, with no account anywhere:
docker run -d --name fctl --restart unless-stopped -p 8787:8787 -v fctl-data:/data \ -e FCTL_PUBLIC_URL=http://192.168.1.20:8787 ghcr.io/hyperstructure/fctl-control docker logs fctl # the link that creates the first accountHow
It's the same Worker and web app that run on Cloudflare, run by workerd (Cloudflare's open-source Workers runtime) through Miniflare, the same runtime
wrangler devandcargo xtask devuse. No code in the Worker knows where it runs. ADR 0026 explains why this beats a native port: a second implementation of D1, Durable Objects, alarms, hibernating WebSockets and WebCrypto behind 20,000 lines of control plane would drift from production.deploy/standalone/server.mjsruns it with the bindings ofcrates/fctl-control/wrangler.tomland its state (D1 and every Durable Object, as SQLite files) inFCTL_DATA_DIR. It does what Cloudflare does around the Worker:wrangler d1 migrations apply --local, sod1_migrationsrecords them as on Cloudflare).CF-Connecting-IPfrom the connection, or fromX-Forwarded-ForbehindFCTL_TRUST_PROXYproxies. Without it, Miniflare keeps aCF-Connecting-IPthe client sends, so anyone could dodge the sign-in rate limit and write any address into the audit log. The proxy also dropsMF-*headers (which steer Miniflare), answers/cdn-cgi/(Miniflare's own pages) with a 404, and turns off Miniflare's stack-trace error pages.FCTL_MASTER_KEYisn't set (and refuses a different key later), and prints a setup link while the instance has no account.Also in this PR:
deploy/standalone/Dockerfile→ghcr.io/hyperstructure/fctl-control. The Worker and web app build once on the build platform, and the runtime stage is Node 22 slim with wrangler, Miniflare and workerd, running asnodeunder tini. It runs fine with a read-only root.compose.yamlandkubernetes.yaml(a one-replica StatefulSet with probes, a read-only root, a Service and an Ingress) are examples.__Host-cookies withoutSecurethere, which browsers drop, so nobody could sign in athttp://192.168.1.20:8787. Where cookies can't beSecure, they are now namedfctl,fctl-oauthandfctl-2fa(fctl_domain::cookies). https and localhost instances keep their names. The server warns at startup about what plain http gives up.cargo xtask serveruns the standalone server from a clone, without Docker.cargo xtask dev --server <url>runs the host and the smoke test against a control plane that's already running.cargo xtask dev --smoke --serveragainst it, and checks that it stops cleanly. Release gets a "Standalone image" job that publishes it for amd64 and arm64 (:<version>, plus:<major>.<minor>and:latestwhen it's the newest release they cover).docs/self-hosting.mdnow covers both ways (the shared GitHub, Google, email and hosts sections apply to both), plus architecture, security, development, README, AGENTS.md, the roadmap and the release skill.Verified
cargo xtask checkpasses, including new tests forfctl_domain::cookies, the server's 23node --testtests (proxy headers and client addresses, a real WebSocket through the proxy, config, the lock, the schedule) and its Biome check. actionlint (with shellcheck) passes on both workflows, and kubeconform-strict(Kubernetes 1.33) passes onkubernetes.yaml.cargo xtask dev --smoke(the wrangler path) still passes after thedev.rschanges.cargo xtask servefrom the checkout, thencargo xtask dev --smoke --server http://localhost:8787: a host connects and the session commits, waits for its background task, takes its result and stops.--read-only --tmpfs /tmp, it made its master key, applied the 13 migrations and passed the same smoke test. SIGTERM through tini stops it cleanly and releases the lock. Restarted on the same volume, it kept the owner, the session and its event log, with nothing re-applied. The healthcheck command passes. It uses about 430 MB at rest (node 141 MB, workerd 285 MB), and the image is 488 MB. My local build needed three sandbox-only tweaks (apt as root, nochown, noUSER) because Podman here maps a single UID. CI's "Standalone image" job builds the real Dockerfile with Docker (amd64), and on this PR it passed: asnode, the image made its key, applied the migrations, ran the smoke test's session and exited 0 ondocker stop.http://192.168.64.39:8788. First, Chromium drops a__Host-cookie set over http at that address and keeps a plain one. Then the image: creating the owner through/setupsigns in (cookiefctl,HttpOnly, notSecure), and the session survives a reload (/api/v1/auth/me200, the floor loads).scheduledwith ascheduledTime) returnsokagainst the real Worker. A data directory the server can't write to now gets a one-line message naming the user that needs access, instead of a stack trace.POST /setupsent withCF-Connecting-IP: 6.6.6.6andX-Forwarded-For: 7.7.7.7went into the audit log as 127.0.0.1./cdn-cgi/handler/scheduledand/cdn-cgi/local/platform-proxyanswer 404. A second server on the same data waits 45 s, then refuses. With a small Durable Object, an alarm that came due while the server was stopped fired as soon as it started again.For a person
ghcr.io/hyperstructure/fctl-control. If GitHub makes it private, make it public under the org's Packages → fctl-control → Package settings, as was done for the sandbox image..github/rulesets/decides that. I didn't add it, since a broken image shouldn't block deploying app.fctl.sh unless you want it to.docker run ghcr.io/hyperstructure/fctl-controlfails, but building from a clone works.Session: https://app.fctl.sh/s/ses_01M5CBK2S0RJZ0GWZ7HAD137H4