Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
b1edf5e
Add vendor run identity verification primitives
Nov 16, 2026
e210cef
Pin vendor identity discovery and signing keys
Nov 16, 2026
ce993d4
Persist verified vendor run identity bindings
Nov 16, 2026
6d9b91c
Add documented vendor identity token sources
Nov 16, 2026
4b55553
Wire vendor VM identity into execution provisioning
Nov 16, 2026
b311a68
Bind Fly identity subject to the provisioned machine
Nov 16, 2026
1367265
Store bearer credentials with Factorize-managed encryption
Nov 16, 2026
713a4cc
Store model account caches with server encryption
Nov 16, 2026
0032832
Update model account API fixture
Nov 16, 2026
8326995
Select tenant provider connections for jobs
Nov 16, 2026
276edfa
Preserve managed caches during unlock rotation
Nov 16, 2026
6ca4076
Fix managed cache rotation fixture revision
Nov 16, 2026
9a2fdc9
Allow server-preserved caches in key rotation
Nov 16, 2026
bdd2c87
GEN-2922 resolve and revoke run provider credentials
Nov 16, 2026
2efd2d8
Route selected run GitHub and Linear requests
Nov 16, 2026
0a49490
Route selected model requests through active run proxy
Nov 16, 2026
5d0a09b
Document GEN-2922 credential proxy cutover
Nov 16, 2026
47ccf62
Pin Fly run identities to organization slugs and verify live vendors
Nov 17, 2026
bcfe788
Authenticate backend API requests with provisioned vendor run identities
Nov 17, 2026
01d63cd
Forward selected run credentials inside the backend and persist disco…
Nov 17, 2026
940b85d
Add vendor identity guest helper and selected run integration discovery
Nov 17, 2026
f1aaa50
Use token-free run snapshots and Worker-compatible Fly guest execution
Nov 17, 2026
78b6da4
Launch run identity helpers and retire legacy HTTP admission paths
Nov 17, 2026
066b6d5
Retire standalone proxy and unlock architecture with guarded managed …
Nov 17, 2026
b2d487e
Align cutover documentation and browser validation with managed crede…
Nov 17, 2026
dea1b3d
Update lifecycle and contract tests for vendor-authenticated guest ac…
Nov 17, 2026
cc5ae0e
Wait for Fly guest boot and keep base image startup separate from job…
Nov 17, 2026
b98efe2
Record completed GEN-2922 acceptance, live vendor checks and final va…
Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/decisions/gen-2826-browser-proxy-https-pairing.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
> Superseded by GEN-2922. The standalone proxy and browser pairing described below are retired; see the credential cutover runbook.

# GEN-2826: Browser to credential proxy HTTPS and identity pairing

## Decision
Expand Down
155 changes: 25 additions & 130 deletions docs/docker-execution-development.md
Original file line number Diff line number Diff line change
@@ -1,130 +1,25 @@
# Local Docker execution and credential-proxy E2E

Docker is a test-only execution infrastructure adapter. Application jobs select
`executionConfigId: "docker"` only when the local API has an explicit
`TEST_DOCKER_EXECUTION` configuration. Deployed Workers do not configure it,
do not list Docker, and reject that selection. Docker supports code jobs only.

## Prerequisites and commands

Use Node 24.12.0 and npm 11.19.0, PostgreSQL, Chromium and Docker with Linux
container/bridge-network permissions. For an exe.dev VM use the pinned validation
runner described in [factorize-validation-runner.md](factorize-validation-runner.md).
Docker is an additional host prerequisite: verify `docker info` succeeds. Missing
prerequisites fail validation rather than skipping coverage.

```sh
npm ci
npm run bootstrap:test
# Export DATABASE_URL, AUTH_TEST_DATABASE_URL and QUEUE_TEST_DATABASE_URL printed above.
npm run test:docker
npm test
```

The focused command builds the deployable credential-proxy Dockerfile and a small
code-job fixture image with cached Docker layers. Initial builds require registry
and Debian/npm download access; subsequent runs reuse layers. No image publication,
Fly token, model account or external API credential is needed. The command resolves
locally built images to immutable Docker image IDs and uses those exact IDs for
provisioning. Keep several GiB free for images/build cache.

For a separate local PostgreSQL container, bind its port to loopback and supply
`VALIDATION_DATABASE_URL` and `VALIDATION_DATABASE_ADMIN_URL` to bootstrap. Include
`?sslmode=disable` for a local server without TLS. Both URLs must use localhost or
127.0.0.1; never use a shared or production database.

