@zabaca/zbc 0.16.4 → 0.17.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 +27 -1
- package/templates/apps/walgit/shared/capabilities.ts +22 -0
- package/templates/apps/walgit/shared/container-env.ts +4 -0
- package/templates/apps/walgit/shared/events.ts +57 -8
- package/templates/apps/walgit/shared/landing.ts +38 -6
- package/templates/apps/walgit/shared/llms.ts +66 -1
- package/templates/apps/walgit/shared/protocol.ts +23 -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/hook-main.ts +93 -4
- package/templates/apps/walgit/src/http.ts +72 -0
- package/templates/apps/walgit/src/proposals.ts +360 -0
- package/templates/apps/walgit/src/push.ts +21 -1
- package/templates/apps/walgit/src/server.ts +31 -0
- package/templates/apps/walgit/src/signers.ts +72 -0
package/package.json
CHANGED
|
@@ -67,7 +67,7 @@ first push to a name printed `fatal:` before succeeding — which an agent reads
|
|
|
67
67
|
## Ref events (ADR-0009)
|
|
68
68
|
|
|
69
69
|
**Ref Event**:
|
|
70
|
-
A message telling a subscriber that a watched ref is now at a given sha. Latest-state, never a replayed history: there is no cursor, no `since`, and no sequence number on the wire. A deletion is the same message with a null sha.
|
|
70
|
+
A message telling a subscriber that a watched ref is now at a given sha. Latest-state, never a replayed history: there is no cursor, no `since`, and no sequence number on the wire. A deletion is the same message with a null sha. When the ref is a branch and the move landed Proposals, it also carries `merged` — their ids — so a Watcher on `main` learns a Proposal landed without a second call; the field is absent, never empty, when it landed none, and a Handshake never carries it, because nothing moved. That is not a second kind of state: it is a property of the move, computed in `post-receive` by the same ancestry walk the Proposal read surface uses, and a subscriber that was disconnected reads what is open from `GET /<name>.git/proposals` instead.
|
|
71
71
|
_Avoid_: notification (implies delivery to an endpoint, which is exactly what this is not), webhook
|
|
72
72
|
|
|
73
73
|
**Watch**:
|
|
@@ -163,3 +163,29 @@ _Disambiguate_: `WALGIT_PUBLIC` is deployment-wide and about tokens; Private is
|
|
|
163
163
|
**Read Challenge**:
|
|
164
164
|
How a reader proves a key over smart-HTTP, where git signs nothing on fetch. The host publishes a nonce; the client signs it with the same key that signs its pushes and presents the signature as its credential; the host verifies it with the same verifier a Push Certificate gets and looks the fingerprint up in the Reader List. Signed under its own namespace so a Read Challenge can never be replayed as a Push Certificate or an SSH login. Every read a Private repository has — clone, fetch, the Provenance Read, a Watch on the event stream — is behind this one gate and no other.
|
|
165
165
|
_Avoid_: login, token (there is none; the signature is the credential), auth
|
|
166
|
+
|
|
167
|
+
## Proposals (ADR-0018)
|
|
168
|
+
|
|
169
|
+
**Proposal**:
|
|
170
|
+
A ref under `refs/walgit/proposals/` that names a commit its pusher wants in a target ref. It is a ref and a Push Certificate and nothing else: the host keeps no record of it beyond the Index, requests nothing of anyone, and derives its state from git ancestry rather than storing one. The ref reads `refs/walgit/proposals/<target>/<id>`, where the **last segment is the id** and everything before it is the target branch — so a target may itself contain slashes (`feat/login`) and nothing has to be fetched to know what a Proposal is for. `pre-receive` refuses one whose target does not exist, whose target is not a branch (a segment beginning `refs/`, which is what stops anyone proposing a Signer List), or whose tip is not a commit: append-only means a ref written here is written for good, so junk is refused before it is stored or never. Deployment-wide and off by default (`WALGIT_PROPOSALS`); with the flag off the namespace is an ordinary one under the ordinary gate.
|
|
171
|
+
_Avoid_: pull request (GitHub's, and already means a GitHub PR elsewhere in the repository), merge request, change request (an approval-board ticket), PR
|
|
172
|
+
|
|
173
|
+
**Merged**:
|
|
174
|
+
A Proposal whose tip is an ancestor of its target ref's tip. Computed on read, never recorded, so it is only ever true because someone with the right to write the target pushed a fast-forward or a true merge of the Proposal's tip. A squash or a rebase of it does not merge the Proposal, and a Proposal is never Merged by anything but ancestry.
|
|
175
|
+
_Avoid_: closed, accepted (nothing records an acceptance), landed
|
|
176
|
+
|
|
177
|
+
**Whoever may read may propose**:
|
|
178
|
+
The one rule for who can push a Proposal: on a world-readable name, anyone whose push is signed; on a Private name, its Signers and Readers. There is no third list. An Unclaimed name refuses nothing anyway, so a Proposal there is allowed and pointless.
|
|
179
|
+
|
|
180
|
+
**Proposal Read**:
|
|
181
|
+
`GET /<name>.git/proposals` — every Proposal a repository holds, as
|
|
182
|
+
`{ id, target, tip, pusher, merged }`. Derived on every read and stored nowhere:
|
|
183
|
+
the ids and targets from the ref names, the tips and the pusher fingerprints
|
|
184
|
+
from the Index, and **Merged** from `merge-base --is-ancestor` against the Cache,
|
|
185
|
+
which is synced (and Materialized, on a cold container) first because the Index
|
|
186
|
+
holds no commits to walk. Gated exactly as the Provenance Read is — the
|
|
187
|
+
deployment credential, then the Read Challenge on a Private name — and it does
|
|
188
|
+
not exist at all on a deployment that does not offer Proposals. *Superseded* is
|
|
189
|
+
deliberately not reported: ADR-0018 admits it only if the same walk yields it
|
|
190
|
+
free, and it does not.
|
|
191
|
+
_Avoid_: list endpoint, PR list, the proposals API
|
|
@@ -62,6 +62,7 @@ type CapabilityVar = Extract<
|
|
|
62
62
|
| 'WALGIT_PUSH_CERT_SEED'
|
|
63
63
|
| 'WALGIT_SIGNER_LISTS'
|
|
64
64
|
| 'WALGIT_PRIVATE_REPOS'
|
|
65
|
+
| 'WALGIT_PROPOSALS'
|
|
65
66
|
>
|
|
66
67
|
|
|
67
68
|
/**
|
|
@@ -155,6 +156,26 @@ export type Capabilities = {
|
|
|
155
156
|
* the `Credentialed` term already says: one credential reads every name.
|
|
156
157
|
*/
|
|
157
158
|
namesCanBePrivate: boolean
|
|
159
|
+
/**
|
|
160
|
+
* A claimed name takes a signed push to `refs/walgit/proposals/<target>/<id>`
|
|
161
|
+
* from whoever may READ it, while every other ref stays under the Signer List
|
|
162
|
+
* (docs/adr/0018).
|
|
163
|
+
*
|
|
164
|
+
* Everything `namesCanBeClaimed` needs, plus its own flag. Not the flag
|
|
165
|
+
* alone, for the reason Private is not its seed alone: a Proposal is a SIGNED
|
|
166
|
+
* push to a name that holds a Signer List, so with no nonce seed nothing can
|
|
167
|
+
* sign one, and on a deployment with no gate there is no refusal to widen —
|
|
168
|
+
* `refs/walgit/proposals/…` is already a ref namespace anyone may write to.
|
|
169
|
+
* A document rendered from the flag by itself would describe a handoff no
|
|
170
|
+
* push could make.
|
|
171
|
+
*
|
|
172
|
+
* `publicAccess` is deliberately NOT in it, where Private needs it: a
|
|
173
|
+
* Proposal is a push, and a push proves its key with the certificate inside
|
|
174
|
+
* the pack rather than with the one `authorization` header a deployment token
|
|
175
|
+
* occupies. A credentialed deployment can take Proposals from everyone it
|
|
176
|
+
* gave a token to.
|
|
177
|
+
*/
|
|
178
|
+
proposals: boolean
|
|
158
179
|
/** A repository is collected this many hours after its last push. */
|
|
159
180
|
retentionHours: number | null
|
|
160
181
|
/** Largest single push, in bytes. */
|
|
@@ -210,6 +231,7 @@ export function capabilitiesFrom(
|
|
|
210
231
|
signedPushes &&
|
|
211
232
|
publicAccess &&
|
|
212
233
|
seedValue(env.WALGIT_PRIVATE_REPOS) !== null,
|
|
234
|
+
proposals: namesCanRefuse && signedPushes && flagEnabled(env.WALGIT_PROPOSALS),
|
|
213
235
|
retentionHours: positiveNumber(env.WALGIT_RETENTION_HOURS),
|
|
214
236
|
maxPushBytes: positiveNumber(env.WALGIT_MAX_PUSH_BYTES),
|
|
215
237
|
maxRepoBytes: positiveNumber(env.WALGIT_MAX_REPO_BYTES),
|
|
@@ -60,6 +60,10 @@ export const CONTAINER_ENV = [
|
|
|
60
60
|
// container because the Reader List is read in `pre-receive` and every read
|
|
61
61
|
// will be verified here, where a subprocess exists.
|
|
62
62
|
'WALGIT_PRIVATE_REPOS',
|
|
63
|
+
// Proposals (docs/adr/0018). A plain flag rather than a seed: it carries no
|
|
64
|
+
// nonce and mints nothing — it only widens what `pre-receive` accepts on a
|
|
65
|
+
// claimed name, and the hook that widens runs in the container.
|
|
66
|
+
'WALGIT_PROPOSALS',
|
|
63
67
|
] as const
|
|
64
68
|
|
|
65
69
|
export type ContainerEnvName = (typeof CONTAINER_ENV)[number]
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
|
|
25
25
|
import { authorizedBy } from './credentials'
|
|
26
|
-
import { REF_NAME, REPO_ID, ZERO_OID } from './protocol'
|
|
26
|
+
import { PROPOSAL_ID, REF_NAME, REPO_ID, ZERO_OID } from './protocol'
|
|
27
27
|
|
|
28
28
|
/** One repository, and optionally the refs within it that matter. */
|
|
29
29
|
export interface WatchEntry {
|
|
@@ -37,6 +37,22 @@ export interface RefEvent {
|
|
|
37
37
|
repo: string
|
|
38
38
|
ref: string
|
|
39
39
|
sha: string | null
|
|
40
|
+
/**
|
|
41
|
+
* The Proposals this move MERGED: their ids, when this ref is a branch whose
|
|
42
|
+
* new tip a Proposal's tip became an ancestor of under this push
|
|
43
|
+
* (docs/adr/0018).
|
|
44
|
+
*
|
|
45
|
+
* ABSENT when it merged none, and never an empty array: a subscriber asking
|
|
46
|
+
* `merged?.length` should not have to tell "nothing landed" from "this
|
|
47
|
+
* deployment does not do Proposals", because in both cases nothing landed.
|
|
48
|
+
*
|
|
49
|
+
* Still latest-state, and not a log (docs/adr/0009). It is a property of the
|
|
50
|
+
* move — what became true when the ref got here — which a handshake
|
|
51
|
+
* therefore cannot carry: nothing moved, so nothing merged. A subscriber that
|
|
52
|
+
* was disconnected reads what is open from `GET /<name>.git/proposals`, which
|
|
53
|
+
* recomputes it from ancestry and is the same answer.
|
|
54
|
+
*/
|
|
55
|
+
merged?: string[]
|
|
40
56
|
}
|
|
41
57
|
|
|
42
58
|
/** The answer to a `watch`: current state, before any event can fire. */
|
|
@@ -226,10 +242,11 @@ export function parseAnnounce(body: unknown): Parsed<Announcement> {
|
|
|
226
242
|
for (const item of events) {
|
|
227
243
|
if (typeof item !== 'object' || item === null)
|
|
228
244
|
return { ok: false, error: 'event is not an object' }
|
|
229
|
-
const { repo, ref, sha } = item as {
|
|
245
|
+
const { repo, ref, sha, merged } = item as {
|
|
230
246
|
repo?: unknown
|
|
231
247
|
ref?: unknown
|
|
232
248
|
sha?: unknown
|
|
249
|
+
merged?: unknown
|
|
233
250
|
}
|
|
234
251
|
if (typeof repo !== 'string' || !REPO_ID.test(repo)) {
|
|
235
252
|
return {
|
|
@@ -246,7 +263,28 @@ export function parseAnnounce(body: unknown): Parsed<Announcement> {
|
|
|
246
263
|
if (sha !== null && (typeof sha !== 'string' || !/^[0-9a-f]{40,64}$/.test(sha))) {
|
|
247
264
|
return { ok: false, error: `invalid sha for ${ref}` }
|
|
248
265
|
}
|
|
249
|
-
|
|
266
|
+
// The Proposal ids this move merged, judged by the same grammar the ref
|
|
267
|
+
// they came from is: the Fan-out hands these to subscribers untouched, so
|
|
268
|
+
// an id this door accepts is an id every watcher is told about.
|
|
269
|
+
if (merged !== undefined) {
|
|
270
|
+
if (!Array.isArray(merged)) return { ok: false, error: `"merged" for ${ref} is not an array` }
|
|
271
|
+
for (const id of merged) {
|
|
272
|
+
if (typeof id !== 'string' || !PROPOSAL_ID.test(id)) {
|
|
273
|
+
return {
|
|
274
|
+
ok: false,
|
|
275
|
+
error: `invalid Proposal id for ${ref}: ${JSON.stringify(id ?? null)}`,
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
parsed.push({
|
|
281
|
+
repo,
|
|
282
|
+
ref,
|
|
283
|
+
sha,
|
|
284
|
+
// Empty stays absent, as it is on the way out: one spelling of "nothing
|
|
285
|
+
// merged" on the wire, whichever end wrote it.
|
|
286
|
+
...(Array.isArray(merged) && merged.length > 0 ? { merged: [...(merged as string[])] } : {}),
|
|
287
|
+
})
|
|
250
288
|
}
|
|
251
289
|
return { ok: true, value: { events: parsed, readersChanged: [...(changed as string[])] } }
|
|
252
290
|
}
|
|
@@ -317,14 +355,25 @@ export function eventsFromChanges(
|
|
|
317
355
|
// straight from the push path, and a parameter narrower than what they hold
|
|
318
356
|
// would make every call site build a second object to drop one field.
|
|
319
357
|
changes: readonly { ref: string; oldOid?: string; newOid: string }[],
|
|
358
|
+
/**
|
|
359
|
+
* What each moved ref merged, by ref name (`mergedProposals` in
|
|
360
|
+
* `src/proposals.ts`). Handed in rather than computed here because it is an
|
|
361
|
+
* ancestry walk against the Cache, and this file is the pure wire — and
|
|
362
|
+
* empty, always, on a deployment not taking Proposals.
|
|
363
|
+
*/
|
|
364
|
+
merged: Readonly<Record<string, string[]>> = {},
|
|
320
365
|
): RefEvent[] {
|
|
321
366
|
return changes
|
|
322
367
|
.filter((change) => REF_NAME.test(change.ref))
|
|
323
|
-
.map((change) =>
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
368
|
+
.map((change) => {
|
|
369
|
+
const ids = merged[change.ref]
|
|
370
|
+
return {
|
|
371
|
+
repo,
|
|
372
|
+
ref: change.ref,
|
|
373
|
+
sha: change.newOid === ZERO_OID ? null : change.newOid,
|
|
374
|
+
...(ids && ids.length > 0 ? { merged: [...ids] } : {}),
|
|
375
|
+
}
|
|
376
|
+
})
|
|
328
377
|
}
|
|
329
378
|
|
|
330
379
|
/** One message on the wire. Serialized in one place so its shape is one thing. */
|
|
@@ -284,6 +284,31 @@ function publicClaim(caps: Capabilities): string {
|
|
|
284
284
|
* learns "a repository is Private if it holds a `readers` file" knows the
|
|
285
285
|
* entire model. How to write one is `/llms.txt`, and the refusal itself.
|
|
286
286
|
*/
|
|
287
|
+
/**
|
|
288
|
+
* Proposals, as a rule of the host rather than a row in what is missing
|
|
289
|
+
* (docs/adr/0018).
|
|
290
|
+
*
|
|
291
|
+
* The `Pull requests` roadmap row has said *under design* since the page was
|
|
292
|
+
* written, and this is where it is spent — the same move Ownership and Private
|
|
293
|
+
* made, and for the same reason: a page carrying one capability twice, once as
|
|
294
|
+
* a fact and once as an achievement, is a page arguing with itself.
|
|
295
|
+
*
|
|
296
|
+
* Read from `proposals`, which is the only reading that can be right here: a
|
|
297
|
+
* Proposal is a SIGNED push to a name that HOLDS a Signer List, so the flag
|
|
298
|
+
* alone describes a handoff no push on that deployment could make.
|
|
299
|
+
*
|
|
300
|
+
* It names the ref, because the ref is the whole mechanism: there is no button,
|
|
301
|
+
* no record and no third list — the pusher picks the id, the target is in the
|
|
302
|
+
* name, and *merged* is the target's history containing it.
|
|
303
|
+
*/
|
|
304
|
+
function proposalsClaim(caps: Capabilities): string {
|
|
305
|
+
if (!caps.proposals) return ''
|
|
306
|
+
return claim(
|
|
307
|
+
'Proposals',
|
|
308
|
+
'<b>A claimed name takes a change from anyone who may read it.</b> Push to <code>refs/walgit/proposals/<branch>/<your-id></code> and it is held, signed and append-only, without being a Signer. Nobody accepts it but a Signer merging it themselves: it is <em>merged</em> when the branch\u2019s history contains it, and there is nothing else to be.',
|
|
309
|
+
)
|
|
310
|
+
}
|
|
311
|
+
|
|
287
312
|
function privateClaim(caps: Capabilities): string {
|
|
288
313
|
if (!caps.namesCanBePrivate) return ''
|
|
289
314
|
return claim(
|
|
@@ -451,6 +476,7 @@ function claims(caps: Capabilities): string {
|
|
|
451
476
|
appendOnlyClaim(caps),
|
|
452
477
|
publicClaim(caps),
|
|
453
478
|
privateClaim(caps),
|
|
479
|
+
proposalsClaim(caps),
|
|
454
480
|
thirdClaim(caps),
|
|
455
481
|
signingClaim(caps),
|
|
456
482
|
// Unconditional, unlike every term above it: nothing in `/robots.txt` is
|
|
@@ -565,9 +591,19 @@ function roadmapOwnership(caps: Capabilities): string {
|
|
|
565
591
|
* the reason one of them is cheap rather than part of it.
|
|
566
592
|
*/
|
|
567
593
|
function roadmapPulls(caps: Capabilities): string {
|
|
568
|
-
|
|
594
|
+
// The row LEAVES when the deployment takes Proposals, exactly as Ownership
|
|
595
|
+
// and Private leave: `proposalsClaim` above states the rule, and a roadmap
|
|
596
|
+
// row calling it under design underneath would be the page describing one
|
|
597
|
+
// capability in two contradictory places.
|
|
598
|
+
if (caps.proposals) return ''
|
|
599
|
+
const missing = caps.appendOnly
|
|
569
600
|
? 'Append-only already makes a proposal safe to push. What is missing is a way to say a branch is one, and a way to say it landed — not a review UI.'
|
|
570
601
|
: 'A branch is already the whole of a proposal. What is missing is a way to say that is what it is, and a way to say it landed — not a review UI.'
|
|
602
|
+
return ` <li>
|
|
603
|
+
<span class="when">Under design</span>
|
|
604
|
+
<h3>Pull requests</h3>
|
|
605
|
+
<p>${missing}</p>
|
|
606
|
+
</li>`
|
|
571
607
|
}
|
|
572
608
|
|
|
573
609
|
/**
|
|
@@ -1174,11 +1210,7 @@ const PAGE = `<!doctype html>
|
|
|
1174
1210
|
<p>What is missing, in the order it unblocks itself. Nothing here is a date, and each one is written down before it is built.</p>
|
|
1175
1211
|
<ul class="road">
|
|
1176
1212
|
{{ROADMAP_OWNERSHIP}}
|
|
1177
|
-
|
|
1178
|
-
<span class="when">Under design</span>
|
|
1179
|
-
<h3>Pull requests</h3>
|
|
1180
|
-
<p>{{ROADMAP_PULLS}}</p>
|
|
1181
|
-
</li>
|
|
1213
|
+
{{ROADMAP_PULLS}}
|
|
1182
1214
|
<li>
|
|
1183
1215
|
<span class="when">Half built</span>
|
|
1184
1216
|
<h3>CI</h3>
|
|
@@ -501,6 +501,71 @@ A revoked reader keeps the clone they already have — git has no way to reach
|
|
|
501
501
|
into somebody's working tree, and walgit does not pretend otherwise. Revoking is
|
|
502
502
|
a commit removing the line, it takes from the next read onward, and an event
|
|
503
503
|
stream reading on the strength of the old list is closed when the push lands.
|
|
504
|
+
`
|
|
505
|
+
: ''
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Proposals, taught where an agent that has work for a name it may not push
|
|
509
|
+
* to goes looking (docs/adr/0018).
|
|
510
|
+
*
|
|
511
|
+
* Placed after ownership and privacy because it depends on both in the strong
|
|
512
|
+
* sense: a Proposal is the one push a CLAIMED name takes from someone not on
|
|
513
|
+
* its Signer List, and who may propose is exactly who may read — which is
|
|
514
|
+
* everyone on a world-readable name and the Reader List on a Private one.
|
|
515
|
+
* `proposals` encodes that dependency, which is why it is the only flag read
|
|
516
|
+
* here.
|
|
517
|
+
*
|
|
518
|
+
* Every spelling is one the push path actually enforces — the namespace, the
|
|
519
|
+
* target in the ref name, the fast-forward that updates one — so an agent
|
|
520
|
+
* that reads this and an agent that reads the refusal are not being told
|
|
521
|
+
* about two different mechanisms.
|
|
522
|
+
*/
|
|
523
|
+
const proposing = caps.proposals
|
|
524
|
+
? `
|
|
525
|
+
## Propose a change
|
|
526
|
+
|
|
527
|
+
A name that holds a Signer List takes one push from someone it does not name: a
|
|
528
|
+
**Proposal**. It is a ref and its signature, and nothing else.
|
|
529
|
+
|
|
530
|
+
\`\`\`sh
|
|
531
|
+
git push --signed=yes https://${host}/$NAME.git HEAD:refs/walgit/proposals/main/fix-auth
|
|
532
|
+
\`\`\`
|
|
533
|
+
|
|
534
|
+
\`main\` is the branch you want it in and must already exist there; \`fix-auth\` is
|
|
535
|
+
your own word for the change. The host assigns nothing and stores nothing else:
|
|
536
|
+
there is no number to wait for and no record beyond the ref.
|
|
537
|
+
|
|
538
|
+
- **Whoever may read may propose.** On a world-readable name that is anyone
|
|
539
|
+
whose push is signed; on a Private one it is the Reader List and the Signers.
|
|
540
|
+
There is no third list to be added to.
|
|
541
|
+
- **Update it with a fast-forward** to the same ref. A taken id belongs to
|
|
542
|
+
whoever pushed it first — a second pusher is refused as a non-fast-forward,
|
|
543
|
+
and picks another id.
|
|
544
|
+
- **Merged is ancestry.** It is merged when the branch's history contains its
|
|
545
|
+
commit, computed when somebody asks and never recorded. A squash or a rebase
|
|
546
|
+
of your commits is a different commit, so it never marks one merged.
|
|
547
|
+
- **Nobody accepts it but a Signer.** There is no merge button and no endpoint:
|
|
548
|
+
a Signer fetches it, merges or fast-forwards it in their own tree, and pushes.
|
|
549
|
+
Conflicts are resolved where git resolves them.
|
|
550
|
+
|
|
551
|
+
Read what is open with \`curl https://${host}/$NAME.git/proposals\` — a JSON array
|
|
552
|
+
of \`{ id, target, tip, pusher, merged }\`, behind the same credential a clone of
|
|
553
|
+
that name needs. \`git ls-remote https://${host}/$NAME.git 'refs/walgit/proposals/*'\`
|
|
554
|
+
lists the same refs without the verdict: the target is in the ref name, so
|
|
555
|
+
nothing has to be fetched either way.
|
|
556
|
+
|
|
557
|
+
${
|
|
558
|
+
caps.events
|
|
559
|
+
? `If you are watching the branch (below), you do not have to ask twice: the event
|
|
560
|
+
for a branch that moved carries \`merged\` — the ids of the Proposals that move
|
|
561
|
+
landed — and leaves the field out when it landed none.
|
|
562
|
+
|
|
563
|
+
`
|
|
564
|
+
: ''
|
|
565
|
+
}A Proposal is a push like any other: it is signed, it is append-only, it counts
|
|
566
|
+
against the name's size caps, and it cannot be deleted or withdrawn. A target
|
|
567
|
+
that does not exist, a target that is not a branch, and a tip that is not a
|
|
568
|
+
commit are refused before anything is stored.
|
|
504
569
|
`
|
|
505
570
|
: ''
|
|
506
571
|
|
|
@@ -645,7 +710,7 @@ git clone https://${host}/$NAME.git
|
|
|
645
710
|
\`\`\`
|
|
646
711
|
|
|
647
712
|
Handing work to another agent is the URL and nothing else. There is no owner to ask, no invitation to send and no review to pass.
|
|
648
|
-
${signing}${ownership}${privacy}${events}
|
|
713
|
+
${signing}${ownership}${privacy}${proposing}${events}
|
|
649
714
|
## If a push is refused
|
|
650
715
|
|
|
651
716
|
Read the message. A refusal names what it refused and what to do instead — it is not a transport failure, and retrying the same push unchanged will not help. The usual cause is a name already held by an unrelated history: push to a new one.
|
|
@@ -156,6 +156,18 @@ export const ANNOUNCE_PATH = '/_walgit/announce'
|
|
|
156
156
|
*/
|
|
157
157
|
export const SMART_HTTP = /^\/([^/]+)\.git\/(info\/refs|git-upload-pack|git-receive-pack)$/
|
|
158
158
|
|
|
159
|
+
/**
|
|
160
|
+
* The Proposal read surface: `GET /<name>.git/proposals` (docs/adr/0018).
|
|
161
|
+
*
|
|
162
|
+
* Group 1 is the repository. Beside `SMART_HTTP` rather than inside it,
|
|
163
|
+
* deliberately: that regex is the git protocol and the Worker CLASSIFIES on it,
|
|
164
|
+
* so a fourth endpoint added there would change what the edge counts as a
|
|
165
|
+
* clone. This is a walgit endpoint that happens to live under the repository's
|
|
166
|
+
* own name, which is what ADR-0018 named it and what makes it discoverable from
|
|
167
|
+
* the URL an agent already has.
|
|
168
|
+
*/
|
|
169
|
+
export const PROPOSALS_HTTP = /^\/([^/]+)\.git\/proposals$/
|
|
170
|
+
|
|
159
171
|
/**
|
|
160
172
|
* A repo id is one flat segment.
|
|
161
173
|
*
|
|
@@ -171,6 +183,17 @@ export const REPO_ID = /^[A-Za-z0-9][A-Za-z0-9._-]*$/
|
|
|
171
183
|
/** A ref name, as git writes it. Full name only: `main` is not a ref. */
|
|
172
184
|
export const REF_NAME = /^refs\/[A-Za-z0-9._\-/]+$/
|
|
173
185
|
|
|
186
|
+
/**
|
|
187
|
+
* A Proposal id: the LAST segment of `refs/walgit/proposals/<target>/<id>`
|
|
188
|
+
* (docs/adr/0018), and therefore one ref segment — no slash, since the split
|
|
189
|
+
* that gives a target its own slashes is what makes the last segment the id.
|
|
190
|
+
*
|
|
191
|
+
* Here beside `REF_NAME` rather than in `src/proposals.ts` because both ends
|
|
192
|
+
* validate it: the container names ids on the announce wire, and the Fan-out
|
|
193
|
+
* has to judge them without importing the container's half of the program.
|
|
194
|
+
*/
|
|
195
|
+
export const PROPOSAL_ID = /^[A-Za-z0-9._-]+$/
|
|
196
|
+
|
|
174
197
|
/** The all-zeroes oid: creation when it is `oldOid`, deletion when `newOid`. */
|
|
175
198
|
export const ZERO_OID = '0'.repeat(40)
|
|
176
199
|
|
|
@@ -22,14 +22,22 @@ import type { RefChange } from './wal-index'
|
|
|
22
22
|
|
|
23
23
|
const repoId = process.argv[2]
|
|
24
24
|
const payload = process.argv[3]
|
|
25
|
+
/**
|
|
26
|
+
* What each moved branch merged (docs/adr/0018), computed by `post-receive`
|
|
27
|
+
* where the Cache is and passed down as a third JSON argument. Omitted by a
|
|
28
|
+
* deployment not taking Proposals, and by any caller from before this existed.
|
|
29
|
+
*/
|
|
30
|
+
const mergedPayload = process.argv[4]
|
|
25
31
|
|
|
26
32
|
async function main(): Promise<void> {
|
|
27
|
-
if (!repoId || !payload)
|
|
33
|
+
if (!repoId || !payload)
|
|
34
|
+
throw new Error('usage: announce-main <repo-id> <changes-json> [merged-json]')
|
|
28
35
|
const config = announceConfigFromEnv()
|
|
29
36
|
// Not an error: the environment can change between the spawn and the start,
|
|
30
37
|
// and a deployment with no stream configured simply has nothing to tell.
|
|
31
38
|
if (!config) return
|
|
32
|
-
|
|
39
|
+
const merged = mergedPayload ? (JSON.parse(mergedPayload) as Record<string, string[]>) : {}
|
|
40
|
+
await announce(config, repoId, JSON.parse(payload) as RefChange[], fetch, merged)
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
main().catch((err) => {
|
|
@@ -70,8 +70,15 @@ export async function announce(
|
|
|
70
70
|
repoId: string,
|
|
71
71
|
changes: readonly RefChange[],
|
|
72
72
|
fetchImpl: typeof fetch = fetch,
|
|
73
|
+
/**
|
|
74
|
+
* What each moved branch MERGED, by ref name (docs/adr/0018) — computed on
|
|
75
|
+
* the push path, where the Cache and the Index both are, and carried here
|
|
76
|
+
* rather than derived, because this file knows about a fetch and nothing
|
|
77
|
+
* about ancestry. Empty on every deployment not taking Proposals.
|
|
78
|
+
*/
|
|
79
|
+
merged: Readonly<Record<string, string[]>> = {},
|
|
73
80
|
): Promise<boolean> {
|
|
74
|
-
const events = eventsFromChanges(repoId, changes)
|
|
81
|
+
const events = eventsFromChanges(repoId, changes, merged)
|
|
75
82
|
if (events.length === 0) return false
|
|
76
83
|
// A Reader List lives on the Signer List's ref (docs/adr/0013), so a push
|
|
77
84
|
// that moved it may have revoked a reader whose socket is open right now.
|
|
@@ -18,12 +18,20 @@ import * as fs from 'node:fs'
|
|
|
18
18
|
import * as path from 'node:path'
|
|
19
19
|
|
|
20
20
|
import { capabilitiesFrom } from '../shared/capabilities'
|
|
21
|
+
import { ZERO_OID } from '../shared/protocol'
|
|
21
22
|
import { announceConfigFromEnv } from './announce'
|
|
22
23
|
import { appendOnlyEnabled, checkAppendOnly } from './append-only'
|
|
23
24
|
import { configuredThreshold, isCompactionDue } from './compact'
|
|
24
25
|
import { checkSize, limitsEnforced, limitsOf, liveBytes } from './limits'
|
|
25
26
|
import { clearPending, invocationId, markConsumed, readPending, sweepPending } from './pending'
|
|
26
27
|
import { privateReposEnabled } from './private'
|
|
28
|
+
import {
|
|
29
|
+
checkProposalRefs,
|
|
30
|
+
gitAncestry,
|
|
31
|
+
gitObjectType,
|
|
32
|
+
mergedProposals,
|
|
33
|
+
proposalsEnabled,
|
|
34
|
+
} from './proposals'
|
|
27
35
|
import {
|
|
28
36
|
establishSigner,
|
|
29
37
|
parseRefChanges,
|
|
@@ -123,11 +131,23 @@ async function main(): Promise<number> {
|
|
|
123
131
|
// the push lands. Here is where a refusal is free; there is where it is
|
|
124
132
|
// true. See `publishPush`.
|
|
125
133
|
if (signerListsEnabled()) {
|
|
134
|
+
const claim = (await index()).claim
|
|
135
|
+
// Proposals widen this one verdict and nothing else (docs/adr/0018): a
|
|
136
|
+
// push whose refs are ALL under `refs/walgit/proposals/` is judged by who
|
|
137
|
+
// may READ this name rather than by who may write it. The Reader List
|
|
138
|
+
// comes off the same Claim the Signer List does, so both halves of the
|
|
139
|
+
// question are answered from one reading of the Index.
|
|
126
140
|
const verdict = checkSignerAllowed(
|
|
127
141
|
repoId,
|
|
128
142
|
signer,
|
|
129
|
-
|
|
143
|
+
claim?.signers ?? null,
|
|
130
144
|
changes,
|
|
145
|
+
'pre-receive',
|
|
146
|
+
{
|
|
147
|
+
enabled: proposalsEnabled(),
|
|
148
|
+
privateRepos: privateReposEnabled(process.env),
|
|
149
|
+
readers: claim?.readers ?? null,
|
|
150
|
+
},
|
|
131
151
|
)
|
|
132
152
|
if (!verdict.ok) {
|
|
133
153
|
process.stderr.write(`${verdict.message}\n`)
|
|
@@ -135,6 +155,26 @@ async function main(): Promise<number> {
|
|
|
135
155
|
}
|
|
136
156
|
}
|
|
137
157
|
|
|
158
|
+
// Is what was pushed into the Proposal namespace a Proposal this host will
|
|
159
|
+
// hold — an existing branch as its target, a target that IS a branch, and a
|
|
160
|
+
// commit at its tip (docs/adr/0018)? Judged on the flag alone and for every
|
|
161
|
+
// pusher, the owner included: append-only means a ref written here can
|
|
162
|
+
// never be removed, so junk is refused before it is stored or never.
|
|
163
|
+
//
|
|
164
|
+
// Above append-only and below the gate for the same reason each of those
|
|
165
|
+
// sits where it does: a stranger who may not push here at all is told that
|
|
166
|
+
// first, and everything after it is about WHAT was pushed.
|
|
167
|
+
if (proposalsEnabled()) {
|
|
168
|
+
const verdict = checkProposalRefs(repoId, changes, {
|
|
169
|
+
refs: (await index()).refs,
|
|
170
|
+
objectType: gitObjectType(gitDir),
|
|
171
|
+
})
|
|
172
|
+
if (!verdict.ok) {
|
|
173
|
+
process.stderr.write(`${verdict.message}\n`)
|
|
174
|
+
return 1
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
138
178
|
// Append-only, for the same reason at the same moment: a push that will be
|
|
139
179
|
// refused must not cost an object-store write. git's own deny rules run
|
|
140
180
|
// after this hook, so leaving it to them would upload a pack nothing will
|
|
@@ -267,6 +307,10 @@ async function main(): Promise<number> {
|
|
|
267
307
|
: pending
|
|
268
308
|
const result = await publishPush(store, repoId, toPublish, changes, {
|
|
269
309
|
signerLists: signerListsEnabled(),
|
|
310
|
+
proposals: {
|
|
311
|
+
enabled: proposalsEnabled(),
|
|
312
|
+
privateRepos: privateReposEnabled(process.env),
|
|
313
|
+
},
|
|
270
314
|
})
|
|
271
315
|
if (!result.ok) {
|
|
272
316
|
process.stderr.write(`${publishRefusal(result)}\n`)
|
|
@@ -293,7 +337,14 @@ async function main(): Promise<number> {
|
|
|
293
337
|
const events = announceConfigFromEnv()
|
|
294
338
|
if (events) {
|
|
295
339
|
const changes = parseRefChanges(stdin).filter((c) => c.ref.startsWith('refs/'))
|
|
296
|
-
|
|
340
|
+
// What this push MERGED rides the same announcement (docs/adr/0018), so a
|
|
341
|
+
// Watcher on `main` learns a Proposal landed from the move rather than by
|
|
342
|
+
// reading the Proposal list again. Computed HERE and not in the detached
|
|
343
|
+
// announcer because this is where the Cache and the repository's own
|
|
344
|
+
// environment are — and computed at all only when a branch moved on a
|
|
345
|
+
// deployment taking Proposals, so a push on every other deployment pays
|
|
346
|
+
// nothing.
|
|
347
|
+
if (changes.length > 0) spawnAnnounce(repoId, changes, await mergedForAnnounce(changes))
|
|
297
348
|
}
|
|
298
349
|
try {
|
|
299
350
|
const store = storeFromEnv()
|
|
@@ -351,6 +402,35 @@ function publishRefusal(result: Extract<PublishResult, { ok: false }>): string {
|
|
|
351
402
|
}
|
|
352
403
|
}
|
|
353
404
|
|
|
405
|
+
/**
|
|
406
|
+
* The Proposals this push merged, per branch it moved — or nothing.
|
|
407
|
+
*
|
|
408
|
+
* Best-effort like everything else in `post-receive`: a failure here costs one
|
|
409
|
+
* announcement its `merged` field, never the push and never the announcement.
|
|
410
|
+
* The refs come from the Index (a Proposal pushed to another node is still this
|
|
411
|
+
* repository's) and ancestry from the Cache, which is the split
|
|
412
|
+
* `GET /<name>.git/proposals` already reads Merged through — a commit this disk
|
|
413
|
+
* does not hold reads as NOT merged, never as merged.
|
|
414
|
+
*/
|
|
415
|
+
async function mergedForAnnounce(changes: readonly RefChange[]): Promise<Record<string, string[]>> {
|
|
416
|
+
if (!proposalsEnabled()) return {}
|
|
417
|
+
// A push that moved no branch merged nothing, whatever this repository holds,
|
|
418
|
+
// so the Index is not read at all for a Proposal push or a deletion.
|
|
419
|
+
const moved = changes.some(
|
|
420
|
+
(change) => change.ref.startsWith('refs/heads/') && change.newOid !== ZERO_OID,
|
|
421
|
+
)
|
|
422
|
+
if (!moved) return {}
|
|
423
|
+
try {
|
|
424
|
+
const store = storeFromEnv()
|
|
425
|
+
if (!store) return {}
|
|
426
|
+
const { index } = await loadIndex(store, repoId)
|
|
427
|
+
return mergedProposals(changes, index.refs, gitAncestry(gitDir))
|
|
428
|
+
} catch (err) {
|
|
429
|
+
process.stderr.write(`walgit: merged Proposals not computed: ${(err as Error).message}\n`)
|
|
430
|
+
return {}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
|
|
354
434
|
/**
|
|
355
435
|
* Hand the announcement to a detached process and return.
|
|
356
436
|
*
|
|
@@ -366,11 +446,20 @@ function publishRefusal(result: Extract<PublishResult, { ok: false }>): string {
|
|
|
366
446
|
* what this would have announced, so a subscriber's next handshake reads it
|
|
367
447
|
* there anyway.
|
|
368
448
|
*/
|
|
369
|
-
function spawnAnnounce(
|
|
449
|
+
function spawnAnnounce(
|
|
450
|
+
repo: string,
|
|
451
|
+
changes: readonly RefChange[],
|
|
452
|
+
merged: Readonly<Record<string, string[]>>,
|
|
453
|
+
): void {
|
|
370
454
|
try {
|
|
371
455
|
const child = spawn(
|
|
372
456
|
process.execPath,
|
|
373
|
-
[
|
|
457
|
+
[
|
|
458
|
+
path.join(import.meta.dir, 'announce-main.ts'),
|
|
459
|
+
repo,
|
|
460
|
+
JSON.stringify(changes),
|
|
461
|
+
JSON.stringify(merged),
|
|
462
|
+
],
|
|
374
463
|
{ detached: true, stdio: 'ignore' },
|
|
375
464
|
)
|
|
376
465
|
child.unref()
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
EXPIRE_PATH,
|
|
18
18
|
HEALTH_PATH,
|
|
19
19
|
INTERNAL_HEADER,
|
|
20
|
+
PROPOSALS_HTTP,
|
|
20
21
|
PROVENANCE_PATH,
|
|
21
22
|
READ_CHALLENGE_SCHEME,
|
|
22
23
|
READ_VERDICT_PATH,
|
|
@@ -29,6 +30,7 @@ import {
|
|
|
29
30
|
import { emptyReadResponse } from './empty-read'
|
|
30
31
|
import { renderInstructions } from './instructions'
|
|
31
32
|
import { acceptedNonces, readAllowed, readChallengeNonce, renderReadChallenge } from './private'
|
|
33
|
+
import type { ProposalListing } from './proposals'
|
|
32
34
|
import type { ResolvedRepo } from './repo'
|
|
33
35
|
import { resolveRepo } from './repo'
|
|
34
36
|
import type { Claim, Provenance } from './wal-index'
|
|
@@ -112,6 +114,21 @@ export type HttpHandlerDeps = {
|
|
|
112
114
|
* a missing log is the one wrong answer this feature can give.
|
|
113
115
|
*/
|
|
114
116
|
readProvenance?: (repoId: string) => Promise<ProvenanceRead>
|
|
117
|
+
/**
|
|
118
|
+
* The Proposals one repository holds, with `merged` already derived
|
|
119
|
+
* (docs/adr/0018).
|
|
120
|
+
*
|
|
121
|
+
* The derivation is the caller's because it needs two things this module
|
|
122
|
+
* deliberately has none of: the Index, and a synced Cache to ask
|
|
123
|
+
* `merge-base --is-ancestor` of. `src/server.ts` is where those meet, and
|
|
124
|
+
* `listProposals` (`src/proposals.ts`) is the pure part of it.
|
|
125
|
+
*
|
|
126
|
+
* Optional like every other reader here, and absent means the endpoint does
|
|
127
|
+
* not exist rather than answering an empty list — an instance with no store
|
|
128
|
+
* has no authoritative answer, and "this repository has no Proposals" is
|
|
129
|
+
* exactly the wrong thing to invent out of a missing log.
|
|
130
|
+
*/
|
|
131
|
+
readProposals?: (repoId: string) => Promise<ProposalListing[]>
|
|
115
132
|
/**
|
|
116
133
|
* Read gating for Private repositories (docs/adr/0013), or `undefined` for a
|
|
117
134
|
* deployment that does none — which is every deployment until an operator
|
|
@@ -440,6 +457,61 @@ function createRouter(deps: HttpHandlerDeps): (req: Request) => Promise<Response
|
|
|
440
457
|
})
|
|
441
458
|
}
|
|
442
459
|
|
|
460
|
+
// What Proposals a repository holds (docs/adr/0018). Beside the provenance
|
|
461
|
+
// read and gated identically — the deployment credential above, then the
|
|
462
|
+
// Read Challenge below — because it answers the same kind of question about
|
|
463
|
+
// the same repository: on a Private name, who proposed what is part of what
|
|
464
|
+
// the Reader List is protecting.
|
|
465
|
+
//
|
|
466
|
+
// It exists only where the deployment OFFERS Proposals. That is the derived
|
|
467
|
+
// capability rather than the raw flag (`shared/capabilities.ts`): a Proposal
|
|
468
|
+
// is a signed push to a name holding a Signer List, so on a deployment
|
|
469
|
+
// without those the namespace is an ordinary one and there is no Proposal to
|
|
470
|
+
// report. An instance that advertises none answers 404 here, which is what
|
|
471
|
+
// "with the flag off it does not exist" means.
|
|
472
|
+
const proposalRoute = PROPOSALS_HTTP.exec(url.pathname)
|
|
473
|
+
if (proposalRoute) {
|
|
474
|
+
const offered = (deps.capabilities ?? ADVERTISES_NOTHING).proposals
|
|
475
|
+
if (!offered || !deps.readProposals || request.method !== 'GET') return NOT_FOUND()
|
|
476
|
+
let repoId: string
|
|
477
|
+
try {
|
|
478
|
+
repoId = resolveRepo(deps.reposDir, proposalRoute[1]!).repoId
|
|
479
|
+
} catch {
|
|
480
|
+
// A bad name is a 404 rather than a challenge for a repository that
|
|
481
|
+
// could not exist, exactly as it is on the git path below.
|
|
482
|
+
return NOT_FOUND()
|
|
483
|
+
}
|
|
484
|
+
if (priv) {
|
|
485
|
+
let claim: Claim | undefined
|
|
486
|
+
try {
|
|
487
|
+
claim = await priv.readClaim(repoId)
|
|
488
|
+
} catch {
|
|
489
|
+
claim = LOCKED
|
|
490
|
+
}
|
|
491
|
+
const refused = await refuseRead(request, url, claim)
|
|
492
|
+
if (refused) return refused
|
|
493
|
+
}
|
|
494
|
+
let proposals: ProposalListing[]
|
|
495
|
+
try {
|
|
496
|
+
proposals = await deps.readProposals(repoId)
|
|
497
|
+
} catch (err) {
|
|
498
|
+
// Refused rather than answered empty. Every other absence here is an
|
|
499
|
+
// ordinary answer, but "this repository has no Proposals" read out of an
|
|
500
|
+
// Index we could not reach is a wrong answer a client cannot tell from a
|
|
501
|
+
// right one — and one an agent would act on by pushing a duplicate.
|
|
502
|
+
return reject(503, 'unavailable', `walgit: ${(err as Error).message}\n`)
|
|
503
|
+
}
|
|
504
|
+
return new Response(`${JSON.stringify({ repo: repoId, proposals })}\n`, {
|
|
505
|
+
headers: {
|
|
506
|
+
'content-type': 'application/json; charset=utf-8',
|
|
507
|
+
// Every field in it is derived from where refs point right now, and
|
|
508
|
+
// `merged` flips the moment somebody pushes the target. A cached copy
|
|
509
|
+
// is a Proposal reported open after it was accepted.
|
|
510
|
+
'cache-control': 'no-store',
|
|
511
|
+
},
|
|
512
|
+
})
|
|
513
|
+
}
|
|
514
|
+
|
|
443
515
|
const route = SMART_HTTP.exec(url.pathname)
|
|
444
516
|
if (!route) return NOT_FOUND()
|
|
445
517
|
|
|
@@ -0,0 +1,360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proposals: the one push a claimed name takes from someone not on its Signer
|
|
3
|
+
* List (docs/adr/0018).
|
|
4
|
+
*
|
|
5
|
+
* A Proposal is a ref under `refs/walgit/proposals/<target>/<id>` naming a
|
|
6
|
+
* commit its pusher wants in `refs/heads/<target>`, plus the Push Certificate
|
|
7
|
+
* behind it, and nothing else. There is no record, no row and no file: whether
|
|
8
|
+
* it is Merged is `merge-base --is-ancestor` against the target, computed on
|
|
9
|
+
* read from the Cache and never written down.
|
|
10
|
+
*
|
|
11
|
+
* Three questions live here and all three are pure:
|
|
12
|
+
*
|
|
13
|
+
* - `parseProposalRef` — what a ref NAMES. The target is in the ref name
|
|
14
|
+
* rather than derived from the commit, so `ls-remote` shows it and nothing
|
|
15
|
+
* has to be parsed to list what is open.
|
|
16
|
+
* - `checkProposalRefs` — whether the host will hold it. A Proposal aimed at
|
|
17
|
+
* a branch that does not exist, at something that is not a branch, or
|
|
18
|
+
* pointing at an object that is not a commit, is refused in `pre-receive`
|
|
19
|
+
* rather than stored: append-only means a ref written here can never be
|
|
20
|
+
* deleted, so the one moment to refuse junk is before it lands.
|
|
21
|
+
* - `listProposals` — what the repository HOLDS, for the read surface
|
|
22
|
+
* (`GET /<name>.git/proposals`). It is handed the Index's refs, the Index's
|
|
23
|
+
* provenance and an ancestry predicate, and it stores nothing: Merged is
|
|
24
|
+
* recomputed on every read, because a Proposal that became merged did so by
|
|
25
|
+
* someone pushing the target, and nothing told this host about it.
|
|
26
|
+
*
|
|
27
|
+
* WHO may write one is deliberately not here. That is the Signer List gate's
|
|
28
|
+
* question — `checkSignerAllowed` in `src/signers.ts` — because the rule is
|
|
29
|
+
* *whoever may read may propose*, and reading is a Reader List's answer, which
|
|
30
|
+
* that gate already holds. Splitting it the other way would have put half of
|
|
31
|
+
* ownership in this file.
|
|
32
|
+
*
|
|
33
|
+
* Off unless the instance turns it on, like every capability in this package.
|
|
34
|
+
* With the flag off `refs/walgit/proposals/…` is an ordinary ref namespace
|
|
35
|
+
* under the ordinary gate: nothing widens and nothing is validated.
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
import { flagEnabled } from '../shared/policy'
|
|
39
|
+
import { ZERO_OID } from '../shared/protocol'
|
|
40
|
+
import { git } from './git'
|
|
41
|
+
import type { Provenance, RefChange } from './wal-index'
|
|
42
|
+
|
|
43
|
+
/** The env flag an instance sets to take Proposals. */
|
|
44
|
+
export function proposalsEnabled(env: Record<string, string | undefined> = process.env): boolean {
|
|
45
|
+
return flagEnabled(env.WALGIT_PROPOSALS)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The namespace, with its trailing slash — so `startsWith` cannot match a ref
|
|
50
|
+
* called `refs/walgit/proposalsomething`.
|
|
51
|
+
*/
|
|
52
|
+
export const PROPOSALS_PREFIX = 'refs/walgit/proposals/'
|
|
53
|
+
|
|
54
|
+
/** The branch a Proposal wants its commit in, spelled as a ref. */
|
|
55
|
+
export const targetRef = (target: string): string => `refs/heads/${target}`
|
|
56
|
+
|
|
57
|
+
export interface Proposal {
|
|
58
|
+
/** The branch this Proposal is for, WITHOUT the `refs/heads/` prefix. */
|
|
59
|
+
target: string
|
|
60
|
+
/** The pusher's word. The host assigns nothing and collisions are refused. */
|
|
61
|
+
id: string
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* What a ref names, or `null` when it names no Proposal.
|
|
66
|
+
*
|
|
67
|
+
* The id is the LAST segment and the target is everything before it, which is
|
|
68
|
+
* the only split that lets a target be a branch with slashes in it — `feat/login`
|
|
69
|
+
* is an ordinary branch name, and an agent proposing to one must not have to
|
|
70
|
+
* know this ref is parsed at all.
|
|
71
|
+
*
|
|
72
|
+
* Both halves must be non-empty, so `…/main` (no id) and `…/main/` (no id) and
|
|
73
|
+
* `…//fix` (no target) name nothing. That is a refusal rather than a guess:
|
|
74
|
+
* every one of them is a client that meant something this host cannot tell.
|
|
75
|
+
*/
|
|
76
|
+
export function parseProposalRef(ref: string): Proposal | null {
|
|
77
|
+
if (!ref.startsWith(PROPOSALS_PREFIX)) return null
|
|
78
|
+
const rest = ref.slice(PROPOSALS_PREFIX.length)
|
|
79
|
+
const cut = rest.lastIndexOf('/')
|
|
80
|
+
if (cut <= 0) return null
|
|
81
|
+
const target = rest.slice(0, cut)
|
|
82
|
+
const id = rest.slice(cut + 1)
|
|
83
|
+
if (target === '' || id === '') return null
|
|
84
|
+
return { target, id }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Is this ref in the namespace at all, well-formed or not? */
|
|
88
|
+
export const isProposalRef = (ref: string): boolean => ref.startsWith(PROPOSALS_PREFIX)
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* What the shape check is asked of: the refs this repository holds, and what
|
|
92
|
+
* an object is.
|
|
93
|
+
*
|
|
94
|
+
* The refs come from the **Index**, not from the Cache, for the reason the gate
|
|
95
|
+
* reads its Signer List there — the Cache is disposable, and a target that
|
|
96
|
+
* existed only on whichever node happened to have materialized would make a
|
|
97
|
+
* refusal depend on which container answered.
|
|
98
|
+
*
|
|
99
|
+
* The object type is a subprocess against the quarantine, injected so every
|
|
100
|
+
* decision here is testable without a repository — the same seam
|
|
101
|
+
* `src/signers.ts` puts in front of its blob reader.
|
|
102
|
+
*/
|
|
103
|
+
export interface ProposalSource {
|
|
104
|
+
/** The repository's refs, as the Index holds them: ref → oid. */
|
|
105
|
+
refs: Readonly<Record<string, string>>
|
|
106
|
+
/** `commit`, `tree`, `blob`, `tag` — or `null` for an object git cannot see. */
|
|
107
|
+
objectType: (oid: string) => string | null
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The real object reader: the pushed objects are in the hook's object path. */
|
|
111
|
+
export function gitObjectType(gitDir: string): (oid: string) => string | null {
|
|
112
|
+
return (oid) => {
|
|
113
|
+
const res = git(['--git-dir', gitDir, 'cat-file', '-t', oid])
|
|
114
|
+
if (res.status !== 0) return null
|
|
115
|
+
const type = res.stdout.trim()
|
|
116
|
+
return type === '' ? null : type
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/** Every way a Proposal can be malformed. */
|
|
121
|
+
export type ProposalRefusal =
|
|
122
|
+
/** The ref is in the namespace and names no `<target>/<id>`. */
|
|
123
|
+
| 'grammar'
|
|
124
|
+
/** `refs/heads/<target>` is not a ref this repository holds. */
|
|
125
|
+
| 'missing-target'
|
|
126
|
+
/** The target is not a branch — it names something outside `refs/heads/`. */
|
|
127
|
+
| 'not-a-branch'
|
|
128
|
+
/** The tip is a tree, a blob, a tag, or an object the host cannot see. */
|
|
129
|
+
| 'not-a-commit'
|
|
130
|
+
|
|
131
|
+
export type ProposalVerdict =
|
|
132
|
+
| { ok: true }
|
|
133
|
+
| { ok: false; kind: ProposalRefusal; ref: string; message: string }
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Judge every Proposal ref a push writes. Refs outside the namespace are
|
|
137
|
+
* somebody else's question and are passed over.
|
|
138
|
+
*
|
|
139
|
+
* A DELETION is passed over too: it has no tip to be a commit and no Proposal
|
|
140
|
+
* to validate, and whether a ref here may be removed at all is append-only's
|
|
141
|
+
* answer rather than this one's. On the deployment ADR-0018 is written for
|
|
142
|
+
* append-only is on, so there is nothing to delete with.
|
|
143
|
+
*
|
|
144
|
+
* The first offending ref decides the push, as append-only's judge does and for
|
|
145
|
+
* the same reason: a push is all or nothing to git, so a second refusal would
|
|
146
|
+
* only make the message longer than an agent reads.
|
|
147
|
+
*/
|
|
148
|
+
export function checkProposalRefs(
|
|
149
|
+
repoId: string,
|
|
150
|
+
changes: readonly RefChange[],
|
|
151
|
+
source: ProposalSource,
|
|
152
|
+
): ProposalVerdict {
|
|
153
|
+
for (const change of changes) {
|
|
154
|
+
if (!isProposalRef(change.ref)) continue
|
|
155
|
+
if (change.newOid === ZERO_OID) continue
|
|
156
|
+
|
|
157
|
+
const proposal = parseProposalRef(change.ref)
|
|
158
|
+
if (!proposal) return refuse(repoId, 'grammar', change.ref, 'names no target and id')
|
|
159
|
+
|
|
160
|
+
if (proposal.target.startsWith('refs/')) {
|
|
161
|
+
return refuse(
|
|
162
|
+
repoId,
|
|
163
|
+
'not-a-branch',
|
|
164
|
+
change.ref,
|
|
165
|
+
`its target \`${proposal.target}\` is not a branch — a Proposal names one under refs/heads/`,
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const target = targetRef(proposal.target)
|
|
170
|
+
if (source.refs[target] === undefined) {
|
|
171
|
+
return refuse(repoId, 'missing-target', change.ref, `${target} does not exist here`)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const type = source.objectType(change.newOid)
|
|
175
|
+
if (type !== 'commit') {
|
|
176
|
+
return refuse(
|
|
177
|
+
repoId,
|
|
178
|
+
'not-a-commit',
|
|
179
|
+
change.ref,
|
|
180
|
+
`it points at ${type ?? 'an object this host cannot read'}, not a commit`,
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return { ok: true }
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const refuse = (
|
|
188
|
+
repoId: string,
|
|
189
|
+
kind: ProposalRefusal,
|
|
190
|
+
ref: string,
|
|
191
|
+
why: string,
|
|
192
|
+
): Extract<ProposalVerdict, { ok: false }> => ({
|
|
193
|
+
ok: false,
|
|
194
|
+
kind,
|
|
195
|
+
ref,
|
|
196
|
+
message: rejectionMessage(repoId, ref, why),
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* What a malformed Proposal reads. Product copy, like every other refusal on
|
|
201
|
+
* this path: an agent that cannot act on a refusal has been told nothing, and
|
|
202
|
+
* this one is most often read by an agent that has just learned Proposals
|
|
203
|
+
* exist.
|
|
204
|
+
*/
|
|
205
|
+
function rejectionMessage(repoId: string, ref: string, why: string): string {
|
|
206
|
+
return [
|
|
207
|
+
`walgit: refused — ${ref} is not a Proposal ${repoId} can hold: ${why}.`,
|
|
208
|
+
'',
|
|
209
|
+
'A Proposal is a ref naming the commit you want in an existing branch:',
|
|
210
|
+
'',
|
|
211
|
+
` git push --signed=yes origin HEAD:${PROPOSALS_PREFIX}<branch>/<your-id>`,
|
|
212
|
+
'',
|
|
213
|
+
'The branch is the one you want it merged into and must already exist here;',
|
|
214
|
+
'the id is your own word for this change, and a taken one is refused as a',
|
|
215
|
+
'non-fast-forward, so pick another. Refs here are append-only like every',
|
|
216
|
+
'other, which is why a Proposal is judged before it is stored rather than',
|
|
217
|
+
'after.',
|
|
218
|
+
'',
|
|
219
|
+
'Nothing was uploaded; the repository is unchanged.',
|
|
220
|
+
].join('\n')
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// ── The read surface ────────────────────────────────────────────────────────
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* One Proposal, as `GET /<name>.git/proposals` reports it (docs/adr/0018).
|
|
227
|
+
*
|
|
228
|
+
* Every field is derived: the id and the target from the ref NAME, the tip from
|
|
229
|
+
* the Index, the pusher from the Provenance the Index already records, and
|
|
230
|
+
* `merged` from ancestry at the moment of the read. Nothing here is state
|
|
231
|
+
* walgit keeps — there is no row to go stale and nothing a Materialize could
|
|
232
|
+
* fail to rebuild.
|
|
233
|
+
*/
|
|
234
|
+
export interface ProposalListing extends Proposal {
|
|
235
|
+
/** The commit the pusher wants in the target. */
|
|
236
|
+
tip: string
|
|
237
|
+
/**
|
|
238
|
+
* The key that signed the push that put the tip there, or `null`.
|
|
239
|
+
*
|
|
240
|
+
* `null` rather than an omitted field, because absence is an ordinary answer
|
|
241
|
+
* here: signing is what a deployment taking Proposals demands, but a
|
|
242
|
+
* repository can hold refs from before the Index recorded provenance at all,
|
|
243
|
+
* and a reader should not have to tell a missing key from a missing field.
|
|
244
|
+
*/
|
|
245
|
+
pusher: string | null
|
|
246
|
+
/** Its tip is an ancestor of the target's tip. Computed, never stored. */
|
|
247
|
+
merged: boolean
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* Does `tip` reach `ancestorOf`? The one question `merged` is.
|
|
252
|
+
*
|
|
253
|
+
* Injected so the listing is pure and so the ONLY place that spawns git for
|
|
254
|
+
* this is `gitAncestry` below — the same seam `ProposalSource.objectType` puts
|
|
255
|
+
* in front of the hook's object reader.
|
|
256
|
+
*/
|
|
257
|
+
export type Ancestry = (tip: string, ancestorOf: string) => boolean
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* The real predicate: `merge-base --is-ancestor` against the Cache.
|
|
261
|
+
*
|
|
262
|
+
* The Cache, deliberately, and it is the one thing on this path not read from
|
|
263
|
+
* the Index: the Index knows where refs point and holds no commits, so ancestry
|
|
264
|
+
* cannot be answered from it at all. The caller's job is to have synced the
|
|
265
|
+
* Cache first (`src/sync.ts`) — a cold container Materializes there, which is
|
|
266
|
+
* what makes an answer from a disposable disk as true as one from the log.
|
|
267
|
+
*
|
|
268
|
+
* Exit 0 is yes, 1 is no, and anything else — a commit this disk does not hold
|
|
269
|
+
* — is NOT merged. Reading a missing object as merged would mark a Proposal
|
|
270
|
+
* accepted on the strength of a failed subprocess, which is the one direction a
|
|
271
|
+
* later read cannot take back.
|
|
272
|
+
*/
|
|
273
|
+
export function gitAncestry(gitDir: string): Ancestry {
|
|
274
|
+
return (tip, ancestorOf) =>
|
|
275
|
+
git(['--git-dir', gitDir, 'merge-base', '--is-ancestor', tip, ancestorOf]).status === 0
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Every Proposal a repository holds, in ref order.
|
|
280
|
+
*
|
|
281
|
+
* Sorted by ref name rather than left in whatever order the Index's object
|
|
282
|
+
* happens to serialize, so a client diffing two reads sees only what changed.
|
|
283
|
+
*
|
|
284
|
+
* A ref in the namespace that names no `<target>/<id>` is SKIPPED rather than
|
|
285
|
+
* reported. `pre-receive` refuses those, so one can only be here from before
|
|
286
|
+
* the flag was on — and the read surface is not the place to litigate a ref
|
|
287
|
+
* that is already written for good.
|
|
288
|
+
*
|
|
289
|
+
* Superseded is not derived. ADR-0018 admits it "if it is free", and it is not:
|
|
290
|
+
* it is ancestry between every pair of Proposals to the same target, which is a
|
|
291
|
+
* second quadratic walk for a field nothing has asked for yet.
|
|
292
|
+
*/
|
|
293
|
+
/**
|
|
294
|
+
* What a push MERGED, per branch it moved: the ids of Proposals to that branch
|
|
295
|
+
* whose tip became an ancestor of the new tip (docs/adr/0018).
|
|
296
|
+
*
|
|
297
|
+
* The Ref Event a Watcher receives carries this, so an agent watching `main`
|
|
298
|
+
* learns a Proposal landed from the move itself rather than by reading the
|
|
299
|
+
* Proposal list again — the second call this whole stream exists to avoid.
|
|
300
|
+
*
|
|
301
|
+
* NEWLY, and that is the whole of the old oid's job here: a Proposal that was
|
|
302
|
+
* already an ancestor before this push merged on some earlier push, and
|
|
303
|
+
* re-announcing it on every subsequent commit to the branch would make the
|
|
304
|
+
* field a report of state rather than of what happened. A branch this push
|
|
305
|
+
* CREATED has no before, so everything it reaches is news.
|
|
306
|
+
*
|
|
307
|
+
* Only `refs/heads/` moves are asked about, and never a deletion: a branch that
|
|
308
|
+
* is gone is nothing to be an ancestor of, and a Proposal aimed at it is open —
|
|
309
|
+
* which is what `listProposals` reads it as too.
|
|
310
|
+
*
|
|
311
|
+
* Ids are sorted and a branch that merged nothing is left out entirely, so the
|
|
312
|
+
* caller has nothing to decide about an empty array.
|
|
313
|
+
*/
|
|
314
|
+
export function mergedProposals(
|
|
315
|
+
changes: readonly RefChange[],
|
|
316
|
+
refs: Readonly<Record<string, string>>,
|
|
317
|
+
isAncestor: Ancestry,
|
|
318
|
+
): Record<string, string[]> {
|
|
319
|
+
const merged: Record<string, string[]> = {}
|
|
320
|
+
for (const change of changes) {
|
|
321
|
+
if (!change.ref.startsWith('refs/heads/')) continue
|
|
322
|
+
if (change.newOid === ZERO_OID) continue
|
|
323
|
+
const target = change.ref.slice('refs/heads/'.length)
|
|
324
|
+
const ids: string[] = []
|
|
325
|
+
for (const ref of Object.keys(refs).toSorted()) {
|
|
326
|
+
const proposal = parseProposalRef(ref)
|
|
327
|
+
if (!proposal || proposal.target !== target) continue
|
|
328
|
+
const tip = refs[ref]!
|
|
329
|
+
if (!isAncestor(tip, change.newOid)) continue
|
|
330
|
+
const had = change.oldOid !== undefined && change.oldOid !== ZERO_OID
|
|
331
|
+
if (had && isAncestor(tip, change.oldOid!)) continue
|
|
332
|
+
ids.push(proposal.id)
|
|
333
|
+
}
|
|
334
|
+
if (ids.length > 0) merged[change.ref] = ids
|
|
335
|
+
}
|
|
336
|
+
return merged
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function listProposals(
|
|
340
|
+
refs: Readonly<Record<string, string>>,
|
|
341
|
+
provenance: Readonly<Record<string, Provenance>>,
|
|
342
|
+
isAncestor: Ancestry,
|
|
343
|
+
): ProposalListing[] {
|
|
344
|
+
const listings: ProposalListing[] = []
|
|
345
|
+
for (const ref of Object.keys(refs).toSorted()) {
|
|
346
|
+
const proposal = parseProposalRef(ref)
|
|
347
|
+
if (!proposal) continue
|
|
348
|
+
const tip = refs[ref]!
|
|
349
|
+
const targetTip = refs[targetRef(proposal.target)]
|
|
350
|
+
listings.push({
|
|
351
|
+
...proposal,
|
|
352
|
+
tip,
|
|
353
|
+
pusher: provenance[ref]?.signer ?? null,
|
|
354
|
+
// A target this repository no longer holds is nothing to be an ancestor
|
|
355
|
+
// of, so the Proposal is open — which is also what it is.
|
|
356
|
+
merged: targetTip !== undefined && isAncestor(tip, targetTip),
|
|
357
|
+
})
|
|
358
|
+
}
|
|
359
|
+
return listings
|
|
360
|
+
}
|
|
@@ -24,7 +24,13 @@ import { ZERO_OID } from '../shared/protocol'
|
|
|
24
24
|
import { walKey } from './keys'
|
|
25
25
|
import { writePending, type PendingPush } from './pending'
|
|
26
26
|
import { certSigner } from './push-cert'
|
|
27
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
checkSignerAllowed,
|
|
29
|
+
describeSigner,
|
|
30
|
+
type GateRefusal,
|
|
31
|
+
type ProposalGate,
|
|
32
|
+
type PushSigner,
|
|
33
|
+
} from './signers'
|
|
28
34
|
import type { ObjectStore } from './store'
|
|
29
35
|
import { ulid } from './ulid'
|
|
30
36
|
import {
|
|
@@ -258,6 +264,16 @@ export interface PublishOptions {
|
|
|
258
264
|
* settled in one place (`hook-main`), for both askings.
|
|
259
265
|
*/
|
|
260
266
|
signerLists?: boolean
|
|
267
|
+
/**
|
|
268
|
+
* Proposals, as the gate needs them (docs/adr/0018) — minus the Reader List,
|
|
269
|
+
* which is read HERE, off the Claim this attempt is publishing onto.
|
|
270
|
+
*
|
|
271
|
+
* That split is the same rule as the Signer List beside it: who may propose
|
|
272
|
+
* is who may read, and who may read is a fact about the repository, which can
|
|
273
|
+
* move while a push uploads. Handing the list in from `pre-receive` would
|
|
274
|
+
* judge the re-ask against a repository that no longer exists.
|
|
275
|
+
*/
|
|
276
|
+
proposals?: Omit<ProposalGate, 'readers'>
|
|
261
277
|
}
|
|
262
278
|
|
|
263
279
|
/**
|
|
@@ -378,6 +394,10 @@ export async function publishPush(
|
|
|
378
394
|
index.claim?.signers ?? null,
|
|
379
395
|
changes,
|
|
380
396
|
'publish',
|
|
397
|
+
{
|
|
398
|
+
...(options.proposals ?? { enabled: false, privateRepos: false }),
|
|
399
|
+
readers: index.claim?.readers ?? null,
|
|
400
|
+
},
|
|
381
401
|
)
|
|
382
402
|
if (!verdict.ok) {
|
|
383
403
|
return { ok: false, reason: 'not-allowed', kind: verdict.kind, message: verdict.message }
|
|
@@ -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'
|
|
@@ -205,6 +207,35 @@ try {
|
|
|
205
207
|
return { provenance: index.provenance ?? {}, claim: index.claim }
|
|
206
208
|
}
|
|
207
209
|
: undefined,
|
|
210
|
+
// What Proposals a repository holds, with `merged` derived (docs/adr/0018).
|
|
211
|
+
//
|
|
212
|
+
// Three reads, and each is from the only place that can answer it: the refs
|
|
213
|
+
// and the provenance from the INDEX, because that is the source of truth
|
|
214
|
+
// and a node's disk is a cache; ancestry from the CACHE, because the Index
|
|
215
|
+
// holds no commits. Which is why the sync happens here rather than being
|
|
216
|
+
// skipped as it is for the other JSON reads — a cold container has the refs
|
|
217
|
+
// and none of the objects, and `merge-base` on a commit this disk has never
|
|
218
|
+
// seen reads as "not merged", which is a wrong answer rather than a slow
|
|
219
|
+
// one. `syncRepo` Materializes when reconcile reports objects missing.
|
|
220
|
+
//
|
|
221
|
+
// Absent without a store for the reason `readProvenance` is: the endpoint
|
|
222
|
+
// should not exist where there is nothing authoritative behind it. Whether
|
|
223
|
+
// the deployment OFFERS Proposals at all is the handler's check, against the
|
|
224
|
+
// capability this same process advertises.
|
|
225
|
+
readProposals: store
|
|
226
|
+
? async (repoId) => {
|
|
227
|
+
const { index } = await loadIndex(store, repoId)
|
|
228
|
+
// Nothing to walk, and nothing touched. A read must not bring a name
|
|
229
|
+
// into existence — pushing is what does that — so a repository with
|
|
230
|
+
// no Proposal ref is answered from the Index alone, without
|
|
231
|
+
// `ensureBareRepo` creating a directory for whatever name was asked
|
|
232
|
+
// about. It is also the common case: most repositories hold none.
|
|
233
|
+
if (!Object.keys(index.refs).some(isProposalRef)) return []
|
|
234
|
+
const repo = ensureBareRepo(resolveRepo(reposDir, repoId))
|
|
235
|
+
await syncRepo(store, repo)
|
|
236
|
+
return listProposals(index.refs, index.provenance ?? {}, gitAncestry(repo.dir))
|
|
237
|
+
}
|
|
238
|
+
: undefined,
|
|
208
239
|
// Read gating, and only where all three halves exist (docs/adr/0013): the
|
|
209
240
|
// seed with the Signer List flag beside it, and a store to read the Reader
|
|
210
241
|
// 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,
|