@leed-ai/git-gateway-worker 0.0.0-stage → 0.1.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.
Files changed (269) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +49 -2
  3. package/dist/audit/audit-recorder.d.ts +2 -0
  4. package/dist/audit/audit-recorder.js +53 -0
  5. package/dist/audit/audit-recorder.js.map +1 -0
  6. package/dist/audit/push-report.d.ts +13 -0
  7. package/dist/audit/push-report.js +66 -0
  8. package/dist/audit/push-report.js.map +1 -0
  9. package/dist/audit-recorder-K1Ns3tfC.d.ts +31 -0
  10. package/dist/auth/authenticate.d.ts +14 -0
  11. package/dist/auth/authenticate.js +59 -0
  12. package/dist/auth/authenticate.js.map +1 -0
  13. package/dist/auth/authorize.d.ts +12 -0
  14. package/dist/auth/authorize.js +57 -0
  15. package/dist/auth/authorize.js.map +1 -0
  16. package/dist/auth/read-token-auth.d.ts +60 -0
  17. package/dist/auth/read-token-auth.js +83 -0
  18. package/dist/auth/read-token-auth.js.map +1 -0
  19. package/dist/cache/decision-cache.d.ts +2 -0
  20. package/dist/cache/decision-cache.js +45 -0
  21. package/dist/cache/decision-cache.js.map +1 -0
  22. package/dist/commit-workflow-schemas-BWlg7bZR.d.ts +95 -0
  23. package/dist/decision-cache-87U32iSj.d.ts +24 -0
  24. package/dist/gateway-app.d.ts +69 -0
  25. package/dist/gateway-app.js +80 -0
  26. package/dist/gateway-app.js.map +1 -0
  27. package/dist/gateway-context-Boh9I0mk.d.ts +54 -0
  28. package/dist/gateway-env-DnsBU4Pq.d.ts +40 -0
  29. package/dist/gateway-worker.d.ts +13 -0
  30. package/dist/gateway-worker.js +22 -0
  31. package/dist/gateway-worker.js.map +1 -0
  32. package/dist/git-route-Spxi09Rm.d.ts +22 -0
  33. package/dist/health.d.ts +6 -0
  34. package/dist/health.js +16 -0
  35. package/dist/health.js.map +1 -0
  36. package/dist/logger-BZ1zyKLb.d.ts +27 -0
  37. package/dist/logging/logger.d.ts +2 -0
  38. package/dist/logging/logger.js +15 -0
  39. package/dist/logging/logger.js.map +1 -0
  40. package/dist/on-push-DTREOB__.d.ts +62 -0
  41. package/dist/policy/branch-policy.d.ts +24 -0
  42. package/dist/policy/branch-policy.js +125 -0
  43. package/dist/policy/branch-policy.js.map +1 -0
  44. package/dist/policy/enforce-branch-policy.d.ts +30 -0
  45. package/dist/policy/enforce-branch-policy.js +214 -0
  46. package/dist/policy/enforce-branch-policy.js.map +1 -0
  47. package/dist/policy/fast-forward.d.ts +32 -0
  48. package/dist/policy/fast-forward.js +95 -0
  49. package/dist/policy/fast-forward.js.map +1 -0
  50. package/dist/policy/ref-pattern.d.ts +7 -0
  51. package/dist/policy/ref-pattern.js +25 -0
  52. package/dist/policy/ref-pattern.js.map +1 -0
  53. package/dist/policy/rule-branch-policy.d.ts +17 -0
  54. package/dist/policy/rule-branch-policy.js +69 -0
  55. package/dist/policy/rule-branch-policy.js.map +1 -0
  56. package/dist/proxy/defer.d.ts +8 -0
  57. package/dist/proxy/defer.js +15 -0
  58. package/dist/proxy/defer.js.map +1 -0
  59. package/dist/proxy/forward-read.d.ts +11 -0
  60. package/dist/proxy/forward-read.js +53 -0
  61. package/dist/proxy/forward-read.js.map +1 -0
  62. package/dist/proxy/gateway-deps.d.ts +39 -0
  63. package/dist/proxy/gateway-deps.js +0 -0
  64. package/dist/proxy/gateway-env.d.ts +2 -0
  65. package/dist/proxy/gateway-env.js +0 -0
  66. package/dist/proxy/git-responses.d.ts +25 -0
  67. package/dist/proxy/git-responses.js +83 -0
  68. package/dist/proxy/git-responses.js.map +1 -0
  69. package/dist/proxy/git-route.d.ts +2 -0
  70. package/dist/proxy/git-route.js +34 -0
  71. package/dist/proxy/git-route.js.map +1 -0
  72. package/dist/proxy/push-events.d.ts +28 -0
  73. package/dist/proxy/push-events.js +65 -0
  74. package/dist/proxy/push-events.js.map +1 -0
  75. package/dist/proxy/push-guard.d.ts +43 -0
  76. package/dist/proxy/push-guard.js +81 -0
  77. package/dist/proxy/push-guard.js.map +1 -0
  78. package/dist/proxy/push-options.d.ts +16 -0
  79. package/dist/proxy/push-options.js +33 -0
  80. package/dist/proxy/push-options.js.map +1 -0
  81. package/dist/proxy/receive-pack.d.ts +17 -0
  82. package/dist/proxy/receive-pack.js +244 -0
  83. package/dist/proxy/receive-pack.js.map +1 -0
  84. package/dist/proxy/request-log.d.ts +13 -0
  85. package/dist/proxy/request-log.js +41 -0
  86. package/dist/proxy/request-log.js.map +1 -0
  87. package/dist/proxy/resolve-route.d.ts +9 -0
  88. package/dist/proxy/resolve-route.js +22 -0
  89. package/dist/proxy/resolve-route.js.map +1 -0
  90. package/dist/proxy/upstream-call.d.ts +23 -0
  91. package/dist/proxy/upstream-call.js +63 -0
  92. package/dist/proxy/upstream-call.js.map +1 -0
  93. package/dist/proxy/upstream.d.ts +2 -0
  94. package/dist/proxy/upstream.js +68 -0
  95. package/dist/proxy/upstream.js.map +1 -0
  96. package/dist/push-event-f-5TsFUY.d.ts +15 -0
  97. package/dist/push-policy/changed-paths.d.ts +26 -0
  98. package/dist/push-policy/changed-paths.js +117 -0
  99. package/dist/push-policy/changed-paths.js.map +1 -0
  100. package/dist/push-policy/pushed-objects.d.ts +30 -0
  101. package/dist/push-policy/pushed-objects.js +76 -0
  102. package/dist/push-policy/pushed-objects.js.map +1 -0
  103. package/dist/push-policy/run-push-policy.d.ts +35 -0
  104. package/dist/push-policy/run-push-policy.js +77 -0
  105. package/dist/push-policy/run-push-policy.js.map +1 -0
  106. package/dist/push-policy/tree-diff.d.ts +21 -0
  107. package/dist/push-policy/tree-diff.js +78 -0
  108. package/dist/push-policy/tree-diff.js.map +1 -0
  109. package/dist/push-policy/uncheckable.d.ts +14 -0
  110. package/dist/push-policy/uncheckable.js +25 -0
  111. package/dist/push-policy/uncheckable.js.map +1 -0
  112. package/dist/rpc/branch-methods.d.ts +16 -0
  113. package/dist/rpc/branch-methods.js +43 -0
  114. package/dist/rpc/branch-methods.js.map +1 -0
  115. package/dist/rpc/commit-attempt.d.ts +27 -0
  116. package/dist/rpc/commit-attempt.js +85 -0
  117. package/dist/rpc/commit-attempt.js.map +1 -0
  118. package/dist/rpc/commit-graph.d.ts +20 -0
  119. package/dist/rpc/commit-graph.js +38 -0
  120. package/dist/rpc/commit-graph.js.map +1 -0
  121. package/dist/rpc/commit-method.d.ts +13 -0
  122. package/dist/rpc/commit-method.js +30 -0
  123. package/dist/rpc/commit-method.js.map +1 -0
  124. package/dist/rpc/commit-source.d.ts +12 -0
  125. package/dist/rpc/commit-source.js +9 -0
  126. package/dist/rpc/commit-source.js.map +1 -0
  127. package/dist/rpc/gateway-context.d.ts +2 -0
  128. package/dist/rpc/gateway-context.js +30 -0
  129. package/dist/rpc/gateway-context.js.map +1 -0
  130. package/dist/rpc/gateway-rpc.d.ts +10 -0
  131. package/dist/rpc/gateway-rpc.js +48 -0
  132. package/dist/rpc/gateway-rpc.js.map +1 -0
  133. package/dist/rpc/gateway-service.d.ts +24 -0
  134. package/dist/rpc/gateway-service.js +63 -0
  135. package/dist/rpc/gateway-service.js.map +1 -0
  136. package/dist/rpc/history-page.d.ts +35 -0
  137. package/dist/rpc/history-page.js +122 -0
  138. package/dist/rpc/history-page.js.map +1 -0
  139. package/dist/rpc/lifecycle-methods.d.ts +12 -0
  140. package/dist/rpc/lifecycle-methods.js +39 -0
  141. package/dist/rpc/lifecycle-methods.js.map +1 -0
  142. package/dist/rpc/paint-down.d.ts +17 -0
  143. package/dist/rpc/paint-down.js +96 -0
  144. package/dist/rpc/paint-down.js.map +1 -0
  145. package/dist/rpc/promote-attempt.d.ts +21 -0
  146. package/dist/rpc/promote-attempt.js +55 -0
  147. package/dist/rpc/promote-attempt.js.map +1 -0
  148. package/dist/rpc/push-ref.d.ts +21 -0
  149. package/dist/rpc/push-ref.js +47 -0
  150. package/dist/rpc/push-ref.js.map +1 -0
  151. package/dist/rpc/read-methods.d.ts +17 -0
  152. package/dist/rpc/read-methods.js +94 -0
  153. package/dist/rpc/read-methods.js.map +1 -0
  154. package/dist/rpc/read-token.d.ts +39 -0
  155. package/dist/rpc/read-token.js +107 -0
  156. package/dist/rpc/read-token.js.map +1 -0
  157. package/dist/rpc/repo-access.d.ts +36 -0
  158. package/dist/rpc/repo-access.js +75 -0
  159. package/dist/rpc/repo-access.js.map +1 -0
  160. package/dist/rpc/sync-attempt.d.ts +23 -0
  161. package/dist/rpc/sync-attempt.js +105 -0
  162. package/dist/rpc/sync-attempt.js.map +1 -0
  163. package/dist/sync-workflow-schemas-DCNmNE5-.d.ts +57 -0
  164. package/dist/upstream-DvqMCj5N.d.ts +15 -0
  165. package/dist/workflow-starter-BqhwX6oA.d.ts +45 -0
  166. package/dist/workflows/commit-workflow-schemas.d.ts +2 -0
  167. package/dist/workflows/commit-workflow-schemas.js +84 -0
  168. package/dist/workflows/commit-workflow-schemas.js.map +1 -0
  169. package/dist/workflows/commit-workflow.d.ts +16 -0
  170. package/dist/workflows/commit-workflow.js +22 -0
  171. package/dist/workflows/commit-workflow.js.map +1 -0
  172. package/dist/workflows/on-push.d.ts +2 -0
  173. package/dist/workflows/on-push.js +90 -0
  174. package/dist/workflows/on-push.js.map +1 -0
  175. package/dist/workflows/push-event.d.ts +2 -0
  176. package/dist/workflows/push-event.js +28 -0
  177. package/dist/workflows/push-event.js.map +1 -0
  178. package/dist/workflows/run-commit-workflow.d.ts +15 -0
  179. package/dist/workflows/run-commit-workflow.js +49 -0
  180. package/dist/workflows/run-commit-workflow.js.map +1 -0
  181. package/dist/workflows/run-sync-workflow.d.ts +14 -0
  182. package/dist/workflows/run-sync-workflow.js +67 -0
  183. package/dist/workflows/run-sync-workflow.js.map +1 -0
  184. package/dist/workflows/step-errors.d.ts +15 -0
  185. package/dist/workflows/step-errors.js +24 -0
  186. package/dist/workflows/step-errors.js.map +1 -0
  187. package/dist/workflows/step-runner.d.ts +31 -0
  188. package/dist/workflows/step-runner.js +6 -0
  189. package/dist/workflows/step-runner.js.map +1 -0
  190. package/dist/workflows/sync-branch-workflow.d.ts +15 -0
  191. package/dist/workflows/sync-branch-workflow.js +21 -0
  192. package/dist/workflows/sync-branch-workflow.js.map +1 -0
  193. package/dist/workflows/sync-workflow-schemas.d.ts +2 -0
  194. package/dist/workflows/sync-workflow-schemas.js +104 -0
  195. package/dist/workflows/sync-workflow-schemas.js.map +1 -0
  196. package/dist/workflows/workflow-instance-id.d.ts +12 -0
  197. package/dist/workflows/workflow-instance-id.js +33 -0
  198. package/dist/workflows/workflow-instance-id.js.map +1 -0
  199. package/dist/workflows/workflow-runtime.d.ts +7 -0
  200. package/dist/workflows/workflow-runtime.js +11 -0
  201. package/dist/workflows/workflow-runtime.js.map +1 -0
  202. package/dist/workflows/workflow-starter.d.ts +2 -0
  203. package/dist/workflows/workflow-starter.js +40 -0
  204. package/dist/workflows/workflow-starter.js.map +1 -0
  205. package/package.json +381 -4
  206. package/src/audit/audit-recorder.ts +74 -0
  207. package/src/audit/push-report.ts +60 -0
  208. package/src/auth/authenticate.ts +68 -0
  209. package/src/auth/authorize.ts +57 -0
  210. package/src/auth/read-token-auth.ts +119 -0
  211. package/src/cache/decision-cache.ts +57 -0
  212. package/src/gateway-app.ts +147 -0
  213. package/src/gateway-worker.ts +32 -0
  214. package/src/health.ts +12 -0
  215. package/src/logging/logger.ts +40 -0
  216. package/src/policy/branch-policy.ts +119 -0
  217. package/src/policy/enforce-branch-policy.ts +213 -0
  218. package/src/policy/fast-forward.ts +136 -0
  219. package/src/policy/ref-pattern.ts +24 -0
  220. package/src/policy/rule-branch-policy.ts +76 -0
  221. package/src/proxy/defer.ts +18 -0
  222. package/src/proxy/forward-read.ts +52 -0
  223. package/src/proxy/gateway-deps.ts +43 -0
  224. package/src/proxy/gateway-env.ts +43 -0
  225. package/src/proxy/git-responses.ts +89 -0
  226. package/src/proxy/git-route.ts +49 -0
  227. package/src/proxy/push-events.ts +91 -0
  228. package/src/proxy/push-guard.ts +109 -0
  229. package/src/proxy/push-options.ts +38 -0
  230. package/src/proxy/receive-pack.ts +257 -0
  231. package/src/proxy/request-log.ts +44 -0
  232. package/src/proxy/resolve-route.ts +24 -0
  233. package/src/proxy/upstream-call.ts +71 -0
  234. package/src/proxy/upstream.ts +76 -0
  235. package/src/push-policy/changed-paths.ts +143 -0
  236. package/src/push-policy/pushed-objects.ts +88 -0
  237. package/src/push-policy/run-push-policy.ts +99 -0
  238. package/src/push-policy/tree-diff.ts +107 -0
  239. package/src/push-policy/uncheckable.ts +27 -0
  240. package/src/rpc/branch-methods.ts +57 -0
  241. package/src/rpc/commit-attempt.ts +87 -0
  242. package/src/rpc/commit-graph.ts +44 -0
  243. package/src/rpc/commit-method.ts +36 -0
  244. package/src/rpc/commit-source.ts +15 -0
  245. package/src/rpc/gateway-context.ts +77 -0
  246. package/src/rpc/gateway-rpc.ts +65 -0
  247. package/src/rpc/gateway-service.ts +85 -0
  248. package/src/rpc/history-page.ts +163 -0
  249. package/src/rpc/lifecycle-methods.ts +50 -0
  250. package/src/rpc/paint-down.ts +120 -0
  251. package/src/rpc/promote-attempt.ts +52 -0
  252. package/src/rpc/push-ref.ts +54 -0
  253. package/src/rpc/read-methods.ts +111 -0
  254. package/src/rpc/read-token.ts +135 -0
  255. package/src/rpc/repo-access.ts +112 -0
  256. package/src/rpc/sync-attempt.ts +84 -0
  257. package/src/workflows/commit-workflow-schemas.ts +95 -0
  258. package/src/workflows/commit-workflow.ts +39 -0
  259. package/src/workflows/on-push.ts +128 -0
  260. package/src/workflows/push-event.ts +41 -0
  261. package/src/workflows/run-commit-workflow.ts +45 -0
  262. package/src/workflows/run-sync-workflow.ts +52 -0
  263. package/src/workflows/step-errors.ts +26 -0
  264. package/src/workflows/step-runner.ts +36 -0
  265. package/src/workflows/sync-branch-workflow.ts +40 -0
  266. package/src/workflows/sync-workflow-schemas.ts +122 -0
  267. package/src/workflows/workflow-instance-id.ts +26 -0
  268. package/src/workflows/workflow-runtime.ts +13 -0
  269. package/src/workflows/workflow-starter.ts +69 -0