For example, this creates a separate local PostgreSQL instance without changing
an existing VM service:

```sh
docker run -d --name factorize-validation-postgres \
-e POSTGRES_PASSWORD=local-validation-only -p 127.0.0.1::5432 postgres:16-alpine
for attempt in $(seq 1 30); do
docker exec factorize-validation-postgres pg_isready -U postgres && break
sleep 1
done
factorize_pg_port="$(docker inspect --format '{{(index (index .NetworkSettings.Ports "5432/tcp") 0).HostPort}}' factorize-validation-postgres)"
export VALIDATION_DATABASE_URL="postgresql://postgres:local-validation-only@127.0.0.1:${factorize_pg_port}/factorize_validation?sslmode=disable"
export VALIDATION_DATABASE_ADMIN_URL="postgresql://postgres:local-validation-only@127.0.0.1:${factorize_pg_port}/postgres?sslmode=disable"
npm run bootstrap:test
# Export the three variables printed by bootstrap, then run npm test or npm run test:docker.
# When finished with this isolated helper:
# docker rm -f factorize-validation-postgres
```

The complete scenario has a 120-second test deadline after image preparation;
the host subprocess also has a deadline. Root validation includes this command
and allows 760 seconds for the complete suite.

## Shared host boundary

`MachineJobExecutionBackend` implements reservation/recovery, launch sequencing,
run-credential delivery, guest-generated keys/CSR enrollment, shared launcher and
mTLS tunnel installation, result/log/file collection and shutdown. The Fly wrapper
retains existing Fly handles and identities. Docker implements container lifecycle,
operation labels, private stdin execution and bounded file transfer. Host Docker
access is never mounted into the proxy or job.

`createLocalExecutionRunner` drives the real PostgreSQL scheduler in Node, with a
public provider factory used consistently for launch, polling and cleanup.
`createLocalArtifactStorage` supplies local artifact persistence. The local HTTPS
server passes requests to the application's real Fetch handler. The E2E provides
only Node replacements for unavailable Cloudflare platform classes; it does not
mock backend or scheduler methods. Production Fly execution-host deployment is
outside this issue's scope.

The owner-session `/api/v1/credential-proxy/setup` operation calls the configured
execution host and completes real proxy registration. Browser capabilities for
unlock/lock/apply/status are one-use, valid for 60 seconds and bound to owner,
action, application origin and proxy boot. Unlock keys go directly to the proxy,
which verifies the current encrypted generation before admitting access. Factorize
never accepts plaintext unlock keys through these application endpoints.

## Evidence and limits

The scenario creates its own migrated database, owner identity, HTTPS CA and
synthetic credentials. Jobs, encrypted integrations, verification records, grants
and runs are created/updated through authenticated application APIs. Provisioning
uses the shared one-use bootstrap and real control/enrollment endpoints.

The job and fake API occupy separate networks; only the proxy joins both. The fake
API has no published port. Saved code proves direct TCP access fails and proxy
access succeeds, discovers its granted integration, validates a unique response,
and writes a correlated structured result and output. Independent fixture receipts
verify the injected bearer credential, method, path and body. Locked access and a
saved but ungranted integration produce no additional upstream receipt.

Container inspection, observed guest stdin, installed files, logs and stored
artifacts are checked for upstream/run credential leakage. Results/logs are
persisted and the scheduler destroys the job container before the teardown's
cleanup runs. The built proxy image exercises its actual entry points, OpenSSL,
writable runtime directories and memory-backed TLS storage; it stays healthy
beyond the former two-second startup deadline and shuts down normally.

The test-only exact-origin transport requires NODE_ENV=test plus an explicit test
configuration. It pins the fixture IP, origin and CA while retaining TLS hostname
and certificate verification. Production destination policy continues to reject
private IPs. This does not validate live Fly authentication, networking or exec/SFTP.

## Cleanup and recovery

The command uses unique `fz-*` namespaces, ephemeral ports and isolated
`docker_e2e_*` databases. Both fixture teardown and outer process cleanup cover
failures/signals. After a hard host termination, inspect:

```sh
docker ps -a --filter label=sh.factorize.test.namespace
docker network ls --filter name=fz-
```

