@runeditrun/rer 0.2.10 → 0.2.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli/contract.mjs +1 -1
- package/cli/demo-host.mjs +24 -2
- package/cli/parse.mjs +2 -1
- package/global/CHANGELOG.md +21 -0
- package/modules/demo-host/README.md +9 -0
- package/modules/demo-host/plan.mjs +9 -4
- package/modules/demo-host/remove.mjs +67 -0
- package/modules/deploy-kit/site.mjs +1 -1
- package/modules/operator-auth/dev/index.mjs +7 -5
- package/modules/operator-auth/dev-gate.mjs +2 -1
- package/modules/operator-auth/identity/oidc/index.mjs +6 -1
- package/modules/operator-auth/rejected-response.mjs +44 -0
- package/modules/operator-auth/routes.mjs +6 -1
- package/package.json +1 -1
package/cli/contract.mjs
CHANGED
|
@@ -11,7 +11,7 @@ const definitions = {
|
|
|
11
11
|
build: [['--site'], 'Production build with private local settings excluded and restored. --site instead writes the static run site (homepage, /run, docs) to its declared folder and prints that folder.'],
|
|
12
12
|
verify: [[], 'Run the complete internal verification target.'],
|
|
13
13
|
reset: [['--yes'], 'Confirmed removal of the declared local inventory only.'],
|
|
14
|
-
deploy: [['--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret'], 'Owner-account deployment and health; dry run performs local validation/build only. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. After a healthy deploy rer claims the setup owner on the hosted app with the one-time setup token, then removes the token. --set-secret NAME (value from the environment or --env-file) and --unset-secret NAME change one secret of the deployed Worker without a build and record its new version. --remove --yes deletes what this environment\'s deploy record says rer created (Worker, D1, R2, KV, queues), reads back that each is gone, and touches nothing else. --site deploys the run site instead: an assets-only Worker on its custom domain with www redirected; with --dry-run it builds the site and prints the plan with no provider request. --demo deploys the hosted demo instead (deploy-demo.json): a front Worker on demo.<domain> giving each visitor their own signed-in, throwaway container of this seed that can send nothing; --dry-run writes it to .rer/demo-host with no provider request.'],
|
|
14
|
+
deploy: [['--environment', '--dry-run', '--site', '--demo', '--host', '--env-file', '--image', '--bind-address', '--http-port', '--https-port', '--remove', '--yes', '--set-secret', '--unset-secret'], 'Owner-account deployment and health; dry run performs local validation/build only. Declared secrets come from the environment or --env-file (an owned 0600 KEY=VALUE file); a new Worker gets the local setup owner and fresh generated secrets when they are not given. After a healthy deploy rer claims the setup owner on the hosted app with the one-time setup token, then removes the token. --set-secret NAME (value from the environment or --env-file) and --unset-secret NAME change one secret of the deployed Worker without a build and record its new version. --remove --yes deletes what this environment\'s deploy record says rer created (Worker, D1, R2, KV, queues), reads back that each is gone, and touches nothing else. --site deploys the run site instead: an assets-only Worker on its custom domain with www redirected; with --dry-run it builds the site and prints the plan with no provider request. --demo deploys the hosted demo instead (deploy-demo.json): a front Worker on demo.<domain> giving each visitor their own signed-in, throwaway container of this seed that can send nothing; --dry-run writes it to .rer/demo-host with no provider request; --demo --remove --yes deletes that demo (its Worker, demo.<domain> Custom Domain and Container application, each only while the record its deploy left proves it the demo\'s), reads back that each is gone, and is a no-op once it is.'],
|
|
15
15
|
export: [['--target', '--output', '--origin', '--session-file'], 'Complete supported installation archive with integrity and exclusions.'],
|
|
16
16
|
import: [['--target', '--input', '--journal', '--origin', '--session-file', '--yes', '--legacy-v1', '--acknowledge-unverified-metadata', '--output'], 'Confirmed atomic restore into an empty destination; --journal LATER_ARCHIVE also fences rows that installation erased since. Backup-only local v1 recovery requires --legacy-v1 --acknowledge-unverified-metadata and a new --output v2 archive; --journal requires normal v2 import.'],
|
|
17
17
|
outbox: [['--port', '--host', '--owner-email', '--open'], 'Credential-free local outbox URL; optional ordinary sign-in request and explicit browser opening.'],
|
package/cli/demo-host.mjs
CHANGED
|
@@ -10,7 +10,9 @@ import { DEMO_FILES, demoPlan } from '../modules/demo-host/plan.mjs';
|
|
|
10
10
|
// (modules/demo-host), from deploy-demo.json. It writes .rer/demo-host/: the
|
|
11
11
|
// front Worker, its wrangler.json and the container image folder (workerd
|
|
12
12
|
// engine). --dry-run stops there, so `wrangler dev` can serve that folder with
|
|
13
|
-
// Docker; a deploy runs `wrangler deploy` on it with the Turnstile secret
|
|
13
|
+
// Docker; a deploy runs `wrangler deploy` on it with the Turnstile secret and
|
|
14
|
+
// the demo's record as the version message. `--remove --yes` removes what that
|
|
15
|
+
// record proves is the demo's (modules/demo-host/remove.mjs).
|
|
14
16
|
export async function demoHostCommand(project, options, store, signal, out, operation) {
|
|
15
17
|
const read = async path => { try { return JSON.parse(await readFile(await contained(project.root, path), 'utf8')); } catch (error) { if (error instanceof RerError) throw error; throw invalid(`Missing or malformed ${path}.`); } };
|
|
16
18
|
const app = await read(project.adapter.deploy?.declaration ?? 'deploy.json'), declaration = await read('deploy-demo.json');
|
|
@@ -18,6 +20,7 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
18
20
|
let plan;
|
|
19
21
|
try { plan = demoPlan({ project: app.project, environment: options.environment ?? 'production', compatibilityDate: app.compatibilityDate, originVar: app.originVar, declaration, turnstileSiteKey: process.env.TURNSTILE_SITE_KEY?.trim() }); }
|
|
20
22
|
catch (error) { throw invalid(`The demo deploy declaration is invalid (${error.message}). deploy-demo.json holds {"version": 1, "domain": "<run site apex>", "name": "<product name>"}, optionally "maxInstances" and plain "settings".`); }
|
|
23
|
+
if (options.remove) return removeDemo(plan, store);
|
|
21
24
|
if (process.env.RER_DEMO_OPERATOR_TOKEN && (process.env.RER_DEMO_OPERATOR_TOKEN.length < 32 || process.env.RER_DEMO_OPERATOR_TOKEN.length > 512)) throw invalid('RER_DEMO_OPERATOR_TOKEN must contain 32 to 512 characters.');
|
|
22
25
|
const folder = join(project.root, '.rer', 'demo-host');
|
|
23
26
|
await rm(folder, { recursive: true, force: true });
|
|
@@ -44,7 +47,26 @@ export async function demoHostCommand(project, options, store, signal, out, oper
|
|
|
44
47
|
const require = createRequire(join(project.root, 'package.json'));
|
|
45
48
|
const manifest = require.resolve('wrangler/package.json');
|
|
46
49
|
const wrangler = join(dirname(manifest), JSON.parse(await readFile(manifest, 'utf8')).bin.wrangler);
|
|
47
|
-
await store.run('Deploying the demo Worker and its container image', process.execPath, [wrangler, 'deploy', '--config', 'wrangler.json', '--secrets-file', '.secrets.json'], { cwd: folder, signal });
|
|
50
|
+
await store.run('Deploying the demo Worker and its container image', process.execPath, [wrangler, 'deploy', '--config', 'wrangler.json', '--secrets-file', '.secrets.json', '--message', plan.record], { cwd: folder, signal });
|
|
48
51
|
} finally { await rm(secrets, { force: true }); }
|
|
49
52
|
return { dryRun: false, deployed: true, origin: plan.origin, demo: summary };
|
|
50
53
|
}
|
|
54
|
+
|
|
55
|
+
async function removeDemo(plan, store) {
|
|
56
|
+
const names = ['CLOUDFLARE_ACCOUNT_ID', 'CLOUDFLARE_API_TOKEN'];
|
|
57
|
+
if (names.some(name => !process.env[name]?.trim())) throw missing(`${names.join(' and ')} are required to remove the demo; see DEMO.md "Removing a hosted demo".`);
|
|
58
|
+
const { cloudflare } = await import('../modules/deploy-kit/provider.mjs');
|
|
59
|
+
const { providerRefusal } = await import('../modules/deploy-kit/diagnostics.mjs');
|
|
60
|
+
const { demoRemove } = await import('../modules/demo-host/remove.mjs');
|
|
61
|
+
await store.step(`Removing the demo Worker ${plan.worker} on ${plan.hostname}`);
|
|
62
|
+
let result;
|
|
63
|
+
try { result = await demoRemove({ api: cloudflare({ accountId: process.env.CLOUDFLARE_ACCOUNT_ID, token: process.env.CLOUDFLARE_API_TOKEN }), plan }); }
|
|
64
|
+
catch (error) {
|
|
65
|
+
if (error instanceof RerError) throw error;
|
|
66
|
+
const code = /^[a-z0-9-]{1,80}$/.test(error.message) ? error.message : 'demo-remove-failed';
|
|
67
|
+
const detail = [error.resource && `(${error.resource})`, error.remaining?.length && `still listed: ${error.remaining.join(', ')}`, providerRefusal(error)].filter(Boolean).join('; ');
|
|
68
|
+
throw new RerError('deploy_refused', `Demo remove stopped: ${code}${detail ? ` ${detail}` : ''}. Nothing that is not the demo's was touched; run it again once the cause is fixed.`, 1);
|
|
69
|
+
}
|
|
70
|
+
store.report(result.alreadyRemoved ? `deploy --demo --remove: no demo Worker ${plan.worker} exists; nothing to remove.` : `Removed ${result.removed.join(', ')} and read back that each is gone.`);
|
|
71
|
+
return { removed: true, demo: { worker: plan.worker, hostname: plan.hostname }, deleted: result.removed, alreadyRemoved: Boolean(result.alreadyRemoved) };
|
|
72
|
+
}
|
package/cli/parse.mjs
CHANGED
|
@@ -77,7 +77,8 @@ export function parse(argv, cwd = process.cwd(), { independent = false, deferTai
|
|
|
77
77
|
if (options.profile !== undefined && options.profile !== 'first-party') throw invalid('The supported explicit profile is first-party.');
|
|
78
78
|
if (options.environment !== undefined && !/^[a-z][a-z0-9-]{0,39}$/.test(options.environment)) throw invalid('Provide a valid deployment environment name.');
|
|
79
79
|
for (const key of ['setSecret', 'unsetSecret']) if (options[key] !== undefined && !/^[A-Z][A-Z0-9_]{0,63}$/.test(options[key])) throw invalid('Name a declared secret binding, such as SESSION_SECRET.');
|
|
80
|
-
if(verb==='deploy'&&options.demo&&(options.site||['platform','image','bindAddress','httpPort','httpsPort','envFile','host','
|
|
80
|
+
if(verb==='deploy'&&options.demo&&(options.site||['platform','image','bindAddress','httpPort','httpsPort','envFile','host','setSecret','unsetSecret'].some(key=>options[key]!==undefined)))throw invalid('--demo takes only --environment, --dry-run and --remove --yes: the hosted demo is its own Worker on demo.<domain>.');
|
|
81
|
+
if(verb==='deploy'&&options.demo&&options.remove&&(options.dryRun||!options.yes))throw invalid(options.dryRun?'Use --remove and --dry-run on separate runs.':'deploy --demo --remove deletes the hosted demo\'s Worker, its demo.<domain> Custom Domain and its Container application. Add --yes to confirm.');
|
|
81
82
|
if ((options.remove || options.setSecret || options.unsetSecret) && options.site) throw invalid('--remove, --set-secret and --unset-secret act on the application Worker, not the run site.');
|
|
82
83
|
if (options.origin !== undefined) {
|
|
83
84
|
let url; try { url = new URL(options.origin); } catch { throw invalid('Provide a valid credential-free origin.'); }
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.12
|
|
4
|
+
|
|
5
|
+
- Import-kit resumable field redaction finishes however large one import job is. A step takes as many jobs as fit the request (at most 25); a job that does not fit alone is redacted in pages of its entries, and a step that would not fit writes nothing and is retried smaller, so every committed step stays inside D1's per-request limit and the erasure reaches its final batch. Receipts and match counts are unchanged.
|
|
6
|
+
- `rer deploy --demo --remove --yes [--environment E]` removes a hosted demo: its Custom Domain (and with it the domain's DNS record), its Container application and its Worker, each by exact id and only while the record the deploy left on the Worker version proves it the demo's. Anything else is refused before the first delete; a second run is a no-op.
|
|
7
|
+
- `export/run-demo.yml` gains `test_only` (the demo-test host at `demo.test.<domain>`) and `remove` dispatch inputs, and its readback after a deploy waits for the new hostname to resolve in public DNS, bounded and with a clear message, instead of failing on a first deploy.
|
|
8
|
+
|
|
9
|
+
### Upgrade notes
|
|
10
|
+
|
|
11
|
+
- Seeds take the import-kit change with their next Base refresh (a vendored `modules/import-kit` copy is not replaced by the npm pin). A continuation stored by an earlier kit still reads.
|
|
12
|
+
- A hosted demo deployed by an earlier rer carries no record, so `--remove` refuses it as not the demo's: deploy it once with 0.2.12 (`rer deploy --demo`, or run-demo with the same inputs), then remove it. Copy Base's `export/run-demo.yml` for the new inputs and readback; a manual run no longer needs `RUN_DEMO_DEPLOY`.
|
|
13
|
+
|
|
14
|
+
## 0.2.11
|
|
15
|
+
|
|
16
|
+
- New Base foundations generate public Run instructions for the edition's planned product repository, distinct migration ordinals, and setup names matching the edition.
|
|
17
|
+
- Owned early auth, OIDC, local dev and template refusals finish ordinary request bodies before responding. Oversized or stalled uploads are bounded while privacy headers are retained.
|
|
18
|
+
|
|
19
|
+
### Upgrade notes
|
|
20
|
+
|
|
21
|
+
- Seeds receive these source changes with their next Base refresh; changing the npm pin alone does not refresh seed-owned runtime copies. Existing applied migration histories keep their names.
|
|
22
|
+
- Optional import-kit selection remains deferred until a canonical complete migration schema can drive generation; product import flows still need their own authorized adapter.
|
|
23
|
+
|
|
3
24
|
## 0.2.10
|
|
4
25
|
|
|
5
26
|
- First-owner bootstrap and signed owner claims use a client-IP rate budget, so junk setup-token requests from another client cannot block the correct claim. Repeated wrong tokens from one client remain limited.
|
|
@@ -23,6 +23,15 @@ it with these files and the seed's container image folder (workerd engine) to
|
|
|
23
23
|
container that stops by itself ends its demo too.
|
|
24
24
|
- `capacity.mjs`: `DemoCapacity` admits at most `max_instances` live demos.
|
|
25
25
|
- `pages.mjs`: the start and ended pages (12ui designs), strict CSP.
|
|
26
|
+
- `remove.mjs`: `rer deploy --demo --remove --yes`. The deploy passes the
|
|
27
|
+
demo's record (`plan.record`) to `wrangler deploy --message`; removal takes
|
|
28
|
+
the Worker for the demo's only while it serves that version, the Custom
|
|
29
|
+
Domain only while it routes to that Worker and the Container application
|
|
30
|
+
only while it belongs to that Worker's DemoContainer namespace, refuses
|
|
31
|
+
anything else before the first delete, deletes by exact id (the Worker
|
|
32
|
+
last) and reads back that each is gone (export/DEMO.md "Removing a hosted
|
|
33
|
+
demo"). `cli/demo-remove.test.mjs` runs it through the CLI against a fake
|
|
34
|
+
Cloudflare account (`tests/demo-account.mjs`).
|
|
26
35
|
|
|
27
36
|
`node --test modules/demo-host/tests/*.test.mjs` runs the Worker in workerd
|
|
28
37
|
with its real Durable Objects and rate limit; Turnstile and the container
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { assert, resourceName } from '../deploy-kit/validation.mjs';
|
|
2
|
+
import { assert, hash, resourceName } from '../deploy-kit/validation.mjs';
|
|
3
3
|
import { ownerWorkerName } from '../deploy-kit/owner.mjs';
|
|
4
4
|
import { siteDeclaration } from '../deploy-kit/site.mjs';
|
|
5
5
|
|
|
@@ -34,7 +34,7 @@ export function demoDeclaration(value, originVar) {
|
|
|
34
34
|
export function demoPlan({ project, environment, compatibilityDate, originVar, declaration, turnstileSiteKey }) {
|
|
35
35
|
assert(/^\d{4}-\d{2}-\d{2}$/.test(compatibilityDate ?? '') && /^[A-Z][A-Z0-9_]{0,63}$/.test(originVar ?? ''), 'invalid-plan');
|
|
36
36
|
const { domain, name, maxInstances, settings } = demoDeclaration(declaration, originVar);
|
|
37
|
-
const worker = `${ownerWorkerName(project, environment)}--demo`, hostname = `demo.${domain}
|
|
37
|
+
const worker = `${ownerWorkerName(project, environment)}--demo`, hostname = `demo.${domain}`, container = worker.replace(/-+/g, '-');
|
|
38
38
|
assert(resourceName(worker), 'owner-name-too-long');
|
|
39
39
|
// Rate limit namespaces are account-wide integers: one per demo Worker.
|
|
40
40
|
const namespace = String(1000 + parseInt(createHash('sha256').update(worker).digest('hex').slice(0, 8), 16) % 1_000_000_000);
|
|
@@ -46,8 +46,13 @@ export function demoPlan({ project, environment, compatibilityDate, originVar, d
|
|
|
46
46
|
...(turnstileSiteKey ? { TURNSTILE_SITE_KEY: turnstileSiteKey } : {}) },
|
|
47
47
|
durable_objects: { bindings: [{ name: 'DEMO', class_name: 'DemoContainer' }, { name: 'CAPACITY', class_name: 'DemoCapacity' }] },
|
|
48
48
|
migrations: [{ tag: 'v1', new_sqlite_classes: ['DemoContainer', 'DemoCapacity'] }],
|
|
49
|
-
containers: [{ name:
|
|
49
|
+
containers: [{ name: container, class_name: 'DemoContainer', image: './image/Dockerfile', max_instances: maxInstances, instance_type: 'basic' }],
|
|
50
50
|
ratelimits: [{ name: 'STARTS', namespace_id: namespace, simple: { limit: 3, period: 60 } }],
|
|
51
51
|
};
|
|
52
|
-
return { worker, hostname, origin: `https://${hostname}`, maxInstances, settings: Object.keys(settings), wrangler };
|
|
52
|
+
return { worker, hostname, container, record: demoRecord({ worker, hostname, container }), origin: `https://${hostname}`, maxInstances, settings: Object.keys(settings), wrangler };
|
|
53
53
|
}
|
|
54
|
+
|
|
55
|
+
/** The demo's record of what `rer deploy --demo` creates, kept on the provider so a
|
|
56
|
+
* fresh checkout (a CI runner) can remove it: the deploy writes it as the Worker
|
|
57
|
+
* version's message, and only a Worker serving it is taken for the demo's own. */
|
|
58
|
+
export const demoRecord = ({ worker, hostname, container }) => `rer-demo:${hash({ worker, hostname, container })}`;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { assert } from '../deploy-kit/validation.mjs';
|
|
2
|
+
import { workerSettings } from '../deploy-kit/owner.mjs';
|
|
3
|
+
import { servedVersion } from '../deploy-kit/site.mjs';
|
|
4
|
+
import { deleteWorker } from '../deploy-kit/teardown.mjs';
|
|
5
|
+
|
|
6
|
+
/* `rer deploy --demo --remove --yes`: remove the hosted demo `rer deploy --demo`
|
|
7
|
+
* made for this environment, by exact provider ids, and nothing else. What the
|
|
8
|
+
* deploy made: the front Worker (its Durable Object namespaces go with it), the
|
|
9
|
+
* Workers Custom Domain demo.<domain> (Cloudflare adds and removes its DNS
|
|
10
|
+
* record with it) and the Container application `wrangler deploy` created for
|
|
11
|
+
* the Worker's DemoContainer namespace. It makes no D1, KV, R2, queue or DNS
|
|
12
|
+
* record of its own: the domain's record is Cloudflare's, and goes with it.
|
|
13
|
+
*
|
|
14
|
+
* The Worker is the demo's own only while it serves the version carrying the
|
|
15
|
+
* demo's record (plan.mjs `demoRecord`). The domain is the demo's only while it
|
|
16
|
+
* routes to that Worker, the Container application only while it belongs to
|
|
17
|
+
* that Worker's DemoContainer namespace. Anything else of those names, or
|
|
18
|
+
* attached to that Worker, is refused before the first delete. The Worker goes
|
|
19
|
+
* last, so a run cut short leaves the record for the next one; once everything
|
|
20
|
+
* is gone a second run is a no-op. */
|
|
21
|
+
|
|
22
|
+
function refuse(code, resource) { const error = new Error(code); error.resource = resource; return error; }
|
|
23
|
+
const rows = value => { assert(Array.isArray(value), 'provider-invalid-list'); return value; };
|
|
24
|
+
|
|
25
|
+
/** What exists of the demo now, each with its exact id; refuses whatever is not provably the demo's. */
|
|
26
|
+
async function inventory(api, plan) {
|
|
27
|
+
const named = rows(await api.request(`/workers/domains?hostname=${plan.hostname}`)).filter(row => row?.hostname === plan.hostname);
|
|
28
|
+
const attached = rows(await api.request(`/workers/domains?service=${plan.worker}`)).filter(row => row?.service === plan.worker);
|
|
29
|
+
const apps = rows(await api.request('/containers/applications')).filter(row => row?.name === plan.container);
|
|
30
|
+
const namespaces = rows(await api.list('/workers/durable_objects/namespaces')).filter(row => row?.script === plan.worker);
|
|
31
|
+
const worker = await workerSettings(api, plan.worker) !== null;
|
|
32
|
+
for (const row of named) if (row.service !== plan.worker) throw refuse('resource-name-collision', `domain:${plan.hostname}`);
|
|
33
|
+
if (worker) {
|
|
34
|
+
const served = await servedVersion(api, plan.worker);
|
|
35
|
+
if (served.annotation !== plan.record) throw refuse('resource-name-collision', `worker:${plan.worker}`);
|
|
36
|
+
if (!served.current) throw refuse('owned-resource-replaced', `worker:${plan.worker}`);
|
|
37
|
+
for (const row of attached) if (row.hostname !== plan.hostname) throw refuse('resource-not-in-record', `domain:${row.hostname}`);
|
|
38
|
+
} else if (named.length || attached.length || apps.length) {
|
|
39
|
+
// Without the Worker nothing proves these are the demo's.
|
|
40
|
+
throw refuse('uncertain-resource-create', named[0] || attached[0] ? `domain:${(named[0] ?? attached[0]).hostname}` : `container:${plan.container}`);
|
|
41
|
+
}
|
|
42
|
+
const container = namespaces.find(row => row.class === 'DemoContainer')?.id;
|
|
43
|
+
for (const app of apps) if (!container || app.durable_objects?.namespace_id !== container) throw refuse('resource-name-collision', `container:${plan.container}`);
|
|
44
|
+
return { worker, domains: named, apps };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export async function demoRemove({ api, plan, sleep }) {
|
|
48
|
+
const found = await inventory(api, plan);
|
|
49
|
+
if (!found.worker) return { worker: plan.worker, removed: [], remaining: [], alreadyRemoved: true };
|
|
50
|
+
const removed = [];
|
|
51
|
+
for (const domain of found.domains) {
|
|
52
|
+
await api.request(`/workers/domains/${domain.id}`, { method: 'DELETE' });
|
|
53
|
+
removed.push(`domain:${plan.hostname}`);
|
|
54
|
+
}
|
|
55
|
+
for (const app of found.apps) { await api.request(`/containers/applications/${app.id}`, { method: 'DELETE' }); removed.push(`container:${plan.container}`); }
|
|
56
|
+
await deleteWorker({ api, worker: plan.worker, ...sleep ? { sleep } : {} });
|
|
57
|
+
removed.push(`worker:${plan.worker}`);
|
|
58
|
+
// Read back: nothing of the demo is listed any more.
|
|
59
|
+
const remaining = [];
|
|
60
|
+
if (await workerSettings(api, plan.worker) !== null) remaining.push(`worker:${plan.worker}`);
|
|
61
|
+
for (const row of rows(await api.list('/workers/durable_objects/namespaces'))) if (row?.script === plan.worker) remaining.push(`durable-object:${row.class}`);
|
|
62
|
+
if (rows(await api.request(`/workers/domains?hostname=${plan.hostname}`)).some(row => row?.hostname === plan.hostname)) remaining.push(`domain:${plan.hostname}`);
|
|
63
|
+
const apps = rows(await api.request('/containers/applications'));
|
|
64
|
+
for (const app of found.apps) if (apps.some(row => row?.id === app.id)) remaining.push(`container:${plan.container}`);
|
|
65
|
+
if (remaining.length) { const error = new Error('remove-incomplete'); error.remaining = remaining; error.removed = removed.filter(item => !remaining.includes(item)); throw error; }
|
|
66
|
+
return { worker: plan.worker, removed, remaining: [] };
|
|
67
|
+
}
|
|
@@ -66,7 +66,7 @@ export function sitePlan({ project, environment, compatibilityDate, declaration,
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
/** The version the Worker's latest deployment serves, as the kit reads ownership: null when there is no Worker. */
|
|
69
|
-
async function servedVersion(api, worker) {
|
|
69
|
+
export async function servedVersion(api, worker) {
|
|
70
70
|
if (!await workerSettings(api, worker)) return null;
|
|
71
71
|
const { deployments } = await api.request(`/workers/scripts/${worker}/deployments`);
|
|
72
72
|
assert(Array.isArray(deployments) && deployments.length > 0, 'invalid-deployments');
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from '../rejected-response.mjs';
|
|
1
2
|
// Local dev identity. SERVER-ONLY and LOCAL-ONLY: load this layer only from a
|
|
2
3
|
// local-only Worker entry (a `wrangler dev` or Vite-serve entry), never from the
|
|
3
4
|
// deployed main. `rer build` refuses any build output containing the marker.
|
|
@@ -40,19 +41,20 @@ export function withDevIdentity(worker, { bindings = env => env, config: authCon
|
|
|
40
41
|
if (managedInstallation(env)) {
|
|
41
42
|
// Never admit a dev credential here; with dev identity on, serve nothing.
|
|
42
43
|
registerDevAdmission(null);
|
|
43
|
-
if (env.RER_DEV_IDENTITY !== 'off') return text(503, 'Dev identity refuses to run beside RER_INSTALLATION_ID with a non-loopback RER_MANAGEMENT_ORIGIN. Remove those bindings from local settings or use rer dev --login.');
|
|
44
|
-
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' ? devNotFound() : worker.fetch(request, original, execution);
|
|
44
|
+
if (env.RER_DEV_IDENTITY !== 'off') return rejectedResponse(request, text(503, 'Dev identity refuses to run beside RER_INSTALLATION_ID with a non-loopback RER_MANAGEMENT_ORIGIN. Remove those bindings from local settings or use rer dev --login.'));
|
|
45
|
+
return new URL(request.url).pathname === '/auth/dev/enter' || new URL(request.url).pathname === '/__dev/personas' ? rejectedResponse(request, devNotFound()) : worker.fetch(request, original, execution);
|
|
45
46
|
}
|
|
46
47
|
const gate = devGate({ key: env.RER_DEV_KEY, origin: env.AUTH_ORIGIN, local: env.AUTH_LOCAL === 'true' });
|
|
47
48
|
registerDevAdmission(gate ? r => gate.admits(r) : null);
|
|
48
49
|
const path = new URL(request.url).pathname;
|
|
49
50
|
if (path === '/auth/dev/enter' || path === '/__dev/personas') {
|
|
50
|
-
if (!gate || env.RER_DEV_IDENTITY === 'off' || !await gate.admits(request)) return devNotFound();
|
|
51
|
+
if (!gate || env.RER_DEV_IDENTITY === 'off' || !await gate.admits(request)) return rejectedResponse(request, devNotFound());
|
|
51
52
|
const context = identity(env, authConfig, declared);
|
|
52
53
|
try {
|
|
53
|
-
|
|
54
|
+
const response = path === '/__dev/personas' ? Response.json(await context.list(), { headers }) : await enter(request, gate, context);
|
|
55
|
+
return rejectedResponse(request, response);
|
|
54
56
|
} catch (error) {
|
|
55
|
-
if (error instanceof AuthError) return Response.json({ error: error.code }, { status: error.status, headers });
|
|
57
|
+
if (error instanceof AuthError) return rejectedResponse(request, Response.json({ error: error.code }, { status: error.status, headers }));
|
|
56
58
|
throw error;
|
|
57
59
|
}
|
|
58
60
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from './rejected-response.mjs';
|
|
1
2
|
import { constantEqual } from './crypto.mjs';
|
|
2
3
|
import { isLoopbackHost, localCookieName } from './http.mjs';
|
|
3
4
|
|
|
@@ -76,7 +77,7 @@ export function devGate({ key, origin, local }) {
|
|
|
76
77
|
return new Response(request.method === 'HEAD' ? null : body, { headers: { ...privateHeaders, 'content-type': 'text/html; charset=utf-8',
|
|
77
78
|
'content-security-policy': `default-src 'none'; script-src ${script}; style-src ${style}; connect-src 'self'; base-uri 'none'; form-action 'none'; frame-ancestors 'none'` } });
|
|
78
79
|
}
|
|
79
|
-
if (request.method !== 'POST' || request.headers.get('sec-fetch-site') === 'cross-site' || !request.headers.get('content-type')?.startsWith('application/json')) return devNotFound();
|
|
80
|
+
if (request.method !== 'POST' || request.headers.get('sec-fetch-site') === 'cross-site' || !request.headers.get('content-type')?.startsWith('application/json')) return rejectedResponse(request, devNotFound());
|
|
80
81
|
const text = await request.text();
|
|
81
82
|
let presented; try { presented = text.length <= 1024 ? JSON.parse(text)?.key : undefined; } catch {}
|
|
82
83
|
if (typeof presented !== 'string' || !constantEqual(presented, key)) return devNotFound();
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from '../../rejected-response.mjs';
|
|
1
2
|
// Server-only entry. Never include this module or its configuration in a browser bundle.
|
|
2
3
|
// OpenID Connect sign-in for several pinned providers at once. Each provider
|
|
3
4
|
// has its own start and callback route; its output is a verified principal,
|
|
@@ -279,7 +280,7 @@ export function createOidcProviders({ admission, db, config: input, clientIp, fe
|
|
|
279
280
|
|
|
280
281
|
// Exact routes only: /auth/oidc/<id>/start and /auth/oidc/<id>/callback.
|
|
281
282
|
export function createOidcHandler(oidc, { signInPath = oidc.signInPath ?? '/signin' } = {}) {
|
|
282
|
-
|
|
283
|
+
const handle = async request => {
|
|
283
284
|
const path = new URL(request.url).pathname;
|
|
284
285
|
const callbackId = oidc.callbackPaths?.[path];
|
|
285
286
|
if (callbackId) return oidc.callback(request, callbackId);
|
|
@@ -303,4 +304,8 @@ export function createOidcHandler(oidc, { signInPath = oidc.signInPath ?? '/sign
|
|
|
303
304
|
return oidc.begin(request, match[1], { returnTo: input.returnTo });
|
|
304
305
|
} catch (e) { return errorResponse(e instanceof OidcError ? e : new OidcError('oidc_invalid_input'), { signInPath }, request); }
|
|
305
306
|
};
|
|
307
|
+
return async request => {
|
|
308
|
+
const response = await handle(request);
|
|
309
|
+
return response ? rejectedResponse(request, response) : response;
|
|
310
|
+
};
|
|
306
311
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const maximumDiscardBytes = 64 * 1024
|
|
2
|
+
const maximumDiscardMs = 2000
|
|
3
|
+
|
|
4
|
+
function limitedResponse(response, message, status) {
|
|
5
|
+
const headers = new Headers(response.headers)
|
|
6
|
+
// Keep privacy/security policy, but never issue credentials or a redirect
|
|
7
|
+
// when the upload itself was refused.
|
|
8
|
+
for (const name of ['set-cookie', 'location', 'content-length', 'content-encoding']) headers.delete(name)
|
|
9
|
+
headers.set('content-type', 'text/plain; charset=utf-8')
|
|
10
|
+
void response.body?.cancel().catch(() => {})
|
|
11
|
+
return new Response(message, { status, headers })
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Finish a rejected upload before returning its response. This preserves the
|
|
16
|
+
* intended status through workerd's upload proxy without buffering input.
|
|
17
|
+
* Oversized or stalled uploads receive explicit 413/408 responses instead.
|
|
18
|
+
*/
|
|
19
|
+
export async function rejectedResponse(request, response) {
|
|
20
|
+
if (!request.body || request.bodyUsed || request.body.locked) return response
|
|
21
|
+
const reader = request.body.getReader()
|
|
22
|
+
let bytes = 0
|
|
23
|
+
let timer
|
|
24
|
+
const deadline = new Promise(resolve => {
|
|
25
|
+
timer = setTimeout(() => resolve('timeout'), maximumDiscardMs)
|
|
26
|
+
})
|
|
27
|
+
try {
|
|
28
|
+
for (;;) {
|
|
29
|
+
const result = await Promise.race([reader.read(), deadline])
|
|
30
|
+
if (result === 'timeout') {
|
|
31
|
+
void reader.cancel('Rejected upload exceeded time limit').catch(() => {})
|
|
32
|
+
return limitedResponse(response, 'Request body timeout', 408)
|
|
33
|
+
}
|
|
34
|
+
if (result.done) return response
|
|
35
|
+
bytes += result.value.byteLength
|
|
36
|
+
if (bytes > maximumDiscardBytes) {
|
|
37
|
+
void reader.cancel('Rejected upload exceeded size limit').catch(() => {})
|
|
38
|
+
return limitedResponse(response, 'Request body too large', 413)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
} finally {
|
|
42
|
+
clearTimeout(timer)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { rejectedResponse } from './rejected-response.mjs';
|
|
1
2
|
import { identitySettingsPage } from './accounts/settings-page.mjs';
|
|
2
3
|
import { confirmationResponse } from './identity/email-link/confirmation.mjs';
|
|
3
4
|
import { createOidcHandler } from './identity/oidc/index.mjs';
|
|
@@ -20,7 +21,7 @@ function notice(auth, code, extra = {}) {
|
|
|
20
21
|
/** Fetch-compatible optional HTTP adapter. Returns null for paths it does not own. */
|
|
21
22
|
export function createAuthHandler(auth) {
|
|
22
23
|
const oidc = auth.providers ? createOidcHandler(auth.providers, { signInPath: auth.presentation.signInPath }) : null;
|
|
23
|
-
|
|
24
|
+
const handleAuth = async function(request) {
|
|
24
25
|
const url = new URL(request.url);
|
|
25
26
|
const path = url.pathname;
|
|
26
27
|
let form = false;
|
|
@@ -88,4 +89,8 @@ export function createAuthHandler(auth) {
|
|
|
88
89
|
return json({ error: 'auth_unavailable' }, 503);
|
|
89
90
|
}
|
|
90
91
|
};
|
|
92
|
+
return async function(request) {
|
|
93
|
+
const response = await handleAuth(request);
|
|
94
|
+
return response ? rejectedResponse(request, response) : response;
|
|
95
|
+
};
|
|
91
96
|
}
|