@zabaca/zbc 0.16.4 → 0.18.0
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/package.json +1 -1
- package/templates/apps/walgit/CONTEXT.md +31 -1
- package/templates/apps/walgit/README.md +48 -1
- package/templates/apps/walgit/e2e/README.md +44 -0
- package/templates/apps/walgit/e2e/load-report.ts +240 -0
- package/templates/apps/walgit/e2e/load.ts +449 -0
- package/templates/apps/walgit/package.json +2 -1
- package/templates/apps/walgit/shared/capabilities.ts +74 -0
- package/templates/apps/walgit/shared/container-env.ts +12 -0
- package/templates/apps/walgit/shared/events.ts +57 -8
- package/templates/apps/walgit/shared/landing.ts +169 -9
- package/templates/apps/walgit/shared/llms.ts +140 -6
- package/templates/apps/walgit/shared/operator.ts +86 -0
- package/templates/apps/walgit/shared/policy.ts +25 -0
- package/templates/apps/walgit/shared/protocol.ts +38 -0
- package/templates/apps/walgit/src/announce-main.ts +10 -2
- package/templates/apps/walgit/src/announce.ts +8 -1
- package/templates/apps/walgit/src/git-backend.ts +12 -0
- package/templates/apps/walgit/src/hook-main.ts +112 -4
- package/templates/apps/walgit/src/http.ts +202 -1
- package/templates/apps/walgit/src/instructions.ts +17 -1
- package/templates/apps/walgit/src/proposals.ts +360 -0
- package/templates/apps/walgit/src/push.ts +21 -1
- package/templates/apps/walgit/src/rate-limit.ts +264 -0
- package/templates/apps/walgit/src/server.ts +36 -0
- package/templates/apps/walgit/src/signers.ts +72 -0
- package/templates/apps/walgit/worker/index.ts +29 -2
|
@@ -17,6 +17,8 @@ import { ensureBareRepo } from './cache'
|
|
|
17
17
|
import { configuredExpiryMs, expireRepos } from './expire'
|
|
18
18
|
import { createHttpHandler } from './http'
|
|
19
19
|
import { privateReposConfigError, privateReposEnabled, privateReposSeed } from './private'
|
|
20
|
+
import { gitAncestry, isProposalRef, listProposals } from './proposals'
|
|
21
|
+
import { resolveRepo } from './repo'
|
|
20
22
|
import { sshReadVerifier } from './ssh-signature'
|
|
21
23
|
import { runGitHttpBackend } from './git-backend'
|
|
22
24
|
import type { ObjectStore } from './store'
|
|
@@ -147,6 +149,11 @@ console.log(
|
|
|
147
149
|
`retentionHours=${caps.retentionHours ?? 'off'} ` +
|
|
148
150
|
`maxPush=${caps.maxPushBytes ?? 'unset'} maxRepo=${caps.maxRepoBytes ?? 'unset'} ` +
|
|
149
151
|
`private=${caps.namesCanBePrivate} ` +
|
|
152
|
+
`perSource=${
|
|
153
|
+
caps.sourceLimited
|
|
154
|
+
? `${caps.maxNewReposPerSource ?? '-'} repos/${caps.maxPushesPerSource ?? '-'} pushes/${caps.maxPushBytesPerSource ?? '-'} bytes per ${caps.rateWindowSeconds}s`
|
|
155
|
+
: 'off'
|
|
156
|
+
} ` +
|
|
150
157
|
`store=${store ? 'configured' : 'MISSING'}`,
|
|
151
158
|
)
|
|
152
159
|
|
|
@@ -205,6 +212,35 @@ try {
|
|
|
205
212
|
return { provenance: index.provenance ?? {}, claim: index.claim }
|
|
206
213
|
}
|
|
207
214
|
: undefined,
|
|
215
|
+
// What Proposals a repository holds, with `merged` derived (docs/adr/0018).
|
|
216
|
+
//
|
|
217
|
+
// Three reads, and each is from the only place that can answer it: the refs
|
|
218
|
+
// and the provenance from the INDEX, because that is the source of truth
|
|
219
|
+
// and a node's disk is a cache; ancestry from the CACHE, because the Index
|
|
220
|
+
// holds no commits. Which is why the sync happens here rather than being
|
|
221
|
+
// skipped as it is for the other JSON reads — a cold container has the refs
|
|
222
|
+
// and none of the objects, and `merge-base` on a commit this disk has never
|
|
223
|
+
// seen reads as "not merged", which is a wrong answer rather than a slow
|
|
224
|
+
// one. `syncRepo` Materializes when reconcile reports objects missing.
|
|
225
|
+
//
|
|
226
|
+
// Absent without a store for the reason `readProvenance` is: the endpoint
|
|
227
|
+
// should not exist where there is nothing authoritative behind it. Whether
|
|
228
|
+
// the deployment OFFERS Proposals at all is the handler's check, against the
|
|
229
|
+
// capability this same process advertises.
|
|
230
|
+
readProposals: store
|
|
231
|
+
? async (repoId) => {
|
|
232
|
+
const { index } = await loadIndex(store, repoId)
|
|
233
|
+
// Nothing to walk, and nothing touched. A read must not bring a name
|
|
234
|
+
// into existence — pushing is what does that — so a repository with
|
|
235
|
+
// no Proposal ref is answered from the Index alone, without
|
|
236
|
+
// `ensureBareRepo` creating a directory for whatever name was asked
|
|
237
|
+
// about. It is also the common case: most repositories hold none.
|
|
238
|
+
if (!Object.keys(index.refs).some(isProposalRef)) return []
|
|
239
|
+
const repo = ensureBareRepo(resolveRepo(reposDir, repoId))
|
|
240
|
+
await syncRepo(store, repo)
|
|
241
|
+
return listProposals(index.refs, index.provenance ?? {}, gitAncestry(repo.dir))
|
|
242
|
+
}
|
|
243
|
+
: undefined,
|
|
208
244
|
// Read gating, and only where all three halves exist (docs/adr/0013): the
|
|
209
245
|
// seed with the Signer List flag beside it, and a store to read the Reader
|
|
210
246
|
// List out of. Without a store the Index cannot be read at all, and a gate
|
|
@@ -50,6 +50,8 @@ import { flagEnabled } from '../shared/policy'
|
|
|
50
50
|
import { SIGNERS_REF, ZERO_OID } from '../shared/protocol'
|
|
51
51
|
import { suggestName } from './append-only'
|
|
52
52
|
import { git } from './git'
|
|
53
|
+
import { readAllowed } from './private'
|
|
54
|
+
import { isProposalRef } from './proposals'
|
|
53
55
|
import { certificatePresented, signedPushEnabled, type PushCertEnv } from './push-cert'
|
|
54
56
|
import type { RefChange } from './wal-index'
|
|
55
57
|
|
|
@@ -552,6 +554,68 @@ export type SignerGateVerdict = { ok: true } | { ok: false; kind: GateRefusal; m
|
|
|
552
554
|
*/
|
|
553
555
|
export type GateStage = 'pre-receive' | 'publish'
|
|
554
556
|
|
|
557
|
+
/**
|
|
558
|
+
* What the gate needs to know about Proposals, which is everything about them
|
|
559
|
+
* that is not already one of its three inputs (docs/adr/0018).
|
|
560
|
+
*
|
|
561
|
+
* The whole shape is passed rather than a precomputed "this push may propose",
|
|
562
|
+
* because the gate is asked TWICE — once before the upload and once at the
|
|
563
|
+
* compare-and-swap — and a boolean settled by each caller for itself is two
|
|
564
|
+
* places the rule lives. Both callers hold these three facts already: the flag
|
|
565
|
+
* from the environment, and the Reader List off the Claim they read the Signer
|
|
566
|
+
* List from.
|
|
567
|
+
*/
|
|
568
|
+
export interface ProposalGate {
|
|
569
|
+
/** `WALGIT_PROPOSALS` — off unless the deployment sets it. */
|
|
570
|
+
enabled: boolean
|
|
571
|
+
/** Is this deployment maintaining Reader Lists at all (`privateReposEnabled`)? */
|
|
572
|
+
privateRepos: boolean
|
|
573
|
+
/** The Reader List the Index holds, or `null` for a world-readable name. */
|
|
574
|
+
readers?: readonly string[] | null
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
/**
|
|
578
|
+
* May this push be let past the Signer List because every ref it writes is a
|
|
579
|
+
* Proposal, and its Signer may READ this repository?
|
|
580
|
+
*
|
|
581
|
+
* Three conditions, and each one is load-bearing:
|
|
582
|
+
*
|
|
583
|
+
* - **Every** ref, not some. git shows the hook a push's refs together and
|
|
584
|
+
* publishes them across several transactions, so a push allowed for its
|
|
585
|
+
* Proposal would land whatever branch was pushed beside it.
|
|
586
|
+
* - **Signed**, verified — never an unestablished Signer. A Proposal nobody
|
|
587
|
+
* can be attributed to is a permanent anonymous write to a name that
|
|
588
|
+
* refuses strangers, which is the whole of what ADR-0012 bought.
|
|
589
|
+
* - **Readable by them**, through `readAllowed` — the same function the clone
|
|
590
|
+
* and the Provenance Read are judged by, because "whoever may read may
|
|
591
|
+
* propose" is one rule and a second copy of it would be a second answer.
|
|
592
|
+
* On a world-readable name that is anyone who signed; on a Private one it
|
|
593
|
+
* is the Reader List and the Signers.
|
|
594
|
+
*
|
|
595
|
+
* The shape of the ref is deliberately not asked here — `checkProposalRefs`
|
|
596
|
+
* (`src/proposals.ts`) judges whether a Proposal is one the host will hold, and
|
|
597
|
+
* it runs in `pre-receive` beside this. Folding it in would give this pure
|
|
598
|
+
* function a git subprocess and an Index read.
|
|
599
|
+
*/
|
|
600
|
+
function mayPropose(
|
|
601
|
+
signer: PushSigner,
|
|
602
|
+
claimed: readonly string[],
|
|
603
|
+
changes: readonly RefChange[],
|
|
604
|
+
proposals: ProposalGate,
|
|
605
|
+
): boolean {
|
|
606
|
+
if (!proposals.enabled) return false
|
|
607
|
+
if (signer.kind !== 'signed') return false
|
|
608
|
+
if (changes.length === 0 || !changes.every((c) => isProposalRef(c.ref))) return false
|
|
609
|
+
return readAllowed({
|
|
610
|
+
enabled: proposals.privateRepos,
|
|
611
|
+
claim: {
|
|
612
|
+
signers: [...claimed],
|
|
613
|
+
...(proposals.readers ? { readers: [...proposals.readers] } : {}),
|
|
614
|
+
},
|
|
615
|
+
presented: signer.fingerprint,
|
|
616
|
+
})
|
|
617
|
+
}
|
|
618
|
+
|
|
555
619
|
/**
|
|
556
620
|
* May this push land, given who signed it and the list this name already holds?
|
|
557
621
|
*
|
|
@@ -585,6 +649,12 @@ export type GateStage = 'pre-receive' | 'publish'
|
|
|
585
649
|
* it. The rule for an operator is the short one: turn the flag on before anyone
|
|
586
650
|
* writes a list, and leave it on.
|
|
587
651
|
*
|
|
652
|
+
* **Proposals are the one widening** (docs/adr/0018), and they narrow nothing:
|
|
653
|
+
* a push whose refs are ALL under `refs/walgit/proposals/` is let through when
|
|
654
|
+
* its Signer may READ this repository — see `mayPropose` above. It is asked
|
|
655
|
+
* after the list has already refused, so a listed key's push is unaffected, and
|
|
656
|
+
* it is off entirely unless the deployment sets the flag.
|
|
657
|
+
*
|
|
588
658
|
* An unclaimed name is `null`. An empty array is read as unclaimed too, and the
|
|
589
659
|
* asymmetry with `checkSignerList` — which refuses writing one — is the point:
|
|
590
660
|
* a list naming nobody cannot be written, so reaching one here means the Index
|
|
@@ -598,9 +668,11 @@ export function checkSignerAllowed(
|
|
|
598
668
|
claimed: readonly string[] | null,
|
|
599
669
|
changes: readonly RefChange[],
|
|
600
670
|
stage: GateStage = 'pre-receive',
|
|
671
|
+
proposals: ProposalGate = { enabled: false, privateRepos: false, readers: null },
|
|
601
672
|
): SignerGateVerdict {
|
|
602
673
|
if (claimed === null || claimed.length === 0) return { ok: true }
|
|
603
674
|
if (signer.kind === 'signed' && claimed.includes(signer.fingerprint)) return { ok: true }
|
|
675
|
+
if (mayPropose(signer, claimed, changes, proposals)) return { ok: true }
|
|
604
676
|
return {
|
|
605
677
|
ok: false,
|
|
606
678
|
kind: signer.kind === 'signed' ? 'not-listed' : signer.kind,
|
|
@@ -33,6 +33,7 @@ import { parseTokens } from '../shared/credentials'
|
|
|
33
33
|
import { authorizeAnnounce, authorizeSubscribe } from '../shared/events'
|
|
34
34
|
import { renderLanding, wantsLanding } from '../shared/landing'
|
|
35
35
|
import { renderLlms, wantsLlms } from '../shared/llms'
|
|
36
|
+
import { operatorFrom } from '../shared/operator'
|
|
36
37
|
import { renderRobots, wantsRobots } from '../shared/robots'
|
|
37
38
|
import {
|
|
38
39
|
ANNOUNCE_PATH,
|
|
@@ -75,6 +76,16 @@ export interface Env {
|
|
|
75
76
|
WALGIT_RETENTION_HOURS?: string
|
|
76
77
|
WALGIT_MAX_PUSH_BYTES?: string
|
|
77
78
|
WALGIT_MAX_REPO_BYTES?: string
|
|
79
|
+
/**
|
|
80
|
+
* What one source may spend in a window (src/rate-limit.ts). All off unless
|
|
81
|
+
* set; the window defaults when a count is set without one. Forwarded to the
|
|
82
|
+
* container, which is where the verdict is reached — this side only states
|
|
83
|
+
* them on the two documents below.
|
|
84
|
+
*/
|
|
85
|
+
WALGIT_RATE_WINDOW_SECONDS?: string
|
|
86
|
+
WALGIT_MAX_NEW_REPOS_PER_SOURCE?: string
|
|
87
|
+
WALGIT_MAX_PUSHES_PER_SOURCE?: string
|
|
88
|
+
WALGIT_MAX_PUSH_BYTES_PER_SOURCE?: string
|
|
78
89
|
/**
|
|
79
90
|
* Where request-level telemetry goes — the half of observability the log
|
|
80
91
|
* cannot produce (shared/telemetry.ts). Optional: a deployment without the
|
|
@@ -117,6 +128,18 @@ export interface Env {
|
|
|
117
128
|
* default, and a secret.
|
|
118
129
|
*/
|
|
119
130
|
WALGIT_PRIVATE_REPOS?: string
|
|
131
|
+
/**
|
|
132
|
+
* Who runs this deployment, and where to write about it
|
|
133
|
+
* (`shared/operator.ts`). Read ONLY through `operatorFrom`, like the policy
|
|
134
|
+
* above is read only through `capabilitiesFrom`.
|
|
135
|
+
*
|
|
136
|
+
* Deliberately absent from `CONTAINER_ENV`: nothing the container serves
|
|
137
|
+
* names an operator, and a name there would cost a container restart on
|
|
138
|
+
* every copy edit. Unset means the two edge documents carry no operator
|
|
139
|
+
* block at all, rather than a placeholder nobody reads.
|
|
140
|
+
*/
|
|
141
|
+
WALGIT_OPERATOR?: string
|
|
142
|
+
WALGIT_CONTACT?: string
|
|
120
143
|
WALGIT_EVENTS: DurableObjectNamespace<WalgitEvents>
|
|
121
144
|
}
|
|
122
145
|
|
|
@@ -252,6 +275,10 @@ export default {
|
|
|
252
275
|
// and the socket cannot describe three different deployments — they used
|
|
253
276
|
// to read the environment three times, and only the size caps were shared.
|
|
254
277
|
const caps = capabilitiesFrom(env)
|
|
278
|
+
// Who is answerable for this deployment (`shared/operator.ts`). Derived
|
|
279
|
+
// beside the capabilities and passed to both documents, so the page and
|
|
280
|
+
// the manual cannot name two different operators.
|
|
281
|
+
const operator = operatorFrom(env)
|
|
255
282
|
|
|
256
283
|
// The browser half of `/`, answered at the edge (shared/landing.ts). Placed
|
|
257
284
|
// before every other decision on purpose: a link on an aggregator points at
|
|
@@ -264,7 +291,7 @@ export default {
|
|
|
264
291
|
// them: this document and `/llms.txt` want a bare hostname they prefix
|
|
265
292
|
// with `https://`/`wss://` themselves, while `GET /` needs a full origin
|
|
266
293
|
// including the scheme, and one field could not serve both.
|
|
267
|
-
const page = renderLanding(url.host, caps)
|
|
294
|
+
const page = renderLanding(url.host, caps, operator)
|
|
268
295
|
const bytes = new TextEncoder().encode(page)
|
|
269
296
|
record(env, ctx, {
|
|
270
297
|
kind: 'landing',
|
|
@@ -305,7 +332,7 @@ export default {
|
|
|
305
332
|
// `/llms.txt` is not reachable as a repo route even for a repository called
|
|
306
333
|
// `llms.txt`.
|
|
307
334
|
if (wantsLlms(request.method, url.pathname)) {
|
|
308
|
-
const doc = renderLlms(url.host, caps)
|
|
335
|
+
const doc = renderLlms(url.host, caps, operator)
|
|
309
336
|
const bytes = new TextEncoder().encode(doc)
|
|
310
337
|
record(env, ctx, {
|
|
311
338
|
kind: 'landing',
|