Remove only containers/networks whose labels/names match the interrupted run.
Stop its runner before dropping its exact `docker_e2e_*` database. Cached test
images remain deliberately for reuse; remove only the Factorize test image tags
or their known build-cache entries when reclaiming space.

The narrower infrastructure check remains available:

```sh
docker pull alpine:3.22
npm exec --workspace=factorize -- vitest run --config scripts/docker-infrastructure.config.ts
```
# Local Docker execution validation

Use the pinned Factorize validation runner documented in
[factorize-validation-runner.md](factorize-validation-runner.md). Run `npm ci`,
then `npm run test:local` for the required complete suite. For focused iteration,
bootstrap the isolated local database and run `npm run test:docker` with the
printed variables. Remote/shared databases are refused.

The Docker lane builds only the isolated code-job fixture image. It executes a
saved job through the real API, scheduler, Fly lifecycle backend, job launcher,
localhost identity helper, signed JWT verifier, selected backend egress,
artifact persistence and provider cleanup. A test-local Unix-socket issuer
supplies synthetic Fly-shaped JWTs and fixture JWKS. This is deterministic
protocol evidence, not live Fly identity evidence. No production verifier
fallback or fixture key is installed by application code.

The test also checks an unselected credential, permanent disconnect revocation,
credential-free guest configuration, stored results and cleanup after artifact
collection. Docker resource labels, isolated database names, bounded process
trees and independent fallback cleanup keep failures local to this invocation.
The separate infrastructure test covers idempotent creation and guest transport.

The standalone proxy image and owner proxy/unlock setup API have been removed.
`TEST_DOCKER_EXECUTION` exposes only an explicitly enabled test execution target;
production execution uses documented exe.dev or Fly identity and provisioning.
81 changes: 21 additions & 60 deletions docs/fly-guest-transport.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,21 @@
# Fly guest command and file transport

`createFlyGuestTransport` in `packages/api/src/fly-guest-transport.ts` uses the documented `fly machine exec` and `fly sftp put/get` commands. It starts Fly CLI directly with an argument vector; guest command arguments and paths are never interpolated into a shell command. The Fly API token is supplied through the CLI's `FLY_API_TOKEN` environment variable and is not included in arguments, results, or transport errors.

The execution host must have a supported `fly` CLI installed and access to the selected Fly app and Machine. The token must authorize Machine execution and SFTP access. Machines must be running. The guest image must support Fly's Machine exec and SFTP paths; images do not need exe.dev's SSH tooling or systemd. `run()` accepts a nonempty executable and argv plus optional stdin bytes, returns captured stdout/stderr and the process exit code, and enforces a deadline of at most ten minutes and a combined output cap of at most 16 MiB. File operations enforce a configurable transfer cap of at most 64 MiB and use normalized absolute guest paths. Timed out operations terminate the CLI process group.

Both execution backends install and invoke the same small `factorize-job` guest launcher as `exedev`. It requires Python 3, the `exedev` account, and a writable `/home/exedev/.factorize-job` directory. It accepts a bounded JSON launch payload over stdin, starts the code script or agent argv without a shell command assembled from the payload, writes structured process state, preserves stdout/stderr and the run result, and exposes `factorize-job status` for Fly scheduler polling. Fly images also need `runuser`, `/bin/sh`, `/usr/local/bin`, Node.js and OpenSSL for portable proxy access, and the provider's documented Machine exec/SFTP support. Codex images must provide the tested `codex-cli 0.167.1`; Fly checks this as the `exedev` user before launch and returns a bounded failure for a missing or unsupported version. Code jobs do not require Codex. Image verification checks Python 3 for exe.dev execution; Fly reports a bounded launch failure when guest prerequisites are absent. The helper and job Machine are not configured to restart and replay a failed process. Custom entrypoints can finish their own setup before the backend invokes the launcher.

The local protocol fixtures verify process result handling, timeout, output overflow, disconnect, safe argv construction, and file byte transfer. They do not validate live Fly authentication, Fly CLI compatibility, routing to a real Machine, or the guest's exec/SFTP capabilities. A separate opt-in validation requires a Fly account, an authorized app/Machine and token, an installed Fly CLI, and a custom image with Fly exec/SFTP support; no Fly network call is part of the required test suite.