@@ -0,0 +1,28 @@
1
+ import { r as Logger } from "../logger-BZ1zyKLb.js";
2
+ import { t as OnPushHook } from "../on-push-DTREOB__.js";
3
+ import { t as PushEvent } from "../push-event-f-5TsFUY.js";
4
+ import { AuditRefOutcome } from "@leed-ai/git-gateway-contract/proxy/audit-event";
5
+ /** Most updates one push event carries (the PushEvent schema's cap); a larger push is split. */
6
+ export declare const MAX_EVENT_UPDATES = 1000;
7
+ /**
8
+ * The push events for a smart-HTTP push, from the per-ref outcomes read from the storage host's
9
+ * report-status: one event per {@link MAX_EVENT_UPDATES} updates the host reported "ok", in the
10
+ * order the push named them. Refused and unknown updates are left out; no accepted update, no
11
+ * event.
12
+ */
13
+ export declare function pushEventsFrom(repo: string, outcomes: readonly AuditRefOutcome[], pushedAt: string): PushEvent[];
14
+ /** What {@link deliverPushEvents} needs from the gateway. */
15
+ export interface PushEventSink {
16
+ readonly onPush: OnPushHook;
17
+ readonly onPushError: (error: unknown) => void;
18
+ readonly logger: Logger;
19
+ readonly now: () => Date;
20
+ }
21
+ /**
22
+ * Hands the accepted updates of a smart-HTTP push to the deployment's onPush hook, once the
23
+ * storage host's report has been read. The push has already happened, so nothing here changes the
24
+ * response: a hook failure is logged and passed to `onPushError`. When the report could not be
25
+ * read (too large, malformed) no event is sent and a warning is logged. Never rejects.
26
+ */
27
+ export declare function deliverPushEvents(sink: PushEventSink, repo: string, outcomes: Promise<readonly AuditRefOutcome[]>, requestId: string): Promise<void>;
28
+ //# sourceMappingURL=push-events.d.ts.map
@@ -0,0 +1,65 @@
1
+ import { FullRefName } from "@leed-ai/git-gateway-contract/schemas/names";
2
+ // src/proxy/push-events.ts
3
+ /** Most updates one push event carries (the PushEvent schema's cap); a larger push is split. */
4
+ const MAX_EVENT_UPDATES = 1e3;
5
+ /**
6
+ * The push events for a smart-HTTP push, from the per-ref outcomes read from the storage host's
7
+ * report-status: one event per {@link MAX_EVENT_UPDATES} updates the host reported "ok", in the
8
+ * order the push named them. Refused and unknown updates are left out; no accepted update, no
9
+ * event.
10
+ */
11
+ function pushEventsFrom(repo, outcomes, pushedAt) {
12
+ const updates = outcomes.filter((outcome) => outcome.status === "ok" && FullRefName.safeParse(outcome.ref).success).map(({ ref, oldSha, newSha }) => ({
13
+ ref,
14
+ oldSha,
15
+ newSha
16
+ }));
17
+ const events = [];
18
+ for (let start = 0; start < updates.length; start += MAX_EVENT_UPDATES) events.push({
19
+ repo,
20
+ updates: updates.slice(start, start + MAX_EVENT_UPDATES),
21
+ pushedAt
22
+ });
23
+ return events;
24
+ }
25
+ /**
26
+ * Hands the accepted updates of a smart-HTTP push to the deployment's onPush hook, once the
27
+ * storage host's report has been read. The push has already happened, so nothing here changes the
28
+ * response: a hook failure is logged and passed to `onPushError`. When the report could not be
29
+ * read (too large, malformed) no event is sent and a warning is logged. Never rejects.
30
+ */
31
+ async function deliverPushEvents(sink, repo, outcomes, requestId) {
32
+ let refs;
33
+ try {
34
+ refs = await outcomes;
35
+ } catch (error) {
36
+ report(sink, requestId, repo, error);
37
+ return;
38
+ }
39
+ if (refs.some((ref) => ref.status === "unknown")) sink.logger.log({
40
+ level: "warn",
41
+ message: "push event incomplete: the storage host report could not be read for every ref",
42
+ requestId,
43
+ repo
44
+ });
45
+ for (const event of pushEventsFrom(repo, refs, sink.now().toISOString())) try {
46
+ await sink.onPush(event);
47
+ } catch (error) {
48
+ report(sink, requestId, repo, error);
49
+ }
50
+ }
51
+ function report(sink, requestId, repo, error) {
52
+ sink.logger.log({
53
+ level: "error",
54
+ message: "onPush hook failed",
55
+ requestId,
56
+ repo,
57
+ error: error instanceof Error ? error.message : String(error)
58
+ });
59
+ try {
60
+ sink.onPushError(error);
61
+ } catch {}
62
+ }
63
+ export { MAX_EVENT_UPDATES, deliverPushEvents, pushEventsFrom };
64
+
65
+ //# sourceMappingURL=push-events.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-events.js","names":[],"sources":["../../src/proxy/push-events.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { AuditRefOutcome } from '@leed-ai/git-gateway-contract/proxy/audit-event';\nimport { FullRefName } from '@leed-ai/git-gateway-contract/schemas/names';\nimport type { RefUpdate } from '@leed-ai/git-gateway-contract/schemas/ref-update';\n\nimport type { Logger } from '../logging/logger.ts';\nimport type { OnPushHook } from '../workflows/on-push.ts';\nimport type { PushEvent } from '../workflows/push-event.ts';\n\n/** Most updates one push event carries (the PushEvent schema's cap); a larger push is split. */\nexport const MAX_EVENT_UPDATES = 1000;\n\n/**\n * The push events for a smart-HTTP push, from the per-ref outcomes read from the storage host's\n * report-status: one event per {@link MAX_EVENT_UPDATES} updates the host reported \"ok\", in the\n * order the push named them. Refused and unknown updates are left out; no accepted update, no\n * event.\n */\nexport function pushEventsFrom(\n repo: string,\n outcomes: readonly AuditRefOutcome[],\n pushedAt: string,\n): PushEvent[] {\n const updates: RefUpdate[] = outcomes\n .filter((outcome) => outcome.status === 'ok' && FullRefName.safeParse(outcome.ref).success)\n .map(({ ref, oldSha, newSha }) => ({ ref, oldSha, newSha }));\n const events: PushEvent[] = [];\n for (let start = 0; start < updates.length; start += MAX_EVENT_UPDATES) {\n events.push({ repo, updates: updates.slice(start, start + MAX_EVENT_UPDATES), pushedAt });\n }\n return events;\n}\n\n/** What {@link deliverPushEvents} needs from the gateway. */\nexport interface PushEventSink {\n readonly onPush: OnPushHook;\n readonly onPushError: (error: unknown) => void;\n readonly logger: Logger;\n readonly now: () => Date;\n}\n\n/**\n * Hands the accepted updates of a smart-HTTP push to the deployment's onPush hook, once the\n * storage host's report has been read. The push has already happened, so nothing here changes the\n * response: a hook failure is logged and passed to `onPushError`. When the report could not be\n * read (too large, malformed) no event is sent and a warning is logged. Never rejects.\n */\nexport async function deliverPushEvents(\n sink: PushEventSink,\n repo: string,\n outcomes: Promise<readonly AuditRefOutcome[]>,\n requestId: string,\n): Promise<void> {\n let refs: readonly AuditRefOutcome[];\n try {\n refs = await outcomes;\n } catch (error) {\n report(sink, requestId, repo, error);\n return;\n }\n if (refs.some((ref) => ref.status === 'unknown')) {\n sink.logger.log({\n level: 'warn',\n message: 'push event incomplete: the storage host report could not be read for every ref',\n requestId,\n repo,\n });\n }\n for (const event of pushEventsFrom(repo, refs, sink.now().toISOString())) {\n try {\n await sink.onPush(event);\n } catch (error) {\n report(sink, requestId, repo, error);\n }\n }\n}\n\nfunction report(sink: PushEventSink, requestId: string, repo: string, error: unknown): void {\n sink.logger.log({\n level: 'error',\n message: 'onPush hook failed',\n requestId,\n repo,\n error: error instanceof Error ? error.message : String(error),\n });\n try {\n sink.onPushError(error);\n } catch {\n // The error handler failed too; the failure is already logged.\n }\n}\n"],"mappings":";;;AAUA,MAAa,oBAAoB;;;;;;;AAQjC,SAAgB,eACd,MACA,UACA,UACa;CACb,MAAM,UAAuB,SAC1B,QAAQ,YAAY,QAAQ,WAAW,QAAQ,YAAY,UAAU,QAAQ,GAAG,CAAC,CAAC,OAAO,CAAC,CAC1F,KAAK,EAAE,KAAK,QAAQ,cAAc;EAAE;EAAK;EAAQ;CAAO,EAAE;CAC7D,MAAM,SAAsB,CAAC;CAC7B,KAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,SAAS,mBACnD,OAAO,KAAK;EAAE;EAAM,SAAS,QAAQ,MAAM,OAAO,QAAQ,iBAAiB;EAAG;CAAS,CAAC;CAE1F,OAAO;AACT;;;;;;;AAgBA,eAAsB,kBACpB,MACA,MACA,UACA,WACe;CACf,IAAI;CACJ,IAAI;EACF,OAAO,MAAM;CACf,SAAS,OAAO;EACd,OAAO,MAAM,WAAW,MAAM,KAAK;EACnC;CACF;CACA,IAAI,KAAK,MAAM,QAAQ,IAAI,WAAW,SAAS,GAC7C,KAAK,OAAO,IAAI;EACd,OAAO;EACP,SAAS;EACT;EACA;CACF,CAAC;CAEH,KAAK,MAAM,SAAS,eAAe,MAAM,MAAM,KAAK,IAAI,CAAC,CAAC,YAAY,CAAC,GACrE,IAAI;EACF,MAAM,KAAK,OAAO,KAAK;CACzB,SAAS,OAAO;EACd,OAAO,MAAM,WAAW,MAAM,KAAK;CACrC;AAEJ;AAEA,SAAS,OAAO,MAAqB,WAAmB,MAAc,OAAsB;CAC1F,KAAK,OAAO,IAAI;EACd,OAAO;EACP,SAAS;EACT;EACA;EACA,OAAO,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;CAC9D,CAAC;CACD,IAAI;EACF,KAAK,YAAY,KAAK;CACxB,QAAQ,CAER;AACF"}
@@ -0,0 +1,43 @@
1
+ import { RefRefusal } from "./git-responses.js";
2
+ import { PackScan } from "@leed-ai/git-gateway-core/pack/pack-scanner";
3
+ /** The error a guarded stream fails with when the push is refused; the host never sees a complete pack. */
4
+ export declare class PushRefused extends Error {
5
+ readonly name = "PushRefused";
6
+ readonly refusals: readonly RefRefusal[];
7
+ constructor(refusals: readonly RefRefusal[]);
8
+ }
9
+ /** Options of {@link guardPush}. */
10
+ export interface PushGuardOptions {
11
+ /** Bytes before the pack (the update commands), forwarded without scanning. */
12
+ readonly headLength: number;
13
+ /** Most bytes of commits the scan keeps. */
14
+ readonly maxCommitBytes: number;
15
+ /**
16
+ * Keep the whole pack (checksum included), at most this many bytes, and hand it to `decide`; a
17
+ * longer pack is refused with `tooLarge`. Absent: nothing is kept.
18
+ */
19
+ readonly keepPack?: {
20
+ readonly maxBytes: number;
21
+ readonly tooLarge: string;
22
+ };
23
+ /**
24
+ * Decides the push once the whole pack has been scanned, given the pack when `keepPack` asked
25
+ * for it (null otherwise); returns the refused updates (none to allow it).
26
+ */
27
+ readonly decide: (scan: PackScan, pack: Uint8Array | null) => Promise<readonly RefRefusal[]>;
28
+ /** Called with every refused update, scan failures included, before the stream fails. */
29
+ readonly onRefused: (refusals: readonly RefRefusal[]) => void;
30
+ /** The refs to refuse when the pack cannot be scanned, with the reason to give for each. */
31
+ readonly refuseAll: (reason: string) => readonly RefRefusal[];
32
+ }
33
+ /**
34
+ * A pass-through for a push body that scans the pack as it streams to the storage host, so the
35
+ * gateway can prove fast-forwards from commits the host does not have yet — without buffering the
36
+ * pack. Everything is forwarded as it arrives except the last 20 bytes, the pack checksum; once
37
+ * the body has ended and the scan is complete, `decide` runs, and only if it refuses nothing are
38
+ * those bytes released. With `keepPack`, the pack is also kept (bounded) for `decide` to read
39
+ * whole, as the push policy needs to compute changed paths. On a refusal (or a pack that cannot be read) the stream fails instead, so
40
+ * the host sees a truncated pack and updates no ref.
41
+ */
42
+ export declare function guardPush(options: PushGuardOptions): TransformStream<Uint8Array, Uint8Array>;
43
+ //# sourceMappingURL=push-guard.d.ts.map
@@ -0,0 +1,81 @@
1
+ import { concatBytes } from "@leed-ai/git-gateway-core/bytes";
2
+ import { PackScanner } from "@leed-ai/git-gateway-core/pack/pack-scanner";
3
+ // src/proxy/push-guard.ts
4
+ /** A pack ends with a 20-byte SHA-1 checksum; holding it back keeps the host from completing the push. */
5
+ const HELD_BYTES = 20;
6
+ /** The error a guarded stream fails with when the push is refused; the host never sees a complete pack. */
7
+ var PushRefused = class extends Error {
8
+ name = "PushRefused";
9
+ refusals;
10
+ constructor(refusals) {
11
+ super(`push refused: ${refusals.map((refusal) => refusal.ref).join(", ")}`);
12
+ this.refusals = refusals;
13
+ }
14
+ };
15
+ /**
16
+ * A pass-through for a push body that scans the pack as it streams to the storage host, so the
17
+ * gateway can prove fast-forwards from commits the host does not have yet — without buffering the
18
+ * pack. Everything is forwarded as it arrives except the last 20 bytes, the pack checksum; once
19
+ * the body has ended and the scan is complete, `decide` runs, and only if it refuses nothing are
20
+ * those bytes released. With `keepPack`, the pack is also kept (bounded) for `decide` to read
21
+ * whole, as the push policy needs to compute changed paths. On a refusal (or a pack that cannot be read) the stream fails instead, so
22
+ * the host sees a truncated pack and updates no ref.
23
+ */
24
+ function guardPush(options) {
25
+ const scanner = new PackScanner({ maxCommitBytes: options.maxCommitBytes });
26
+ let position = 0;
27
+ let held = /* @__PURE__ */ new Uint8Array(0);
28
+ const kept = [];
29
+ let keptBytes = 0;
30
+ const refuse = (refusals) => {
31
+ options.onRefused(refusals);
32
+ return new PushRefused(refusals);
33
+ };
34
+ const unreadable = (error) => {
35
+ const detail = error instanceof Error ? error.message : String(error);
36
+ return refuse(options.refuseAll(`the pushed pack could not be checked: ${detail}`));
37
+ };
38
+ return new TransformStream({
39
+ async transform(chunk, controller) {
40
+ const start = position;
41
+ position += chunk.length;
42
+ if (position > options.headLength) {
43
+ const packBytes = chunk.subarray(Math.max(0, options.headLength - start));
44
+ if (options.keepPack !== void 0) {
45
+ keptBytes += packBytes.length;
46
+ if (keptBytes > options.keepPack.maxBytes) throw refuse(options.refuseAll(options.keepPack.tooLarge));
47
+ kept.push(packBytes.slice());
48
+ }
49
+ try {
50
+ await scanner.push(packBytes);
51
+ } catch (error) {
52
+ throw unreadable(error);
53
+ }
54
+ }
55
+ if (chunk.length >= HELD_BYTES) {
56
+ if (held.length > 0) controller.enqueue(held);
57
+ controller.enqueue(chunk.subarray(0, chunk.length - HELD_BYTES));
58
+ held = chunk.slice(chunk.length - HELD_BYTES);
59
+ return;
60
+ }
61
+ const joined = concatBytes([held, chunk]);
62
+ const release = Math.max(0, joined.length - HELD_BYTES);
63
+ if (release > 0) controller.enqueue(joined.slice(0, release));
64
+ held = joined.slice(release);
65
+ },
66
+ async flush(controller) {
67
+ let scan;
68
+ try {
69
+ scan = scanner.finish();
70
+ } catch (error) {
71
+ throw unreadable(error);
72
+ }
73
+ const refusals = await options.decide(scan, options.keepPack === void 0 ? null : concatBytes(kept));
74
+ if (refusals.length > 0) throw refuse(refusals);
75
+ if (held.length > 0) controller.enqueue(held);
76
+ }
77
+ });
78
+ }
79
+ export { PushRefused, guardPush };
80
+
81
+ //# sourceMappingURL=push-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-guard.js","names":[],"sources":["../../src/proxy/push-guard.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { concatBytes } from '@leed-ai/git-gateway-core/bytes';\nimport { PackScanner, type PackScan } from '@leed-ai/git-gateway-core/pack/pack-scanner';\n\nimport type { RefRefusal } from './git-responses.ts';\n\n/** A pack ends with a 20-byte SHA-1 checksum; holding it back keeps the host from completing the push. */\nconst HELD_BYTES = 20;\n\n/** The error a guarded stream fails with when the push is refused; the host never sees a complete pack. */\nexport class PushRefused extends Error {\n override readonly name = 'PushRefused';\n readonly refusals: readonly RefRefusal[];\n\n constructor(refusals: readonly RefRefusal[]) {\n super(`push refused: ${refusals.map((refusal) => refusal.ref).join(', ')}`);\n this.refusals = refusals;\n }\n}\n\n/** Options of {@link guardPush}. */\nexport interface PushGuardOptions {\n /** Bytes before the pack (the update commands), forwarded without scanning. */\n readonly headLength: number;\n /** Most bytes of commits the scan keeps. */\n readonly maxCommitBytes: number;\n /**\n * Keep the whole pack (checksum included), at most this many bytes, and hand it to `decide`; a\n * longer pack is refused with `tooLarge`. Absent: nothing is kept.\n */\n readonly keepPack?: { readonly maxBytes: number; readonly tooLarge: string };\n /**\n * Decides the push once the whole pack has been scanned, given the pack when `keepPack` asked\n * for it (null otherwise); returns the refused updates (none to allow it).\n */\n readonly decide: (scan: PackScan, pack: Uint8Array | null) => Promise<readonly RefRefusal[]>;\n /** Called with every refused update, scan failures included, before the stream fails. */\n readonly onRefused: (refusals: readonly RefRefusal[]) => void;\n /** The refs to refuse when the pack cannot be scanned, with the reason to give for each. */\n readonly refuseAll: (reason: string) => readonly RefRefusal[];\n}\n\n/**\n * A pass-through for a push body that scans the pack as it streams to the storage host, so the\n * gateway can prove fast-forwards from commits the host does not have yet — without buffering the\n * pack. Everything is forwarded as it arrives except the last 20 bytes, the pack checksum; once\n * the body has ended and the scan is complete, `decide` runs, and only if it refuses nothing are\n * those bytes released. With `keepPack`, the pack is also kept (bounded) for `decide` to read\n * whole, as the push policy needs to compute changed paths. On a refusal (or a pack that cannot be read) the stream fails instead, so\n * the host sees a truncated pack and updates no ref.\n */\nexport function guardPush(options: PushGuardOptions): TransformStream<Uint8Array, Uint8Array> {\n const scanner = new PackScanner({ maxCommitBytes: options.maxCommitBytes });\n let position = 0;\n let held = new Uint8Array(0);\n const kept: Uint8Array[] = [];\n let keptBytes = 0;\n\n const refuse = (refusals: readonly RefRefusal[]): PushRefused => {\n options.onRefused(refusals);\n return new PushRefused(refusals);\n };\n const unreadable = (error: unknown): PushRefused => {\n const detail = error instanceof Error ? error.message : String(error);\n return refuse(options.refuseAll(`the pushed pack could not be checked: ${detail}`));\n };\n\n return new TransformStream<Uint8Array, Uint8Array>({\n async transform(chunk, controller) {\n const start = position;\n position += chunk.length;\n if (position > options.headLength) {\n const packBytes = chunk.subarray(Math.max(0, options.headLength - start));\n if (options.keepPack !== undefined) {\n keptBytes += packBytes.length;\n if (keptBytes > options.keepPack.maxBytes)\n throw refuse(options.refuseAll(options.keepPack.tooLarge));\n kept.push(packBytes.slice());\n }\n try {\n await scanner.push(packBytes);\n } catch (error) {\n throw unreadable(error);\n }\n }\n if (chunk.length >= HELD_BYTES) {\n if (held.length > 0) controller.enqueue(held);\n controller.enqueue(chunk.subarray(0, chunk.length - HELD_BYTES));\n held = chunk.slice(chunk.length - HELD_BYTES);\n return;\n }\n const joined = concatBytes([held, chunk]);\n const release = Math.max(0, joined.length - HELD_BYTES);\n if (release > 0) controller.enqueue(joined.slice(0, release));\n held = joined.slice(release);\n },\n async flush(controller) {\n let scan: PackScan;\n try {\n scan = scanner.finish();\n } catch (error) {\n throw unreadable(error);\n }\n const refusals = await options.decide(scan, options.keepPack === undefined ? null : concatBytes(kept));\n if (refusals.length > 0) throw refuse(refusals);\n if (held.length > 0) controller.enqueue(held);\n },\n });\n}\n"],"mappings":";;;;AAOA,MAAM,aAAa;;AAGnB,IAAa,cAAb,cAAiC,MAAM;CACrC,OAAyB;CACzB;CAEA,YAAY,UAAiC;EAC3C,MAAM,iBAAiB,SAAS,KAAK,YAAY,QAAQ,GAAG,CAAC,CAAC,KAAK,IAAI,GAAG;EAC1E,KAAK,WAAW;CAClB;AACF;;;;;;;;;;AAiCA,SAAgB,UAAU,SAAoE;CAC5F,MAAM,U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GAC5D,OAAO,OAAO,MAAM,OAAO;EAC7B;EACA,MAAM,MAAM,YAAY;GACtB,IAAI;GACJ,IAAI;IACF,OAAO,QAAQ,OAAO;GACxB,SAAS,OAAO;IACd,MAAM,WAAW,KAAK;GACxB;GACA,MAAM,WAAW,MAAM,QAAQ,OAAO,MAAM,QAAQ,aAAa,KAAA,IAAY,OAAO,YAAY,IAAI,CAAC;GACrG,IAAI,SAAS,SAAS,GAAG,MAAM,OAAO,QAAQ;GAC9C,IAAI,KAAK,SAAS,GAAG,WAAW,QAAQ,IAAI;EAC9C;CACF,CAAC;AACH"}
@@ -0,0 +1,16 @@
1
+ import { ReceivePackRequest } from "@leed-ai/git-gateway-core/schemas/receive-pack";
2
+ /** The name of a push option: the part of `<name>[=<value>]` before the first "=". */
3
+ export declare function pushOptionName(option: string): string;
4
+ /**
5
+ * The names of a push's options that are not on the allowlist, deduplicated, in the order sent.
6
+ * A storage host acts on push options with the gateway's own credential — GitLab opens and
7
+ * auto-merges merge requests (`merge_request.*`) and sets CI variables (`ci.variable`) — so an
8
+ * option outside the allowlist would let a push reach refs the branch policy never saw.
9
+ */
10
+ export declare function disallowedPushOptions(request: Pick<ReceivePackRequest, 'pushOptions'>, allowed: readonly string[]): string[];
11
+ /**
12
+ * The reason a push refused for its options is given: the option names only (a value may be a
13
+ * secret, such as a CI variable), each cut to 100 characters, at most five of them.
14
+ */
15
+ export declare function pushOptionsReason(names: readonly string[]): string;
16
+ //# sourceMappingURL=push-options.d.ts.map
@@ -0,0 +1,33 @@
1
+ // src/proxy/push-options.ts
2
+ /** The name of a push option: the part of `<name>[=<value>]` before the first "=". */
3
+ function pushOptionName(option) {
4
+ const equals = option.indexOf("=");
5
+ return equals === -1 ? option : option.slice(0, equals);
6
+ }
7
+ /**
8
+ * The names of a push's options that are not on the allowlist, deduplicated, in the order sent.
9
+ * A storage host acts on push options with the gateway's own credential — GitLab opens and
10
+ * auto-merges merge requests (`merge_request.*`) and sets CI variables (`ci.variable`) — so an
11
+ * option outside the allowlist would let a push reach refs the branch policy never saw.
12
+ */
13
+ function disallowedPushOptions(request, allowed) {
14
+ const permitted = new Set(allowed);
15
+ const refused = /* @__PURE__ */ new Set();
16
+ for (const option of request.pushOptions) {
17
+ const name = pushOptionName(option);
18
+ if (!permitted.has(name)) refused.add(name);
19
+ }
20
+ return [...refused];
21
+ }
22
+ /**
23
+ * The reason a push refused for its options is given: the option names only (a value may be a
24
+ * secret, such as a CI variable), each cut to 100 characters, at most five of them.
25
+ */
26
+ function pushOptionsReason(names) {
27
+ const shown = names.slice(0, 5).map((name) => JSON.stringify(name.slice(0, 100)));
28
+ const more = names.length > 5 ? ` and ${names.length - 5} more` : "";
29
+ return `${names.length === 1 ? "push option" : "push options"} ${shown.join(", ")}${more} not allowed by this gateway`;
30
+ }
31
+ export { disallowedPushOptions, pushOptionName, pushOptionsReason };
32
+
33
+ //# sourceMappingURL=push-options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"push-options.js","names":[],"sources":["../../src/proxy/push-options.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { ReceivePackRequest } from '@leed-ai/git-gateway-core/schemas/receive-pack';\n\n/** The name of a push option: the part of `<name>[=<value>]` before the first \"=\". */\nexport function pushOptionName(option: string): string {\n const equals = option.indexOf('=');\n return equals === -1 ? option : option.slice(0, equals);\n}\n\n/**\n * The names of a push's options that are not on the allowlist, deduplicated, in the order sent.\n * A storage host acts on push options with the gateway's own credential — GitLab opens and\n * auto-merges merge requests (`merge_request.*`) and sets CI variables (`ci.variable`) — so an\n * option outside the allowlist would let a push reach refs the branch policy never saw.\n */\nexport function disallowedPushOptions(\n request: Pick<ReceivePackRequest, 'pushOptions'>,\n allowed: readonly string[],\n): string[] {\n const permitted = new Set(allowed);\n const refused = new Set<string>();\n for (const option of request.pushOptions) {\n const name = pushOptionName(option);\n if (!permitted.has(name)) refused.add(name);\n }\n return [...refused];\n}\n\n/**\n * The reason a push refused for its options is given: the option names only (a value may be a\n * secret, such as a CI variable), each cut to 100 characters, at most five of them.\n */\nexport function pushOptionsReason(names: readonly string[]): string {\n const shown = names.slice(0, 5).map((name) => JSON.stringify(name.slice(0, 100)));\n const more = names.length > 5 ? ` and ${names.length - 5} more` : '';\n const noun = names.length === 1 ? 'push option' : 'push options';\n return `${noun} ${shown.join(', ')}${more} not allowed by this gateway`;\n}\n"],"mappings":";;AAIA,SAAgB,eAAe,QAAwB;CACrD,MAAM,SAAS,OAAO,QAAQ,GAAG;CACjC,OAAO,WAAW,KAAK,SAAS,OAAO,MAAM,GAAG,MAAM;AACxD;;;;;;;AAQA,SAAgB,sBACd,SACA,SACU;CACV,MAAM,YAAY,IAAI,IAAI,OAAO;CACjC,MAAM,0BAAU,IAAI,IAAY;CAChC,KAAK,MAAM,UAAU,QAAQ,aAAa;EACxC,MAAM,OAAO,eAAe,MAAM;EAClC,IAAI,CAAC,UAAU,IAAI,IAAI,GAAG,QAAQ,IAAI,IAAI;CAC5C;CACA,OAAO,CAAC,GAAG,OAAO;AACpB;;;;;AAMA,SAAgB,kBAAkB,OAAkC;CAClE,MAAM,QAAQ,MAAM,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,SAAS,KAAK,UAAU,KAAK,MAAM,GAAG,GAAG,CAAC,CAAC;CAChF,MAAM,OAAO,MAAM,SAAS,IAAI,QAAQ,MAAM,SAAS,EAAE,SAAS;CAElE,OAAO,GADM,MAAM,WAAW,IAAI,gBAAgB,eACnC,GAAG,MAAM,KAAK,IAAI,IAAI,KAAK;AAC5C"}
@@ -0,0 +1,17 @@
1
+ import { GatewayDeps } from "./gateway-deps.js";
2
+ import { n as GatewayEnv } from "../gateway-env-DnsBU4Pq.js";
3
+ import { Handler } from "hono";
4
+ /**
5
+ * Forwards a push the branch policy let through. When fast-forwards remain to be proven from the
6
+ * pack, or the push policy is to be given changed paths computed from it, the body streams through a guard that scans it and holds back the pack checksum until
7
+ * they are; a refusal then fails the upstream request (the host gets a truncated pack and updates
8
+ * nothing) and the client is told in-protocol which refs were refused and why. The host's answer
9
+ * is held until that verdict is known — and when the host's request fails first, the verdict is
10
+ * still awaited (at most `maxVerdictWaitMs`), so a refusal is never mistaken for a storage
11
+ * failure — and the push is audited only after it; otherwise it
12
+ * streams back untouched. When an audit hook or an onPush hook is set, a copy of the answer is
13
+ * read for per-ref outcomes: the audit event gets them, and the refs the host accepted go to the
14
+ * onPush hook as push events, both after the response through `waitUntil`.
15
+ */
16
+ export declare function receivePack(deps: GatewayDeps): Handler<GatewayEnv>;
17
+ //# sourceMappingURL=receive-pack.d.ts.map
@@ -0,0 +1,244 @@
1
+ import { readPushOutcomes, rejectedOutcomes, unknownOutcomes } from "../audit/push-report.js";
2
+ import { provePending } from "../policy/branch-policy.js";
3
+ import { refuseAll } from "../policy/enforce-branch-policy.js";
4
+ import { deferWith } from "./defer.js";
5
+ import { refusePush, textResponse } from "./git-responses.js";
6
+ import { deliverPushEvents } from "./push-events.js";
7
+ import { judgeChangedPaths } from "../push-policy/run-push-policy.js";
8
+ import { guardPush } from "./push-guard.js";
9
+ import { callUpstream, streamToClient } from "./upstream-call.js";
10
+ // src/proxy/receive-pack.ts
11
+ /** Bytes of a host report read for push events when the audit report is switched off (1 MiB). */
12
+ const DEFAULT_REPORT_BYTES = 1048576;
13
+ /** The reason given for every update when proving the push failed unexpectedly. */
14
+ const UNCHECKED_REASON = "the push could not be checked; try again later";
15
+ /** Waits for `promise`, but at most `ms` milliseconds. */
16
+ async function within(promise, ms) {
17
+ let timer;
18
+ const timeout = new Promise((resolve) => {
19
+ timer = setTimeout(resolve, ms);
20
+ });
21
+ await Promise.race([promise, timeout]);
22
+ clearTimeout(timer);
23
+ }
24
+ /**
25
+ * Holds a 2xx storage host answer back until the push guard has decided, so a host that answers
26
+ * before reading the whole body cannot carry a push past a refusal made later. Returns once the
27
+ * guard's verdict is in, or once the host's answer has ended without one (the host stopped
28
+ * reading, so it never got the pack checksum and updated nothing); the answer is buffered by the
29
+ * tee meanwhile and handed back whole. On a refusal the watching branch is cancelled as well.
30
+ */
31
+ async function awaitVerdict(upstream, verdict, isRefused) {
32
+ const [watched, kept] = (upstream.body ?? new Blob([]).stream()).tee();
33
+ const reader = watched.getReader();
34
+ const ended = (async () => {
35
+ try {
36
+ for (let next = await reader.read(); !next.done; next = await reader.read());
37
+ } catch {}
38
+ })();
39
+ await Promise.race([verdict, ended]);
40
+ if (isRefused()) await reader.cancel().catch(() => void 0);
41
+ const init = {
42
+ status: upstream.status,
43
+ statusText: upstream.statusText,
44
+ headers: upstream.headers
45
+ };
46
+ return {
47
+ ok: true,
48
+ response: new Response(kept, init)
49
+ };
50
+ }
51
+ /**
52
+ * Forwards a push the branch policy let through. When fast-forwards remain to be proven from the
53
+ * pack, or the push policy is to be given changed paths computed from it, the body streams through a guard that scans it and holds back the pack checksum until
54
+ * they are; a refusal then fails the upstream request (the host gets a truncated pack and updates
55
+ * nothing) and the client is told in-protocol which refs were refused and why. The host's answer
56
+ * is held until that verdict is known — and when the host's request fails first, the verdict is
57
+ * still awaited (at most `maxVerdictWaitMs`), so a refusal is never mistaken for a storage
58
+ * failure — and the push is audited only after it; otherwise it
59
+ * streams back untouched. When an audit hook or an onPush hook is set, a copy of the answer is
60
+ * read for per-ref outcomes: the audit event gets them, and the refs the host accepted go to the
61
+ * onPush hook as push events, both after the response through `waitUntil`.
62
+ */
63
+ function receivePack(deps) {
64
+ return async (context) => {
65
+ const requestId = context.get("requestId");
66
+ const principal = context.get("principal");
67
+ const git = context.get("git");
68
+ const push = context.get("push");
69
+ const defer = deferWith(context);
70
+ const commands = push.request.commands;
71
+ let refused = null;
72
+ /** Settles once the guard has allowed or refused the push, or will never decide it. */
73
+ const { promise: verdict, resolve: settleVerdict } = Promise.withResolvers();
74
+ let deciding = false;
75
+ const { policyUpdates } = push;
76
+ const guarded = push.pending.length > 0 || policyUpdates !== null;
77
+ if (push.pending.length > 0) deps.logger.log({
78
+ level: "debug",
79
+ message: "proving fast-forwards from the pushed pack",
80
+ requestId,
81
+ repo: git.repo,
82
+ refs: push.pending.map(({ update }) => update.ref)
83
+ });
84
+ let body = push.body;
85
+ if (guarded) {
86
+ const { pushPolicy } = deps;
87
+ const maxPackBytes = deps.config.maxPushPolicyPackBytes;
88
+ const guard = guardPush({
89
+ headLength: push.headLength,
90
+ maxCommitBytes: deps.config.maxScannedCommitBytes,
91
+ ...policyUpdates === null ? {} : { keepPack: {
92
+ maxBytes: maxPackBytes,
93
+ tooLarge: `the push policy could not check this push: the pack is larger than ${maxPackBytes} bytes`
94
+ } },
95
+ decide: async (scan, pack) => {
96
+ deciding = true;
97
+ let refusals;
98
+ try {
99
+ refusals = await provePending(deps, git, push.pending, scan.commits);
100
+ if (refusals.length === 0 && policyUpdates !== null && pushPolicy !== void 0 && pack !== null) refusals = await judgeChangedPaths({
101
+ pushPolicy,
102
+ backend: deps.backend,
103
+ config: deps.config
104
+ }, {
105
+ principal,
106
+ repo: git.repo,
107
+ updates: policyUpdates
108
+ }, pack);
109
+ } catch (error) {
110
+ deps.logger.log({
111
+ level: "error",
112
+ message: "proving the push failed",
113
+ requestId,
114
+ repo: git.repo,
115
+ error: error instanceof Error ? error.message : String(error)
116
+ });
117
+ refusals = commands.map((command) => ({
118
+ ref: command.ref,
119
+ reason: UNCHECKED_REASON
120
+ }));
121
+ }
122
+ if (refusals.length === 0) settleVerdict();
123
+ return refusals;
124
+ },
125
+ onRefused: (refusals) => {
126
+ refused = refuseAll(push.request, refusals);
127
+ settleVerdict();
128
+ },
129
+ refuseAll: (reason) => commands.map((command) => ({
130
+ ref: command.ref,
131
+ reason
132
+ }))
133
+ });
134
+ push.body.pipeTo(guard.writable).catch(() => {
135
+ if (!deciding) settleVerdict();
136
+ });
137
+ body = guard.readable;
138
+ }
139
+ const refusal = (all) => {
140
+ const reasons = new Map(all.map((entry) => [entry.ref, entry.reason]));
141
+ const reason = all.find((entry) => entry.reason !== "not updated: another update in this push was refused")?.reason ?? "not updated: another update in this push was refused";
142
+ deps.audit.record({
143
+ requestId,
144
+ principal,
145
+ git,
146
+ outcome: "denied",
147
+ reason,
148
+ refs: rejectedOutcomes(push.request, reasons, reason)
149
+ }, defer, requestId);
150
+ deps.logger.log({
151
+ level: "info",
152
+ message: "push refused after scanning its pack",
153
+ requestId,
154
+ repo: git.repo,
155
+ reason
156
+ });
157
+ const response = refusePush(push.request.capabilities, all);
158
+ response.headers.set("X-Request-Id", requestId);
159
+ return response;
160
+ };
161
+ let result = null;
162
+ let failure = null;
163
+ try {
164
+ result = await callUpstream(deps, context, body);
165
+ } catch (error) {
166
+ failure = error;
167
+ }
168
+ if (guarded) {
169
+ if (result?.ok === true) result = await awaitVerdict(result.response, verdict, () => refused !== null);
170
+ else if (refused === null) await within(verdict, deps.config.maxVerdictWaitMs);
171
+ }
172
+ if (refused !== null) {
173
+ await result?.response.body?.cancel().catch(() => void 0);
174
+ return refusal(refused);
175
+ }
176
+ if (result === null) {
177
+ deps.logger.log({
178
+ level: "error",
179
+ message: "storage host unreachable",
180
+ requestId,
181
+ repo: git.repo,
182
+ error: failure instanceof Error ? failure.message : String(failure)
183
+ });
184
+ const reason = "The storage backend is unreachable; try again later";
185
+ deps.audit.record({
186
+ requestId,
187
+ principal,
188
+ git,
189
+ outcome: "failed",
190
+ reason,
191
+ refs: unknownOutcomes(push.request)
192
+ }, defer, requestId);
193
+ return textResponse(502, reason, { "X-Request-Id": requestId });
194
+ }
195
+ if (!result.ok) {
196
+ deps.audit.record({
197
+ requestId,
198
+ principal,
199
+ git,
200
+ outcome: "failed",
201
+ reason: result.reason,
202
+ refs: unknownOutcomes(push.request)
203
+ }, defer, requestId);
204
+ return result.response;
205
+ }
206
+ const upstream = result.response;
207
+ const auditReport = deps.audit.enabled && deps.config.maxAuditReportBytes > 0;
208
+ const onPush = deps.onPush;
209
+ const unknown = {
210
+ requestId,
211
+ principal,
212
+ git,
213
+ outcome: "allowed",
214
+ reason: null
215
+ };
216
+ if (upstream.body === null || !auditReport && onPush === void 0) {
217
+ deps.audit.record({
218
+ ...unknown,
219
+ refs: unknownOutcomes(push.request)
220
+ }, defer, requestId);
221
+ return streamToClient(upstream, upstream.body, requestId);
222
+ }
223
+ const [toClient, toReport] = upstream.body.tee();
224
+ const limit = auditReport ? deps.config.maxAuditReportBytes : DEFAULT_REPORT_BYTES;
225
+ const outcomes = readPushOutcomes(toReport, push.request, limit);
226
+ deps.audit.record(auditReport ? outcomes.then((refs) => ({
227
+ ...unknown,
228
+ refs
229
+ })) : {
230
+ ...unknown,
231
+ refs: unknownOutcomes(push.request)
232
+ }, defer, requestId);
233
+ if (onPush !== void 0) defer(deliverPushEvents({
234
+ onPush,
235
+ onPushError: deps.onPushError,
236
+ logger: deps.logger,
237
+ now: deps.now
238
+ }, git.repo, outcomes, requestId));
239
+ return streamToClient(upstream, toClient, requestId);
240
+ };
241
+ }
242
+ export { receivePack };
243
+
244
+ //# sourceMappingURL=receive-pack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"receive-pack.js","names":[],"sources":["../../src/proxy/receive-pack.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Handler } from 'hono';\n\nimport { readPushOutcomes, rejectedOutcomes, unknownOutcomes } from '../audit/push-report.ts';\nimport { provePending } from '../policy/branch-policy.ts';\nimport { COLLATERAL_REASON, refuseAll } from '../policy/enforce-branch-policy.ts';\nimport { deferWith } from './defer.ts';\nimport type { GatewayDeps } from './gateway-deps.ts';\nimport type { GatewayEnv } from './gateway-env.ts';\nimport { refusePush, textResponse, type RefRefusal } from './git-responses.ts';\nimport { deliverPushEvents } from './push-events.ts';\nimport { judgeChangedPaths } from '../push-policy/run-push-policy.ts';\nimport { guardPush } from './push-guard.ts';\nimport { callUpstream, streamToClient, type UpstreamResult } from './upstream-call.ts';\n\n/** Bytes of a host report read for push events when the audit report is switched off (1 MiB). */\nconst DEFAULT_REPORT_BYTES = 1024 * 1024;\n\n/** The reason given for every update when proving the push failed unexpectedly. */\nconst UNCHECKED_REASON = 'the push could not be checked; try again later';\n\n/** Waits for `promise`, but at most `ms` milliseconds. */\nasync function within(promise: Promise<void>, ms: number): Promise<void> {\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<void>((resolve) => {\n timer = setTimeout(resolve, ms);\n });\n await Promise.race([promise, timeout]);\n clearTimeout(timer);\n}\n\n/**\n * Holds a 2xx storage host answer back until the push guard has decided, so a host that answers\n * before reading the whole body cannot carry a push past a refusal made later. Returns once the\n * guard's verdict is in, or once the host's answer has ended without one (the host stopped\n * reading, so it never got the pack checksum and updated nothing); the answer is buffered by the\n * tee meanwhile and handed back whole. On a refusal the watching branch is cancelled as well.\n */\nasync function awaitVerdict(\n upstream: Response,\n verdict: Promise<void>,\n isRefused: () => boolean,\n): Promise<UpstreamResult> {\n const [watched, kept] = (upstream.body ?? new Blob([]).stream()).tee();\n const reader = watched.getReader();\n const ended = (async () => {\n try {\n for (let next = await reader.read(); !next.done; next = await reader.read());\n } catch {\n // The host's answer failed: it is over either way.\n }\n })();\n await Promise.race([verdict, ended]);\n if (isRefused()) await reader.cancel().catch(() => undefined);\n const init = { status: upstream.status, statusText: upstream.statusText, headers: upstream.headers };\n return { ok: true, response: new Response(kept, init) };\n}\n\n/**\n * Forwards a push the branch policy let through. When fast-forwards remain to be proven from the\n * pack, or the push policy is to be given changed paths computed from it, the body streams through a guard that scans it and holds back the pack checksum until\n * they are; a refusal then fails the upstream request (the host gets a truncated pack and updates\n * nothing) and the client is told in-protocol which refs were refused and why. The host's answer\n * is held until that verdict is known — and when the host's request fails first, the verdict is\n * still awaited (at most `maxVerdictWaitMs`), so a refusal is never mistaken for a storage\n * failure — and the push is audited only after it; otherwise it\n * streams back untouched. When an audit hook or an onPush hook is set, a copy of the answer is\n * read for per-ref outcomes: the audit event gets them, and the refs the host accepted go to the\n * onPush hook as push events, both after the response through `waitUntil`.\n */\nexport function receivePack(deps: GatewayDeps): Handler<GatewayEnv> {\n return async (context) => {\n const requestId = context.get('requestId');\n const principal = context.get('principal');\n const git = context.get('git');\n const push = context.get('push');\n const defer = deferWith(context);\n const commands = push.request.commands;\n let refused: readonly RefRefusal[] | null = null;\n /** Settles once the guard has allowed or refused the push, or will never decide it. */\n const { promise: verdict, resolve: settleVerdict } = Promise.withResolvers<void>();\n let deciding = false;\n const { policyUpdates } = push;\n const guarded = push.pending.length > 0 || policyUpdates !== null;\n if (push.pending.length > 0) {\n deps.logger.log({\n level: 'debug',\n message: 'proving fast-forwards from the pushed pack',\n requestId,\n repo: git.repo,\n refs: push.pending.map(({ update }) => update.ref),\n });\n }\n let body = push.body;\n if (guarded) {\n const { pushPolicy } = deps;\n const maxPackBytes = deps.config.maxPushPolicyPackBytes;\n const guard = guardPush({\n headLength: push.headLength,\n maxCommitBytes: deps.config.maxScannedCommitBytes,\n ...(policyUpdates === null\n ? {}\n : {\n keepPack: {\n maxBytes: maxPackBytes,\n tooLarge: `the push policy could not check this push: the pack is larger than ${maxPackBytes} bytes`,\n },\n }),\n decide: async (scan, pack) => {\n deciding = true;\n let refusals: readonly RefRefusal[];\n try {\n refusals = await provePending(deps, git, push.pending, scan.commits);\n if (\n refusals.length === 0 &&\n policyUpdates !== null &&\n pushPolicy !== undefined &&\n pack !== null\n ) {\n refusals = await judgeChangedPaths(\n { pushPolicy, backend: deps.backend, config: deps.config },\n { principal, repo: git.repo, updates: policyUpdates },\n pack,\n );\n }\n } catch (error) {\n deps.logger.log({\n level: 'error',\n message: 'proving the push failed',\n requestId,\n repo: git.repo,\n error: error instanceof Error ? error.message : String(error),\n });\n refusals = commands.map((command) => ({ ref: command.ref, reason: UNCHECKED_REASON }));\n }\n if (refusals.length === 0) settleVerdict();\n return refusals;\n },\n onRefused: (refusals) => {\n refused = refuseAll(push.request, refusals);\n settleVerdict();\n },\n refuseAll: (reason) => commands.map((command) => ({ ref: command.ref, reason })),\n });\n // The pipe fails when the host stops reading (or the client stops sending); if that happens\n // before the pack has been scanned, no verdict will ever come.\n push.body.pipeTo(guard.writable).catch(() => {\n if (!deciding) settleVerdict();\n });\n body = guard.readable;\n }\n const refusal = (all: readonly RefRefusal[]): Response => {\n const reasons = new Map(all.map((entry) => [entry.ref, entry.reason]));\n const reason = all.find((entry) => entry.reason !== COLLATERAL_REASON)?.reason ?? COLLATERAL_REASON;\n deps.audit.record(\n {\n requestId,\n principal,\n git,\n outcome: 'denied',\n reason,\n refs: rejectedOutcomes(push.request, reasons, reason),\n },\n defer,\n requestId,\n );\n deps.logger.log({\n level: 'info',\n message: 'push refused after scanning its pack',\n requestId,\n repo: git.repo,\n reason,\n });\n const response = refusePush(push.request.capabilities, all);\n response.headers.set('X-Request-Id', requestId);\n return response;\n };\n let result: UpstreamResult | null = null;\n let failure: unknown = null;\n try {\n result = await callUpstream(deps, context, body);\n } catch (error) {\n failure = error;\n }\n if (guarded) {\n if (result?.ok === true) result = await awaitVerdict(result.response, verdict, () => refused !== null);\n // A refusal fails the host's request by design (the pack is cut short), and the host may\n // notice before the guard has recorded its verdict: wait for it, so a refused push is\n // answered in-protocol rather than as a storage failure.\n else if (refused === null) await within(verdict, deps.config.maxVerdictWaitMs);\n }\n if (refused !== null) {\n await result?.response.body?.cancel().catch(() => undefined);\n return refusal(refused);\n }\n if (result === null) {\n deps.logger.log({\n level: 'error',\n message: 'storage host unreachable',\n requestId,\n repo: git.repo,\n error: failure instanceof Error ? failure.message : String(failure),\n });\n const reason = 'The storage backend is unreachable; try again later';\n deps.audit.record(\n { requestId, principal, git, outcome: 'failed', reason, refs: unknownOutcomes(push.request) },\n defer,\n requestId,\n );\n return textResponse(502, reason, { 'X-Request-Id': requestId });\n }\n if (!result.ok) {\n deps.audit.record(\n {\n requestId,\n principal,\n git,\n outcome: 'failed',\n reason: result.reason,\n refs: unknownOutcomes(push.request),\n },\n defer,\n requestId,\n );\n return result.response;\n }\n const upstream = result.response;\n const auditReport = deps.audit.enabled && deps.config.maxAuditReportBytes > 0;\n const onPush = deps.onPush;\n const unknown = { requestId, principal, git, outcome: 'allowed' as const, reason: null };\n if (upstream.body === null || (!auditReport && onPush === undefined)) {\n deps.audit.record({ ...unknown, refs: unknownOutcomes(push.request) }, defer, requestId);\n return streamToClient(upstream, upstream.body, requestId);\n }\n const [toClient, toReport] = upstream.body.tee();\n const limit = auditReport ? deps.config.maxAuditReportBytes : DEFAULT_REPORT_BYTES;\n const outcomes = readPushOutcomes(toReport, push.request, limit);\n deps.audit.record(\n auditReport\n ? outcomes.then((refs) => ({ ...unknown, refs }))\n : { ...unknown, refs: unknownOutcomes(push.request) },\n defer,\n requestId,\n );\n if (onPush !== undefined) {\n defer(\n deliverPushEvents(\n { onPush, onPushError: deps.onPushError, logger: deps.logger, now: deps.now },\n git.repo,\n outcomes,\n requestId,\n ),\n );\n }\n return streamToClient(upstream, toClient, requestId);\n };\n}\n"],"mappings":";;;;;;;;;;;AAgBA,MAAM,uBAAuB;;AAG7B,MAAM,mBAAmB;;AAGzB,eAAe,OAAO,SAAwB,IAA2B;CACvE,IAAI;CACJ,MAAM,UAAU,IAAI,SAAe,YAAY;EAC7C,QAAQ,WAAW,SAAS,EAAE;CAChC,CAAC;CACD,MAAM,QAAQ,KAAK,CAAC,SAAS,OAAO,CAAC;CACrC,aAAa,KAAK;AACpB;;;;;;;;AASA,eAAe,aACb,UACA,SACA,WACyB;CACzB,MAAM,CAAC,SAAS,SAAS,SAAS,QAAQ,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,OAAO,EAAA,CAAG,IAAI;CACrE,MAAM,SAAS,QAAQ,UAAU;CACjC,MAAM,SAAS,YAAY;EACzB,IAAI;GACF,KAAK,IAAI,OAAO,MAAM,OAAO,KAAK,GAAG,CAAC,KAAK,MAAM,OAAO,MAAM,OAAO,KAAK;EAC5E,QAAQ,CAER;CACF,EAAA,CAAG;CACH,MAAM,QAAQ,KAAK,CAAC,SAAS,KAAK,CAAC;CACnC,IAAI,UAAU,GAAG,MAAM,OAAO,OAAO,CAAC,CAAC,YAAY,KAAA,CAAS;CAC5D,MAAM,OAAO;EAAE,QAAQ,SAAS;EAAQ,YA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AAU,YAAY,SAAS,KAAK,IAAI;EAC/C,MAAM,QAAQ,cAAc,KAAK,OAAO,sBAAsB;EAC9D,MAAM,WAAW,iBAAiB,UAAU,KAAK,SAAS,KAAK;EAC/D,KAAK,MAAM,OACT,cACI,SAAS,MAAM,UAAU;GAAE,GAAG;GAAS;EAAK,EAAE,IAC9C;GAAE,GAAG;GAAS,MAAM,gBAAgB,KAAK,OAAO;EAAE,GACtD,OACA,SACF;EACA,IAAI,WAAW,KAAA,GACb,MACE,kBACE;GAAE;GAAQ,aAAa,KAAK;GAAa,QAAQ,KAAK;GAAQ,KAAK,KAAK;EAAI,GAC5E,IAAI,MACJ,UACA,SACF,CACF;EAEF,OAAO,eAAe,UAAU,UAAU,SAAS;CACrD;AACF"}
@@ -0,0 +1,13 @@
1
+ import { r as Logger } from "../logger-BZ1zyKLb.js";
2
+ import { n as GatewayEnv } from "../gateway-env-DnsBU4Pq.js";
3
+ import { MiddlewareHandler } from "hono";
4
+ /** The id of a request: its Cloudflare Ray id when it has a valid one, otherwise a random UUID. */
5
+ export declare function requestIdOf(request: Request): string;
6
+ /**
7
+ * The first middleware: gives the request an id (returned as X-Request-Id) and writes one
8
+ * structured log entry when it is answered — method, path, status, duration, repository,
9
+ * endpoint and principal subject. Never the query string beyond `service`, never a header value,
10
+ * never a credential.
11
+ */
12
+ export declare function requestLog(logger: Logger, now: () => Date): MiddlewareHandler<GatewayEnv>;
13
+ //# sourceMappingURL=request-log.d.ts.map