Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
32 changes: 32 additions & 0 deletions docs/portable-workloads.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Portable workload attachment

Portable attachment authenticates an enrolled process as a workload. The existing Factorize proxy evaluates workload scopes, integration revocation epochs, provider-specific permissions, and server-selected origins just as it does for Fly. The enrollment binds a server-issued grant ID, tenant, workload UUID and attachment to an ephemeral signing key. The signed body covers the entire proxy request, including the upstream method, relative path, headers and payload. Tailscale and Headscale remain optional and customer-managed.

## Try it with isolated fixtures

From the repository root on a validation runner with Node 24.21.0, npm 11.19.0, OpenSSL, and the repository's disposable local PostgreSQL database:

```sh
npm ci
npm run bootstrap:test
# Export the local AUTH_TEST_DATABASE_URL printed by bootstrap:test.
cd packages/api
../../node_modules/.bin/vitest run test/portable-workloads.postgres.test.ts test/vm-enrollment.postgres.test.ts
```

The fixture starts a local TLS listener and passes HTTPS requests to the Worker. Only upstream provider fetches are simulated. It creates fake X and Cloudflare connections and runs separate Node processes with an isolated test CA. The tests require no customer accounts.

## Operator and client walkthrough

1. Use an authorized operator credential with `vms:edit`, `proxy:use` and the integration permission to delegate. Read the integration's current required scope from reflection. POST JSON to `/api/v1/workloads/grants`, for example `{"workload":"<workload UUID>","permissions":{"scopes":["proxy:use","integration:<integration UUID>:<current epoch>"]}}`. The same permission snapshot evaluator used by Fly rejects scopes outside the operator's effective access. Record the grantId. A browser owner session alone lacks integration delegation scopes.
2. POST to `/api/v1/workloads/grants/<grantId>/enrollments` with an authenticated workspace owner session and its same-origin Origin header. Deliver the returned JSON directly to the intended process through your trusted channel. It contains a two-minute, single-use secret. Keep it out of shell arguments, command history, environment exports, disk, and logs.
3. On a local computer, VM or VPS with Node 24.21 or later, pipe that JSON from your trusted delivery tool to `node packages/workload-client/example.ts https://factorize.example <X-integration-UUID> /2/users/me`. The example prints the upstream status and disconnects. In a long-running process, import `attach` from `factorize-workload-client`, call `await attach(origin, enrollment)`, use `session.request({integration, method, path, body})`, and `await session.close()` during shutdown.
4. DELETE `/api/v1/workloads/grants/<grantId>` as the owner. The next request under any of its sessions fails. Create a fresh grant if a revoked workload needs access again.

## Trust, expiry and recovery

The enrollment recipient can be the first process to redeem it. Whoever controls delivery controls that choice. Enrollment proves possession of the process key. It supplies no evidence of provider ownership or host integrity. A root user controlling a live host can use the process or intercept enrollment. Workload names, IP addresses, hostnames and clock readings supply no identity. Fly OIDC grants stay bound to their enrolled Fly machine.

Redemption signs the body containing the one-time secret and ephemeral public key. The server compares a stored SHA-256 digest and atomically consumes the secret while binding the key. The client keeps a non-exportable P-256 signing key in memory. Every compact ES256 JWS binds tenant, workload UUID, attachment ID, POST, exact HTTPS URL, SHA-256 of the raw body, issue time and a strictly increasing sequence. PostgreSQL locks the row and accepts a sequence once. Issuance timestamps limit replay lifetime. Session lookup and live authorization use tenant and attachment together. The proxy checks integration availability, revocation epoch, scopes and existing provider rules again before forwarding.

The client heartbeats every 10 seconds. A session expires 30 seconds after its last accepted heartbeat or redemption. A clean disconnect takes effect at commit. After a crash or network loss an already-sent heartbeat may still arrive within the proof freshness window (15 seconds old, up to 5 seconds of forward clock skew), giving a maximum of 50 seconds after the last signature. An in-flight upstream request can finish. A terminated process loses its key even if its directory is copied. After a lost connection, restart with fresh enrollment. If delivery or the process may have been compromised, revoke the grant before issuing a replacement. Rotate upstream credentials separately if the upstream account itself was compromised.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading