@runeditrun/rer 0.2.9 → 0.2.10
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/bounded.mjs +1 -1
- package/global/CHANGELOG.md +8 -0
- package/modules/job-queue/load-admission.mjs +38 -0
- package/modules/operator-auth/README.md +4 -1
- package/modules/operator-auth/identity/email-link/index.mjs +6 -2
- package/modules/owner-claim/README.md +8 -6
- package/modules/owner-claim/transaction.mjs +4 -4
- package/onboarding/commands.mjs +2 -1
- package/onboarding/queue.mjs +8 -1
- package/onboarding/queued-entry.mjs +1 -1
- package/package.json +1 -1
package/cli/bounded.mjs
CHANGED
|
@@ -24,7 +24,7 @@ export async function boundedCommand(project,options,argv,out){
|
|
|
24
24
|
const {createCommands}=await shared('commands.mjs');
|
|
25
25
|
store=await createCommands(directory,{logs:[]},{terminal:()=>{}});
|
|
26
26
|
result=await queuedCommand(process.execPath,[fileURLToPath(new URL('../bin/rer.mjs',import.meta.url)),...childArgs],{
|
|
27
|
-
cwd:project.root,signal:cancellation.signal,stdio:[!options.json&&!options.nonInteractive?'inherit':'ignore','pipe','pipe'],originalCI:policy.ci,env:{...process.env,...policy.environment,RER_BOUNDED_OUTPUT:'1'},
|
|
27
|
+
cwd:project.root,verb:options.verb,signal:cancellation.signal,stdio:[!options.json&&!options.nonInteractive?'inherit':'ignore','pipe','pipe'],originalCI:policy.ci,env:{...process.env,...policy.environment,RER_BOUNDED_OUTPUT:'1'},
|
|
28
28
|
label:await queueLabel(project.root,options.verb,'workflow'),report:text=>out.progress(store.redact(text)+'\n'),onWaiting:options.json?details=>out.event('waiting',details):undefined,
|
|
29
29
|
spawn:(command,args,native)=>{
|
|
30
30
|
const child=store.spawn('Running bounded workflow',command,args,native);
|
package/global/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.10
|
|
4
|
+
|
|
5
|
+
- 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.
|
|
6
|
+
|
|
7
|
+
### Upgrade notes
|
|
8
|
+
|
|
9
|
+
- Seeds receive this auth runtime fix with their next Base refresh. Updating the rer package alone does not replace seed-owned runtime copies.
|
|
10
|
+
|
|
3
11
|
## 0.2.9
|
|
4
12
|
|
|
5
13
|
- `rer deploy --remove --yes` empties each R2 bucket whose saved creation identity proves rer owns it, deletes the bucket, and verifies removal. Buckets with uncertain or replaced ownership are refused; interrupted deletion retains the deployment record so removal can resume.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { loadavg } from 'node:os';
|
|
2
|
+
import { setTimeout as delay } from 'node:timers/promises';
|
|
3
|
+
import { configuration } from './config.mjs';
|
|
4
|
+
import { signalExit } from './command.mjs';
|
|
5
|
+
|
|
6
|
+
// CI and descendants sharing a live lease need no second queue slot, but each
|
|
7
|
+
// verification command still waits for load before starting its own deadlines.
|
|
8
|
+
// Once admitted, a running command is never suspended or polled here.
|
|
9
|
+
export async function waitForLoad({ signal, onWaiting, report } = {}) {
|
|
10
|
+
const controller = new AbortController();
|
|
11
|
+
const interrupt = () => controller.abort('SIGINT'), terminate = () => controller.abort('SIGTERM');
|
|
12
|
+
const external = () => controller.abort(signal.reason === 'SIGINT' ? 'SIGINT' : 'SIGTERM');
|
|
13
|
+
process.on('SIGINT', interrupt); process.on('SIGTERM', terminate);
|
|
14
|
+
signal?.addEventListener('abort', external, { once: true });
|
|
15
|
+
if (signal?.aborted) external();
|
|
16
|
+
try {
|
|
17
|
+
const config = await configuration();
|
|
18
|
+
let reportedAt;
|
|
19
|
+
while (!controller.signal.aborted) {
|
|
20
|
+
const load = loadavg()[0];
|
|
21
|
+
if (Number.isFinite(load) && load <= config.loadThreshold) return null;
|
|
22
|
+
if (reportedAt === undefined || Date.now() - reportedAt >= 15_000) {
|
|
23
|
+
const reason = Number.isFinite(load)
|
|
24
|
+
? `the 1-minute load is ${load.toFixed(1)} and verification commands start at ${config.loadThreshold} or below (change with RER_JOBS_LOAD_THRESHOLD)`
|
|
25
|
+
: 'this computer\'s load could not be read';
|
|
26
|
+
const detail = { reason, reasonCodes: [Number.isFinite(load) ? 'load' : 'resources_unavailable'], resources: { load }, limits: { loadThreshold: config.loadThreshold } };
|
|
27
|
+
if (onWaiting) await onWaiting(detail);
|
|
28
|
+
else report?.(`Waiting to start verification command: ${reason}. Running commands finish uninterrupted.`);
|
|
29
|
+
reportedAt = Date.now();
|
|
30
|
+
}
|
|
31
|
+
await delay(config.pollMs, undefined, { signal: controller.signal }).catch(error => { if (error.name !== 'AbortError') throw error; });
|
|
32
|
+
}
|
|
33
|
+
return { code: signalExit(controller.signal.reason), signal: controller.signal.reason };
|
|
34
|
+
} finally {
|
|
35
|
+
process.off('SIGINT', interrupt); process.off('SIGTERM', terminate);
|
|
36
|
+
signal?.removeEventListener('abort', external);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -285,7 +285,10 @@ an invitation whose issuer still has authority.
|
|
|
285
285
|
Durable fixed-window limits pair the client-IP resolver with a normalized email;
|
|
286
286
|
defaults are 30 per IP and 5 per email per 15 minutes. `limitWindowSeconds`,
|
|
287
287
|
`ipLimit` and `emailLimit` configure those defaults. Bootstrap, magic link,
|
|
288
|
-
invitation, confirmation and review use separate scopes.
|
|
288
|
+
invitation, confirmation and review use separate scopes. Bootstrap uses only
|
|
289
|
+
the client-IP budget: its configured owner email is shared by every caller,
|
|
290
|
+
so wrong setup tokens from one client cannot exhaust another client's budget.
|
|
291
|
+
The same bootstrap policy applies to signed owner claims. Confirmation limits bind
|
|
289
292
|
the presented opaque token instead of the address. `clientIp` is mandatory;
|
|
290
293
|
unavailable addresses fail closed (503). Header trust belongs to the deployment
|
|
291
294
|
boundary. Do not trust X-Forwarded-For.
|
|
@@ -24,10 +24,14 @@ export function createEmailLinkLifecycle({ config: input, clock = Date.now, mail
|
|
|
24
24
|
if ((scope === 'magic' || scope === 'bootstrap') && await isLocalCli(request, config)) return;
|
|
25
25
|
const ip = await clientIp(request);
|
|
26
26
|
if (typeof ip !== 'string' || !ip || ip.length > 128) deny('client_ip_unavailable', 503);
|
|
27
|
-
|
|
27
|
+
// Bootstrap's email is the configured owner, shared by every caller. An
|
|
28
|
+
// unauthenticated caller must not spend another client's setup budget.
|
|
29
|
+
const subjects = [`${scope}:ip:${ip}`];
|
|
30
|
+
if (scope !== 'bootstrap') subjects.push(`${scope}:email:${email}`);
|
|
31
|
+
const keys = await Promise.all(subjects.map(subject => hash('rate', subject)));
|
|
28
32
|
const counts = await store.limits(keys, clock(), config.limitWindowSeconds * 1000);
|
|
29
33
|
if (!Array.isArray(counts) || counts.length !== keys.length || counts.some(value => !Number.isSafeInteger(value) || value < 0)) deny('invalid_proof_persistence', 503);
|
|
30
|
-
if (counts[0] > config.ipLimit || counts[1] > config.emailLimit) deny('rate_limited', 429);
|
|
34
|
+
if (counts[0] > config.ipLimit || (scope !== 'bootstrap' && counts[1] > config.emailLimit)) deny('rate_limited', 429);
|
|
31
35
|
}
|
|
32
36
|
async function newToken(kind, returnTo) {
|
|
33
37
|
const token = opaqueToken();
|
|
@@ -109,12 +109,14 @@ COOP `same-origin` to these two cooperating screens.
|
|
|
109
109
|
|
|
110
110
|
## Atomic admission and checks
|
|
111
111
|
|
|
112
|
-
Operator-auth normally commits rate
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
112
|
+
Operator-auth normally commits its client-IP rate limit before bootstrap. This
|
|
113
|
+
budget is per client, so wrong setup tokens from another client cannot block a
|
|
114
|
+
valid signed claim. A request-local D1 adapter reads the actual existing counter
|
|
115
|
+
and projects the real UPSERT result without writing. It defers that unchanged
|
|
116
|
+
UPSERT until the real bootstrap's unchanged three-statement batch. One D1
|
|
117
|
+
transaction inserts the single-use claim, checks an empty auth store, runs the
|
|
118
|
+
original limit and bootstrap SQL, then checks owner/session identity and the
|
|
119
|
+
actual client-IP threshold before committing.
|
|
118
120
|
A SQL CHECK failure or racing claim rolls the entire batch back. No application
|
|
119
121
|
mock, substitute owner/session creation, in-memory lock or retry is involved.
|
|
120
122
|
The adapter accepts only that exact SQL protocol and never serves other auth APIs.
|
|
@@ -36,7 +36,7 @@ export function bootstrapTransaction(db, claim, config, clock) {
|
|
|
36
36
|
async batch(statements) {
|
|
37
37
|
if (committed || !Array.isArray(statements) || statements.some(s => !owned.has(s))) return drift();
|
|
38
38
|
if (!limits) {
|
|
39
|
-
if (statements.length !==
|
|
39
|
+
if (statements.length !== 1 || statements.some(s => normalize(s.sql) !== LIMIT || s.args.length !== 2)) return drift();
|
|
40
40
|
limits = statements;
|
|
41
41
|
// Read the exact counters which the real UPSERT will increment. Auth's
|
|
42
42
|
// configured limit check still runs; repeat it on actual transaction
|
|
@@ -61,9 +61,9 @@ export function bootstrapTransaction(db, claim, config, clock) {
|
|
|
61
61
|
EXISTS(SELECT 1 FROM oa_operators WHERE id=? AND email=? AND role='owner' AND status='active') AND
|
|
62
62
|
EXISTS(SELECT 1 FROM oa_sessions WHERE id=? AND operator_id=?) AND
|
|
63
63
|
${claim.identity ? `EXISTS(SELECT 1 FROM rer_dependency_link WHERE interface='oidc-provider@1' AND issuer=? AND client_id=? AND metadata=? AND needs_relink=0 AND linked_at=?) AND EXISTS(SELECT 1 FROM rer_dependency_installation WHERE singleton=1 AND sector_id=?) AND` : ''}
|
|
64
|
-
${pin.sql} AND (SELECT count FROM oa_limits WHERE key=?)<=?
|
|
64
|
+
${pin.sql} AND (SELECT count FROM oa_limits WHERE key=?)<=?
|
|
65
65
|
THEN 1 ELSE 2 END WHERE jti=?`).bind(owner, owner, claim.email, session, owner,
|
|
66
|
-
...(claim.identity?[claim.identity.issuer,claim.identity.clientId,claim.identity.metadata,claim.identity.linkedAt,claim.installationId]:[]), ...pin.args, limits[0].args[0], config.ipLimit,
|
|
66
|
+
...(claim.identity?[claim.identity.issuer,claim.identity.clientId,claim.identity.metadata,claim.identity.linkedAt,claim.installationId]:[]), ...pin.args, limits[0].args[0], config.ipLimit, claim.jti);
|
|
67
67
|
try {
|
|
68
68
|
const identity = claim.identity ? [
|
|
69
69
|
db.prepare('INSERT INTO oc_idp_grants(issuer,client_id,jti,subject,sector_id) VALUES(?,?,?,?,?)').bind(claim.identity.issuer,claim.identity.clientId,claim.jti,claim.identity.subject,claim.installationId),
|
|
@@ -76,7 +76,7 @@ export function bootstrapTransaction(db, claim, config, clock) {
|
|
|
76
76
|
] : [];
|
|
77
77
|
const results = await db.batch([start, ...[...limits, ...statements].map(s => db.prepare(s.sql).bind(...s.args)), ...identity, finish]);
|
|
78
78
|
committed = true;
|
|
79
|
-
return results.slice(
|
|
79
|
+
return results.slice(1 + limits.length, 1 + limits.length + statements.length);
|
|
80
80
|
} catch {
|
|
81
81
|
// Includes unique/empty-store fences and final CHECK failure. D1 has
|
|
82
82
|
// rolled the whole batch back, including every original limit UPSERT.
|
package/onboarding/commands.mjs
CHANGED
|
@@ -141,7 +141,8 @@ export async function createCommands(directory,state,{terminal=text=>writeSync(1
|
|
|
141
141
|
async run(label,command,args=[],options={}) {
|
|
142
142
|
if(queuePolicy && options.heavy !== false) {
|
|
143
143
|
let queuedChild;
|
|
144
|
-
const
|
|
144
|
+
const commandSignal=signal&&options.signal?AbortSignal.any([signal,options.signal]):options.signal||signal;
|
|
145
|
+
const result = await queuedCommand(command,args,{...options,verb:queuePolicy.verb,signal:commandSignal,originalCI:policy.ci,
|
|
145
146
|
label:await queueLabel(options.cwd??process.cwd(),queuePolicy.verb,options.phase??'command'),report,onWaiting,
|
|
146
147
|
spawn:(program,argv,native)=>(queuedChild=spawnCommand(label,program,argv,{...native,onChild:options.onChild})),cleanup:async(child,result)=>{await stopCommand(child);await options.afterCommand?.(result);}});
|
|
147
148
|
if(result){if(result.code!==0)throw failure(label,result,captures.get(queuedChild));return result;}
|
package/onboarding/queue.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import { readFile, realpath } from 'node:fs/promises';
|
|
|
5
5
|
const portable = basename(dirname(fileURLToPath(import.meta.url))) === 'base-onboarding';
|
|
6
6
|
const queueURL = new URL(portable ? '../base-cli/modules/job-queue/' : '../modules/job-queue/', import.meta.url);
|
|
7
7
|
export const heavyVerbs = new Set(['install', 'setup', 'build', 'verify', 'dev', 'preview', 'deploy', 'release', 'export', 'import', 'installer']);
|
|
8
|
+
export const verificationBoundary = verb => verb === 'release' || verb === 'verify' || verb?.startsWith('verify:');
|
|
8
9
|
export async function queueLabel(root, verb, phase) {
|
|
9
10
|
root = await realpath(root);
|
|
10
11
|
let project='project';
|
|
@@ -35,7 +36,13 @@ export async function queuedCommand(command, args, options) {
|
|
|
35
36
|
// Keep the human recipe relative while retaining the executable argv for tools.
|
|
36
37
|
const statusCommandText = [basename(process.execPath), relative(options.cwd ?? process.cwd(), statusCommand[1]), ...statusCommand.slice(2)].map(shellQuote).join(' ');
|
|
37
38
|
// Read the original caller's decision before an install synthesizes CI=true.
|
|
38
|
-
if (options.originalCI === true || await liveMembership())
|
|
39
|
+
if (options.originalCI === true || await liveMembership()) {
|
|
40
|
+
if (verificationBoundary(options.verb)) {
|
|
41
|
+
const { waitForLoad } = await import(new URL('load-admission.mjs', queueURL));
|
|
42
|
+
return waitForLoad(options);
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
39
46
|
const queue = await createQueue();
|
|
40
47
|
try {
|
|
41
48
|
const result = await queue.run([command, ...args], { ...options, kind: 'heavy', maxWait: 1200,
|
|
@@ -16,7 +16,7 @@ export async function queuedEntrypoint(url,verb='verify') {
|
|
|
16
16
|
const policy=await commandPolicy();
|
|
17
17
|
try{
|
|
18
18
|
const result=await queuedCommand(process.execPath,[...process.execArgv,fileURLToPath(url),...process.argv.slice(2)],{
|
|
19
|
-
cwd:process.cwd(),originalCI:policy.ci,label:await queueLabel(process.cwd(),verb,'suite'),report:text=>store.report(text),env:{...process.env,...policy.environment},
|
|
19
|
+
cwd:process.cwd(),verb,originalCI:policy.ci,label:await queueLabel(process.cwd(),verb,'suite'),report:text=>store.report(text),env:{...process.env,...policy.environment},
|
|
20
20
|
spawn:(command,args,options)=>store.spawn(verb,command,args,options),cleanup:child=>store.stop(child)});
|
|
21
21
|
return result?.code??null;
|
|
22
22
|
}finally{await policy.close();}
|