For portable integrations, the scheduler sends the scoped run credential over Fly's authenticated Machine exec channel directly to the dedicated credential proxy's private Unix socket. The proxy keeps it in process memory, bound to that run and provider VM identity, and removes it when durable revocation arrives. The credential is not part of Machine configuration, launch files, or the job VM payload. During guest launch, the VM generates its own private key and CSR; the proxy signs the CSR for the provider VM identity, and only the certificate and trust bundle return to the scheduler for installation. An internal-only Fly service exposes the proxy tunnel listener on port 9090. The guest starts a loopback CONNECT forwarder and sets HTTP(S)_PROXY for the job process. Each tunnel connection presents only its run ID over mTLS; the proxy retrieves its in-memory credential to perform fresh control-plane enrollment.

## Credential-proxy package and local evidence

`packages/credential-proxy` is a private npm workspace of native ES modules and
uses Node.js built-ins at runtime. Its package entry points are declared in
`package.json`; only `src/` is included in the package artifact, excluding the
test suite's synthetic TLS keys and fixtures. The Fly VM tunnel helper is generated from
`packages/api/src/fly-job-tunnel-helper.ts`. After `npm ci`, inspect the local
package contents without publishing with:

```sh
npm pack --dry-run --workspace=@factorize/credential-proxy --json
npm run test:proxy
```

The provisioner accepts only an image pinned by digest and equal to the reviewed
image supplied by deployment configuration. Proxy control credentials enter
through the private bootstrap socket; run credentials enter through Fly's
authenticated Machine exec channel and remain in proxy memory. Neither user
unlock keys nor integration credentials belong in image build arguments, image
configuration, guest environment variables, or launch payloads.

The minimal credential-proxy OCI recipe is `packages/credential-proxy/Dockerfile`.
It pins the Node 24.12.0 multi-platform manifest digest, installs the
authentication-only Codex CLI 0.167.1 from a checked-in lockfile, copies only
proxy runtime source, and runs as the unprivileged `node` user. Build locally
without publishing using `scripts/build-credential-proxy-image.sh`; Docker
Buildx emits an OCI archive with max-mode provenance and an SBOM under
`~/.factorize-job/credential-proxy-image/`, alongside a compact JSON summary
binding the archive digest to the source commit, base digest, and Codex version.
The OCI archive and generated provenance are inspectable/rebuildable artifacts;
this repository deliberately has no publishing workflow, and this local recipe
does not establish that any production digest has been published or approved.
The provisioner's reviewed-digest configuration must still be updated through
the separate release process after image review. Live Fly networking also
remains unverified.

Local coverage is split across fixtures to avoid repeating full application
startup: `packages/credential-proxy/test/fly-guest-helper.e2e.test.mjs` executes
the generated guest helper against an mTLS proxy and local HTTPS upstream and
rejects a mismatched VM binding; `proxy-listener.e2e.test.mjs` checks per-VM
reflection, locked access, configured-origin forwarding, redirect rejection,
interrupted writes, and reconnect after lock/unlock. These synthetic fixtures do
not establish live provider or production behavior. The combined
`locked scoped run reconnects with its current grant while another VM stays denied`
fixture exercises the production grant resolver with a synthetic Factorize run
snapshot and local TLS upstream. The repository runbook
`packages/docs/self-hosting/credential-proxy-security.mdx` documents key handling, lifecycle recovery,
accepted provider/control-plane risks, and the independent Fly shutdown steps.
# Fly run guest transport

The backend uses the documented Machines HTTP exec API with an argv `command`
array and optional stdin. It does not run a Fly CLI or SSH agent in the Worker.
`packages/api/src/fly-http-guest-transport.ts` handles bounded output, deadlines,
file uploads and downloads. `flyJobGuest` supplies the tenant's encrypted Fly
provisioning credential only to the Machines API; it never enters the guest.

Machines are created with top-level region and the documented default boot
behavior. Their init process only sleeps; image CMD does not launch a job. The
backend polls startup for at most three minutes, and starts stopped/suspended
Machines once without replaying ambiguous responses. It does not race image
preparation with a start request in the `created` state. Before job launch, Factorize verifies the guest's signed OIDC token
from `/.fly/api`, pins the organization-slug issuer and exact subject/Machine,
and persists the immutable run binding. The root-owned localhost identity
helper requests fresh vendor tokens and forwards API, selected credential and
artifact requests to the backend. Upstream credentials stay in Factorize.

The former standalone credential-proxy workspace, image, certificate tunnel and
browser capabilities are removed by GEN-2922. See the credential cutover runbook
before deploying this breaking change.
Loading
Loading