@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 @@
1
+ {"version":3,"file":"gateway-worker.js","names":[],"sources":["../src/gateway-worker.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport type { Hono } from 'hono';\n\nimport { createGatewayApp, type GatewayAppOptions } from './gateway-app.ts';\nimport type { GatewayEnv } from './proxy/gateway-env.ts';\n\n/** The fetch handler a Worker module exports. */\nexport interface GatewayWorker<Env> {\n fetch(request: Request, env: Env, context: ExecutionContext): Promise<Response>;\n}\n\n/**\n * A Worker module's fetch handler that composes the gateway from its bindings: `setup` turns the\n * environment into the app options (backend from `env.ARTIFACTS`, authenticator from JWKS\n * settings, and so on). The app is built once per environment object, so the decision cache\n * lives as long as the isolate.\n */\nexport function createGatewayWorker<Env extends object>(\n setup: (env: Env) => GatewayAppOptions,\n): GatewayWorker<Env> {\n const apps = new WeakMap<Env, Hono<GatewayEnv>>();\n return {\n async fetch(request, env, context) {\n let app = apps.get(env);\n if (app === undefined) {\n app = createGatewayApp(setup(env));\n apps.set(env, app);\n }\n return app.fetch(request, env, context);\n },\n };\n}\n"],"mappings":";;;;;;;;AAiBA,SAAgB,oBACd,OACoB;CACpB,MAAM,uBAAO,IAAI,QAA+B;CAChD,OAAO,EACL,MAAM,MAAM,SAAS,KAAK,SAAS;EACjC,IAAI,MAAM,KAAK,IAAI,GAAG;EACtB,IAAI,QAAQ,KAAA,GAAW;GACrB,MAAM,iBAAiB,MAAM,GAAG,CAAC;GACjC,KAAK,IAAI,KAAK,GAAG;EACnB;EACA,OAAO,IAAI,MAAM,SAAS,KAAK,OAAO;CACxC,EACF;AACF"}
@@ -0,0 +1,22 @@
1
+ import { RepoName } from "@leed-ai/git-gateway-contract/schemas/names";
2
+ import { GitOperation, SmartHttpEndpoint } from "@leed-ai/git-gateway-contract/proxy/git-operation";
3
+ /** A git service as named on the wire. */
4
+ type GitServiceName = 'git-upload-pack' | 'git-receive-pack';
5
+ /** What a smart-HTTP request addresses. */
6
+ interface GitRequest {
7
+ readonly repo: RepoName;
8
+ readonly endpoint: SmartHttpEndpoint;
9
+ readonly service: GitServiceName;
10
+ readonly operation: GitOperation;
11
+ }
12
+ /** Why a path is not a smart-HTTP request the gateway serves. */
13
+ type GitRouteFailure = 'not-found' | 'dumb-http';
14
+ /**
15
+ * Resolves `/<repo>.git/info/refs?service=…`, `/<repo>.git/git-upload-pack` and
16
+ * `/<repo>.git/git-receive-pack`. An info/refs request without a smart service is "dumb-http"
17
+ * (unsupported); anything else, including a repository name the contract does not allow, is
18
+ * "not-found".
19
+ */
20
+ declare function resolveGitRequest(url: URL): GitRequest | GitRouteFailure;
21
+ export { resolveGitRequest as i, GitRouteFailure as n, GitServiceName as r, GitRequest as t };
22
+ //# sourceMappingURL=git-route-Spxi09Rm.d.ts.map
@@ -0,0 +1,6 @@
1
+ import { Hono } from "hono";
2
+ /** The service name reported when a deployment does not name itself. */
3
+ export declare const DEFAULT_SERVICE_NAME = "git-gateway";
4
+ /** A Hono app serving `GET /health` for the given deployment name. */
5
+ export declare function healthRoutes(service?: string): Hono;
6
+ //# sourceMappingURL=health.d.ts.map
package/dist/health.js ADDED
@@ -0,0 +1,16 @@
1
+ import { Hono } from "hono";
2
+ import { HealthResponse } from "@leed-ai/git-gateway-contract/health";
3
+ // src/health.ts
4
+ /** The service name reported when a deployment does not name itself. */
5
+ const DEFAULT_SERVICE_NAME = "git-gateway";
6
+ /** A Hono app serving `GET /health` for the given deployment name. */
7
+ function healthRoutes(service = DEFAULT_SERVICE_NAME) {
8
+ const body = HealthResponse.parse({
9
+ status: "ok",
10
+ service
11
+ });
12
+ return new Hono().get("/health", (context) => context.json(body));
13
+ }
14
+ export { DEFAULT_SERVICE_NAME, healthRoutes };
15
+
16
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","names":[],"sources":["../src/health.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { Hono } from 'hono';\nimport { HealthResponse } from '@leed-ai/git-gateway-contract/health';\n\n/** The service name reported when a deployment does not name itself. */\nexport const DEFAULT_SERVICE_NAME = 'git-gateway';\n\n/** A Hono app serving `GET /health` for the given deployment name. */\nexport function healthRoutes(service: string = DEFAULT_SERVICE_NAME): Hono {\n const body = HealthResponse.parse({ status: 'ok', service });\n return new Hono().get('/health', (context) => context.json(body));\n}\n"],"mappings":";;;;AAKA,MAAa,uBAAuB;;AAGpC,SAAgB,aAAa,UAAkB,sBAA4B;CACzE,MAAM,OAAO,eAAe,MAAM;EAAE,QAAQ;EAAM;CAAQ,CAAC;CAC3D,OAAO,IAAI,KAAK,CAAC,CAAC,IAAI,YAAY,YAAY,QAAQ,KAAK,IAAI,CAAC;AAClE"}
@@ -0,0 +1,27 @@
1
+ /** How serious a log entry is. */
2
+ type LogLevel = 'debug' | 'info' | 'warn' | 'error';
3
+ /**
4
+ * One structured log entry. Every entry the gateway writes carries the request id; none ever
5
+ * carries a credential, a header value or an upstream URL's query string.
6
+ */
7
+ interface LogEntry {
8
+ readonly level: LogLevel;
9
+ /** What happened, e.g. "request", "upstream failed", "audit hook failed". */
10
+ readonly message: string;
11
+ readonly requestId: string;
12
+ /** Further facts: repository, endpoint, principal subject, status, duration, reason. */
13
+ readonly [field: string]: string | number | boolean | null | readonly string[] | undefined;
14
+ }
15
+ /** Where the gateway writes its structured logs. */
16
+ interface Logger {
17
+ log(entry: LogEntry): void;
18
+ }
19
+ /** A logger that drops everything. */
20
+ declare const silentLogger: Logger;
21
+ /**
22
+ * A logger that writes each entry as one JSON line to the console, which Workers Logs and
23
+ * `wrangler tail` collect.
24
+ */
25
+ declare const consoleLogger: Logger;
26
+ export { silentLogger as a, consoleLogger as i, LogLevel as n, Logger as r, LogEntry as t };
27
+ //# sourceMappingURL=logger-BZ1zyKLb.d.ts.map
@@ -0,0 +1,2 @@
1
+ import { a as silentLogger, i as consoleLogger, n as LogLevel, r as Logger, t as LogEntry } from "../logger-BZ1zyKLb.js";
2
+ export { LogEntry, LogLevel, Logger, consoleLogger, silentLogger };
@@ -0,0 +1,15 @@
1
+ // src/logging/logger.ts
2
+ /** A logger that drops everything. */
3
+ const silentLogger = { log: () => void 0 };
4
+ /**
5
+ * A logger that writes each entry as one JSON line to the console, which Workers Logs and
6
+ * `wrangler tail` collect.
7
+ */
8
+ const consoleLogger = { log(entry) {
9
+ const line = JSON.stringify(entry);
10
+ if (entry.level === "error") console.error(line);
11
+ else console.log(line);
12
+ } };
13
+ export { consoleLogger, silentLogger };
14
+
15
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","names":[],"sources":["../../src/logging/logger.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\n/** How serious a log entry is. */\nexport type LogLevel = 'debug' | 'info' | 'warn' | 'error';\n\n/**\n * One structured log entry. Every entry the gateway writes carries the request id; none ever\n * carries a credential, a header value or an upstream URL's query string.\n */\nexport interface LogEntry {\n readonly level: LogLevel;\n /** What happened, e.g. \"request\", \"upstream failed\", \"audit hook failed\". */\n readonly message: string;\n readonly requestId: string;\n /** Further facts: repository, endpoint, principal subject, status, duration, reason. */\n readonly [field: string]: string | number | boolean | null | readonly string[] | undefined;\n}\n\n/** Where the gateway writes its structured logs. */\nexport interface Logger {\n log(entry: LogEntry): void;\n}\n\n/** A logger that drops everything. */\nexport const silentLogger: Logger = { log: () => undefined };\n\n/**\n * A logger that writes each entry as one JSON line to the console, which Workers Logs and\n * `wrangler tail` collect.\n */\nexport const consoleLogger: Logger = {\n log(entry) {\n const line = JSON.stringify(entry);\n // The console is the Workers runtime's log sink; this is the gateway's only use of it.\n // oxlint-disable-next-line no-console\n if (entry.level === 'error') console.error(line);\n // oxlint-disable-next-line no-console\n else console.log(line);\n },\n};\n"],"mappings":";;AAwBA,MAAa,eAAuB,EAAE,WAAW,KAAA,EAAU;;;;;AAM3D,MAAa,gBAAwB,EACnC,IAAI,OAAO;CACT,MAAM,OAAO,KAAK,UAAU,KAAK;CAGjC,IAAI,MAAM,UAAU,SAAS,QAAQ,MAAM,IAAI;MAE1C,QAAQ,IAAI,IAAI;AACvB,EACF"}
@@ -0,0 +1,62 @@
1
+ import { t as PushEvent } from "./push-event-f-5TsFUY.js";
2
+ import { t as SyncBranchWorkflowParams } from "./sync-workflow-schemas-DCNmNE5-.js";
3
+ import { r as WorkflowStarter } from "./workflow-starter-BqhwX6oA.js";
4
+ import { SyncRule } from "@leed-ai/git-gateway-contract/schemas/gateway-config";
5
+ /** Something a deployment runs after every accepted push. Rejecting asks for the event again. */
6
+ type OnPushHook = (event: PushEvent) => Promise<void>;
7
+ /**
8
+ * The onPush hook for the configured sync rules: for every rule whose `from` branch the push
9
+ * moved (not deleted), start a SyncBranchWorkflow syncing `into` from it. The instance id is
10
+ * derived from repository, both branches and the new head, so a redelivered event starts nothing
11
+ * new.
12
+ */
13
+ declare function syncRuleHook(syncRules: readonly SyncRule[], syncWorkflow: WorkflowStarter<SyncBranchWorkflowParams>): OnPushHook;
14
+ /**
15
+ * Delivers one push event to every hook. The event is parsed with {@link PushEvent} first
16
+ * (invalid_input when it does not match). Every hook runs even when another fails; if any failed,
17
+ * an AggregateError of their errors is thrown afterwards. Hooks must therefore be idempotent, as
18
+ * {@link syncRuleHook} is.
19
+ */
20
+ declare function dispatchPushEvent(event: unknown, hooks: readonly OnPushHook[]): Promise<void>;
21
+ /** What {@link composeOnPush} builds the deployment's onPush hook from. */
22
+ interface OnPushOptions {
23
+ /** The configured sync rules (GatewayConfig.syncRules). */
24
+ readonly syncRules: readonly SyncRule[];
25
+ /** The SyncBranchWorkflow binding the sync rules start instances of; required when there are rules. */
26
+ readonly syncWorkflow?: WorkflowStarter<SyncBranchWorkflowParams> | undefined;
27
+ /** The deployment's own hook, run beside the sync rules. */
28
+ readonly onPush?: OnPushHook | undefined;
29
+ }
30
+ /**
31
+ * The one onPush hook a gateway runs after every accepted push: {@link syncRuleHook} for the
32
+ * configured sync rules and the deployment's own hook, each run even when the other fails (see
33
+ * {@link dispatchPushEvent}); a lone hook is returned as it is. Undefined when there is nothing
34
+ * to run. Throws a TypeError when sync rules are configured without a SyncBranchWorkflow binding,
35
+ * which would leave them dead.
36
+ */
37
+ declare function composeOnPush(options: OnPushOptions): OnPushHook | undefined;
38
+ /** The part of a Queues message the consumer uses. */
39
+ interface PushEventMessage {
40
+ readonly body: unknown;
41
+ ack(): void;
42
+ retry(): void;
43
+ }
44
+ /** What {@link consumePushEvents} did with a batch. */
45
+ interface PushBatchOutcome {
46
+ /** Events every hook handled. */
47
+ readonly delivered: number;
48
+ /** Messages that are not push events; acknowledged, since redelivery cannot fix them. */
49
+ readonly dropped: number;
50
+ /** Events some hook failed on; handed back to the queue for redelivery. */
51
+ readonly retried: number;
52
+ }
53
+ /**
54
+ * A Queues consumer for push events: each message is dispatched to the hooks, then acknowledged,
55
+ * or retried when a hook failed. Messages that do not parse as a {@link PushEvent} are
56
+ * acknowledged and counted as dropped.
57
+ */
58
+ declare function consumePushEvents(batch: {
59
+ readonly messages: readonly PushEventMessage[];
60
+ }, hooks: readonly OnPushHook[]): Promise<PushBatchOutcome>;
61
+ export { composeOnPush as a, syncRuleHook as c, PushEventMessage as i, OnPushOptions as n, consumePushEvents as o, PushBatchOutcome as r, dispatchPushEvent as s, OnPushHook as t };
62
+ //# sourceMappingURL=on-push-DTREOB__.d.ts.map
@@ -0,0 +1,24 @@
1
+ import { GatewayDeps } from "../proxy/gateway-deps.js";
2
+ import { r as PendingFastForward } from "../gateway-env-DnsBU4Pq.js";
3
+ import { RefRefusal } from "../proxy/git-responses.js";
4
+ import { t as GitRequest } from "../git-route-Spxi09Rm.js";
5
+ import { ReceivePackRequest } from "@leed-ai/git-gateway-core/schemas/receive-pack";
6
+ /** The branch policy's verdict on a push before its pack is read. */
7
+ export interface PushVerdict {
8
+ /** Updates refused outright; when any is, nothing is forwarded. */
9
+ readonly refusals: readonly RefRefusal[];
10
+ /** Fast-forward-only updates whose new commit is not in storage yet: proven from the pack. */
11
+ readonly pending: readonly PendingFastForward[];
12
+ }
13
+ /** One line of at most 500 characters, as a report-status reason must be. */
14
+ export declare function reasonLine(text: string): string;
15
+ /**
16
+ * Runs the branch policy over every update of a push. Updates outside refs/heads/ and refs/tags/
17
+ * are refused before the policy is asked. A "fast-forward-only" decision allows a creation and
18
+ * refuses a deletion (no new commit can contain the old head); on an existing tag it is refused (moving a tag is never a fast-forward); on a branch whose new commit storage already
19
+ * has, ancestry is proven now; otherwise it is left pending, to be proven from the pack.
20
+ */
21
+ export declare function judgePush(deps: GatewayDeps, git: GitRequest, principal: Parameters<GatewayDeps['branchPolicy']['check']>[0], request: ReceivePackRequest): Promise<PushVerdict>;
22
+ /** Proves pending fast-forwards from the scanned pack and storage; returns those that are not. */
23
+ export declare function provePending(deps: GatewayDeps, git: GitRequest, pending: readonly PendingFastForward[], packCommits: ReadonlyMap<string, readonly string[]>): Promise<RefRefusal[]>;
24
+ //# sourceMappingURL=branch-policy.d.ts.map
@@ -0,0 +1,125 @@
1
+ import { proveFastForward } from "./fast-forward.js";
2
+ import { RefUpdate } from "@leed-ai/git-gateway-contract/schemas/ref-update";
3
+ import { ZERO_SHA } from "@leed-ai/git-gateway-contract/schemas/sha";
4
+ import { PolicyResult } from "@leed-ai/git-gateway-contract/proxy/policy-result";
5
+ // src/policy/branch-policy.ts
6
+ /** One line of at most 500 characters, as a report-status reason must be. */
7
+ function reasonLine(text) {
8
+ const line = text.replaceAll(/[\n\r\0]+/g, " ").trim();
9
+ return (line === "" ? "refused" : line).slice(0, 500);
10
+ }
11
+ const NOT_A_BRANCH = "only branches (refs/heads/*) and tags (refs/tags/*) can be pushed through this gateway";
12
+ const UNVERIFIABLE = "could not verify that the update is a fast-forward";
13
+ /**
14
+ * Runs the branch policy over every update of a push. Updates outside refs/heads/ and refs/tags/
15
+ * are refused before the policy is asked. A "fast-forward-only" decision allows a creation and
16
+ * refuses a deletion (no new commit can contain the old head); on an existing tag it is refused (moving a tag is never a fast-forward); on a branch whose new commit storage already
17
+ * has, ancestry is proven now; otherwise it is left pending, to be proven from the pack.
18
+ */
19
+ async function judgePush(deps, git, principal, request) {
20
+ const refusals = [];
21
+ const updates = [];
22
+ for (const command of request.commands) {
23
+ const parsed = RefUpdate.safeParse(command);
24
+ if (parsed.success) updates.push(parsed.data);
25
+ else refusals.push({
26
+ ref: command.ref,
27
+ reason: NOT_A_BRANCH
28
+ });
29
+ }
30
+ const result = updates.length === 0 ? { refs: [] } : PolicyResult.parse(deps.branchPolicy.check(principal, git.repo, updates));
31
+ const decisions = new Map(result.refs.map((decision) => [decision.ref, decision]));
32
+ const pending = [];
33
+ for (const update of updates) {
34
+ const decision = decisions.get(update.ref);
35
+ if (decision === void 0) {
36
+ refusals.push({
37
+ ref: update.ref,
38
+ reason: "the branch policy made no decision for this ref"
39
+ });
40
+ continue;
41
+ }
42
+ if (decision.decision === "allow") continue;
43
+ const reason = reasonLine(decision.reason);
44
+ if (decision.decision === "deny") {
45
+ refusals.push({
46
+ ref: update.ref,
47
+ reason
48
+ });
49
+ continue;
50
+ }
51
+ if (update.newSha === ZERO_SHA) {
52
+ refusals.push({
53
+ ref: update.ref,
54
+ reason
55
+ });
56
+ continue;
57
+ }
58
+ if (update.oldSha === ZERO_SHA) continue;
59
+ if (update.ref.startsWith("refs/tags/")) {
60
+ refusals.push({
61
+ ref: update.ref,
62
+ reason
63
+ });
64
+ continue;
65
+ }
66
+ let stored;
67
+ try {
68
+ stored = await deps.backend.readCommit(git.repo, update.newSha) !== null;
69
+ } catch {
70
+ refusals.push({
71
+ ref: update.ref,
72
+ reason: reasonLine(`${reason} (${UNVERIFIABLE})`)
73
+ });
74
+ continue;
75
+ }
76
+ if (!stored) {
77
+ pending.push({
78
+ update,
79
+ reason
80
+ });
81
+ continue;
82
+ }
83
+ const verdict = await proveFastForward(update.oldSha, update.newSha, {
84
+ repo: git.repo,
85
+ backend: deps.backend,
86
+ maxReads: deps.config.maxAncestryReads
87
+ });
88
+ if (verdict === "no") refusals.push({
89
+ ref: update.ref,
90
+ reason
91
+ });
92
+ if (verdict === "unknown") refusals.push({
93
+ ref: update.ref,
94
+ reason: reasonLine(`${reason} (${UNVERIFIABLE})`)
95
+ });
96
+ }
97
+ return {
98
+ refusals,
99
+ pending
100
+ };
101
+ }
102
+ /** Proves pending fast-forwards from the scanned pack and storage; returns those that are not. */
103
+ async function provePending(deps, git, pending, packCommits) {
104
+ const refusals = [];
105
+ for (const { update, reason } of pending) {
106
+ const verdict = await proveFastForward(update.oldSha, update.newSha, {
107
+ repo: git.repo,
108
+ backend: deps.backend,
109
+ packCommits,
110
+ maxReads: deps.config.maxAncestryReads
111
+ });
112
+ if (verdict === "no") refusals.push({
113
+ ref: update.ref,
114
+ reason
115
+ });
116
+ if (verdict === "unknown") refusals.push({
117
+ ref: update.ref,
118
+ reason: reasonLine(`${reason} (${UNVERIFIABLE})`)
119
+ });
120
+ }
121
+ return refusals;
122
+ }
123
+ export { judgePush, provePending, reasonLine };
124
+
125
+ //# sourceMappingURL=branch-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"branch-policy.js","names":[],"sources":["../../src/policy/branch-policy.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { PolicyResult, type RefDecision } from '@leed-ai/git-gateway-contract/proxy/policy-result';\nimport { RefUpdate } from '@leed-ai/git-gateway-contract/schemas/ref-update';\nimport { ZERO_SHA } from '@leed-ai/git-gateway-contract/schemas/sha';\nimport type { ReceivePackRequest } from '@leed-ai/git-gateway-core/schemas/receive-pack';\n\nimport type { GatewayDeps } from '../proxy/gateway-deps.ts';\nimport type { PendingFastForward } from '../proxy/gateway-env.ts';\nimport type { RefRefusal } from '../proxy/git-responses.ts';\nimport type { GitRequest } from '../proxy/git-route.ts';\nimport { proveFastForward } from './fast-forward.ts';\n\n/** The branch policy's verdict on a push before its pack is read. */\nexport interface PushVerdict {\n /** Updates refused outright; when any is, nothing is forwarded. */\n readonly refusals: readonly RefRefusal[];\n /** Fast-forward-only updates whose new commit is not in storage yet: proven from the pack. */\n readonly pending: readonly PendingFastForward[];\n}\n\n/** One line of at most 500 characters, as a report-status reason must be. */\nexport function reasonLine(text: string): string {\n const line = text.replaceAll(/[\\n\\r\\0]+/g, ' ').trim();\n return (line === '' ? 'refused' : line).slice(0, 500);\n}\n\nconst NOT_A_BRANCH = 'only branches (refs/heads/*) and tags (refs/tags/*) can be pushed through this gateway';\nconst UNVERIFIABLE = 'could not verify that the update is a fast-forward';\n\n/**\n * Runs the branch policy over every update of a push. Updates outside refs/heads/ and refs/tags/\n * are refused before the policy is asked. A \"fast-forward-only\" decision allows a creation and\n * refuses a deletion (no new commit can contain the old head); on an existing tag it is refused (moving a tag is never a fast-forward); on a branch whose new commit storage already\n * has, ancestry is proven now; otherwise it is left pending, to be proven from the pack.\n */\nexport async function judgePush(\n deps: GatewayDeps,\n git: GitRequest,\n principal: Parameters<GatewayDeps['branchPolicy']['check']>[0],\n request: ReceivePackRequest,\n): Promise<PushVerdict> {\n const refusals: RefRefusal[] = [];\n const updates: RefUpdate[] = [];\n for (const command of request.commands) {\n const parsed = RefUpdate.safeParse(command);\n if (parsed.success) updates.push(parsed.data);\n else refusals.push({ ref: command.ref, reason: NOT_A_BRANCH });\n }\n const result =\n updates.length === 0\n ? { refs: [] }\n : PolicyResult.parse(deps.branchPolicy.check(principal, git.repo, updates));\n const decisions = new Map<string, RefDecision>(result.refs.map((decision) => [decision.ref, decision]));\n const pending: PendingFastForward[] = [];\n for (const update of updates) {\n const decision = decisions.get(update.ref);\n if (decision === undefined) {\n refusals.push({ ref: update.ref, reason: 'the branch policy made no decision for this ref' });\n continue;\n }\n if (decision.decision === 'allow') continue;\n const reason = reasonLine(decision.reason);\n if (decision.decision === 'deny') {\n refusals.push({ ref: update.ref, reason });\n continue;\n }\n if (update.newSha === ZERO_SHA) {\n refusals.push({ ref: update.ref, reason });\n continue;\n }\n if (update.oldSha === ZERO_SHA) continue;\n if (update.ref.startsWith('refs/tags/')) {\n refusals.push({ ref: update.ref, reason });\n continue;\n }\n let stored: boolean;\n try {\n stored = (await deps.backend.readCommit(git.repo, update.newSha)) !== null;\n } catch {\n refusals.push({ ref: update.ref, reason: reasonLine(`${reason} (${UNVERIFIABLE})`) });\n continue;\n }\n if (!stored) {\n pending.push({ update, reason });\n continue;\n }\n const verdict = await proveFastForward(update.oldSha, update.newSha, {\n repo: git.repo,\n backend: deps.backend,\n maxReads: deps.config.maxAncestryReads,\n });\n if (verdict === 'no') refusals.push({ ref: update.ref, reason });\n if (verdict === 'unknown')\n refusals.push({ ref: update.ref, reason: reasonLine(`${reason} (${UNVERIFIABLE})`) });\n }\n return { refusals, pending };\n}\n\n/** Proves pending fast-forwards from the scanned pack and storage; returns those that are not. */\nexport async function provePending(\n deps: GatewayDeps,\n git: GitRequest,\n pending: readonly PendingFastForward[],\n packCommits: ReadonlyMap<string, readonly string[]>,\n): Promise<RefRefusal[]> {\n const refusals: RefRefusal[] = [];\n for (const { update, reason } of pending) {\n const verdict = await proveFastForward(update.oldSha, update.newSha, {\n repo: git.repo,\n backend: deps.backend,\n packCommits,\n maxReads: deps.config.maxAncestryReads,\n });\n if (verdict === 'no') refusals.push({ ref: update.ref, reason });\n if (verdict === 'unknown')\n refusals.push({ ref: update.ref, reason: reasonLine(`${reason} (${UNVERIFIABLE})`) });\n }\n return refusals;\n}\n"],"mappings":";;;;;;AAqBA,SAAgB,WAAW,MAAsB;CAC/C,MAAM,OAAO,KAAK,WAAW,cAAc,GAAG,CAAC,CAAC,KAAK;CACrD,QAAQ,SAAS,KAAK,YAAY,KAAA,CAAM,MAAM,GAAG,GAAG;AACtD;AAEA,MAAM,eAAe;AACrB,MAAM,eAAe;;;;;;;AAQrB,eAAsB,UACpB,MACA,KACA,WACA,SACsB;CACtB,MAAM,WAAyB,CAAC;CAChC,MAAM,UAAuB,CAAC;CAC9B,KAAK,MAAM,WAAW,QAAQ,UAAU;EACtC,MAAM,SAAS,UAAU,UAAU,OAAO;EAC1C,IAAI,OAAO,SAAS,QAAQ,KAAK,OAAO,IAAI;OACvC,SAAS,KAAK;GAA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SAAS,KAAK;GACd,UAAU,KAAK,OAAO;EACxB,CAAC;EACD,IAAI,YAAY,MAAM,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK;EAAO,CAAC;EAC/D,IAAI,YAAY,WACd,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK,QAAQ,WAAW,GAAG,OAAO,IAAI,aAAa,EAAE;EAAE,CAAC;CACxF;CACA,OAAO;EAAE;EAAU;CAAQ;AAC7B;;AAGA,eAAsB,aACpB,MACA,KACA,SACA,aACuB;CACvB,MAAM,WAAyB,CAAC;CAChC,KAAK,MAAM,EAAE,QAAQ,YAAY,SAAS;EACxC,MAAM,UAAU,MAAM,iBAAiB,OAAO,QAAQ,OAAO,QAAQ;GACnE,MAAM,IAAI;GACV,SAAS,KAAK;GACd;GACA,UAAU,KAAK,OAAO;EACxB,CAAC;EACD,IAAI,YAAY,MAAM,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK;EAAO,CAAC;EAC/D,IAAI,YAAY,WACd,SAAS,KAAK;GAAE,KAAK,OAAO;GAAK,QAAQ,WAAW,GAAG,OAAO,IAAI,aAAa,EAAE;EAAE,CAAC;CACxF;CACA,OAAO;AACT"}
@@ -0,0 +1,30 @@
1
+ import { GatewayDeps } from "../proxy/gateway-deps.js";
2
+ import { n as GatewayEnv } from "../gateway-env-DnsBU4Pq.js";
3
+ import { RefRefusal } from "../proxy/git-responses.js";
4
+ import { MiddlewareHandler } from "hono";
5
+ import { ReceivePackRequest } from "@leed-ai/git-gateway-core/schemas/receive-pack";
6
+ /** The reason given for an update refused only because another update of the same push was. */
7
+ export declare const COLLATERAL_REASON = "not updated: another update in this push was refused";
8
+ /** Most bytes of a refused push read and discarded before it is answered. */
9
+ export declare const MAX_DRAIN_BYTES: number;
10
+ /**
11
+ * Reads and discards what remains of a refused push, so a client that is still sending gets its
12
+ * answer instead of a reset connection — but at most `limit` bytes, after which the rest is
13
+ * cancelled. Read errors (a client that hung up) are swallowed: the answer is already decided.
14
+ */
15
+ export declare function drain(stream: ReadableStream<Uint8Array>, limit?: number): Promise<void>;
16
+ /** Every update of a push refused: the given refusals, and the collateral reason for the rest. */
17
+ export declare function refuseAll(request: ReceivePackRequest, refusals: readonly RefRefusal[]): RefRefusal[];
18
+ /**
19
+ * Branch-policy middleware for git-receive-pack: reads only the leading update commands of the
20
+ * push (never the pack), refuses a push carrying a push option outside
21
+ * `SmartHttpConfig.allowedPushOptions` (the storage host would act on it with the gateway's own
22
+ * credential), asks the BranchPolicy about every ref, and proves fast-forwards it can
23
+ * from storage, then runs the push policy (when there is one) — at once when it needs no changed
24
+ * paths, or after the pack when it does. A push is forwarded only when every update is allowed —
25
+ * otherwise the client is answered in-protocol ("ng <ref> <reason>" per ref) and nothing reaches storage. Updates whose
26
+ * ancestry depends on commits in the pack are left for the receive-pack handler to prove as the
27
+ * pack streams past.
28
+ */
29
+ export declare function enforceBranchPolicy(deps: GatewayDeps): MiddlewareHandler<GatewayEnv>;
30
+ //# sourceMappingURL=enforce-branch-policy.d.ts.map
@@ -0,0 +1,214 @@
1
+ import { rejectedOutcomes, unknownOutcomes } from "../audit/push-report.js";
2
+ import { deferWith } from "../proxy/defer.js";
3
+ import { NO_CACHE, errResponse, refusePush, textResponse } from "../proxy/git-responses.js";
4
+ import { disallowedPushOptions, pushOptionsReason } from "../proxy/push-options.js";
5
+ import { judgeWithPushPolicy, pushPolicyNeeds } from "../push-policy/run-push-policy.js";
6
+ import { judgePush, reasonLine } from "./branch-policy.js";
7
+ import { isCoreError } from "@leed-ai/git-gateway-core/core-error";
8
+ import { PktLineReader } from "@leed-ai/git-gateway-core/pkt-line/pkt-line-reader";
9
+ import { parseReceivePackRequest } from "@leed-ai/git-gateway-core/receive-pack/parse-request";
10
+ import { RefUpdate } from "@leed-ai/git-gateway-contract/schemas/ref-update";
11
+ import { ZERO_SHA } from "@leed-ai/git-gateway-contract/schemas/sha";
12
+ // src/policy/enforce-branch-policy.ts
13
+ /** The reason given for an update refused only because another update of the same push was. */
14
+ const COLLATERAL_REASON = "not updated: another update in this push was refused";
15
+ /** Most bytes of a refused push read and discarded before it is answered. */
16
+ const MAX_DRAIN_BYTES = 16777216;
17
+ /**
18
+ * Reads and discards what remains of a refused push, so a client that is still sending gets its
19
+ * answer instead of a reset connection — but at most `limit` bytes, after which the rest is
20
+ * cancelled. Read errors (a client that hung up) are swallowed: the answer is already decided.
21
+ */
22
+ async function drain(stream, limit = MAX_DRAIN_BYTES) {
23
+ const reader = stream.getReader();
24
+ let read = 0;
25
+ try {
26
+ for (let next = await reader.read(); !next.done; next = await reader.read()) {
27
+ read += next.value.length;
28
+ if (read > limit) {
29
+ await reader.cancel();
30
+ return;
31
+ }
32
+ }
33
+ } catch {
34
+ await reader.cancel().catch(() => void 0);
35
+ }
36
+ }
37
+ /** Every update of a push refused: the given refusals, and the collateral reason for the rest. */
38
+ function refuseAll(request, refusals) {
39
+ const byRef = new Map(refusals.map((refusal) => [refusal.ref, refusal.reason]));
40
+ return request.commands.map((command) => ({
41
+ ref: command.ref,
42
+ reason: byRef.get(command.ref) ?? "not updated: another update in this push was refused"
43
+ }));
44
+ }
45
+ /**
46
+ * The request body as receive-pack bytes: gunzipped when the client compressed it, and null for
47
+ * git's auth probe (a body of just a flush packet, sent before a large chunked push).
48
+ */
49
+ async function receivePackBody(request) {
50
+ const raw = request.body ?? new Blob([]).stream();
51
+ const body = request.headers.get("Content-Encoding") === "gzip" ? raw.pipeThrough(new DecompressionStream("gzip")) : raw;
52
+ const reader = new PktLineReader(body);
53
+ if ((await reader.read())?.type === "flush" && await reader.read() === null) return null;
54
+ return reader.replay();
55
+ }
56
+ /**
57
+ * Branch-policy middleware for git-receive-pack: reads only the leading update commands of the
58
+ * push (never the pack), refuses a push carrying a push option outside
59
+ * `SmartHttpConfig.allowedPushOptions` (the storage host would act on it with the gateway's own
60
+ * credential), asks the BranchPolicy about every ref, and proves fast-forwards it can
61
+ * from storage, then runs the push policy (when there is one) — at once when it needs no changed
62
+ * paths, or after the pack when it does. A push is forwarded only when every update is allowed —
63
+ * otherwise the client is answered in-protocol ("ng <ref> <reason>" per ref) and nothing reaches storage. Updates whose
64
+ * ancestry depends on commits in the pack are left for the receive-pack handler to prove as the
65
+ * pack streams past.
66
+ */
67
+ function enforceBranchPolicy(deps) {
68
+ return async (context, next) => {
69
+ const requestId = context.get("requestId");
70
+ const principal = context.get("principal");
71
+ const git = context.get("git");
72
+ const defer = deferWith(context);
73
+ let parsed;
74
+ try {
75
+ const body = await receivePackBody(context.req.raw);
76
+ if (body === null) return new Response(null, {
77
+ status: 200,
78
+ headers: {
79
+ "Content-Type": "application/x-git-receive-pack-result",
80
+ ...NO_CACHE,
81
+ "X-Request-Id": requestId
82
+ }
83
+ });
84
+ parsed = await parseReceivePackRequest(body, { maxHeadBytes: deps.config.maxPushHeadBytes });
85
+ } catch (error) {
86
+ if (!isCoreError(error)) throw error;
87
+ const reason = reasonLine(`malformed push: ${error.message}`);
88
+ deps.audit.record({
89
+ requestId,
90
+ principal,
91
+ git,
92
+ outcome: "denied",
93
+ reason,
94
+ refs: []
95
+ }, defer, requestId);
96
+ const response = errResponse(git.service, "rpc", reason);
97
+ response.headers.set("X-Request-Id", requestId);
98
+ return response;
99
+ }
100
+ const refusedOptions = disallowedPushOptions(parsed.request, deps.config.allowedPushOptions);
101
+ if (refusedOptions.length > 0) {
102
+ const reason = reasonLine(pushOptionsReason(refusedOptions));
103
+ const refusals = parsed.request.commands.map((command) => ({
104
+ ref: command.ref,
105
+ reason
106
+ }));
107
+ deps.audit.record({
108
+ requestId,
109
+ principal,
110
+ git,
111
+ outcome: "denied",
112
+ reason,
113
+ refs: rejectedOutcomes(parsed.request, /* @__PURE__ */ new Map(), reason)
114
+ }, defer, requestId);
115
+ await drain(parsed.body);
116
+ deps.logger.log({
117
+ level: "info",
118
+ message: "push refused for its push options",
119
+ requestId,
120
+ repo: git.repo,
121
+ reason
122
+ });
123
+ const response = refusePush(parsed.request.capabilities, refusals);
124
+ response.headers.set("X-Request-Id", requestId);
125
+ return response;
126
+ }
127
+ /** Answers 503 when a policy hook failed; nothing reaches storage. */
128
+ const unavailable = async (error, what) => {
129
+ deps.logger.log({
130
+ level: "error",
131
+ message: `${what} failed`,
132
+ requestId,
133
+ repo: git.repo,
134
+ error: error instanceof Error ? error.message : String(error)
135
+ });
136
+ const reason = `The ${what} is unavailable; try again later`;
137
+ deps.audit.record({
138
+ requestId,
139
+ principal,
140
+ git,
141
+ outcome: "failed",
142
+ reason,
143
+ refs: unknownOutcomes(parsed.request)
144
+ }, defer, requestId);
145
+ await drain(parsed.body);
146
+ return textResponse(503, reason, { "X-Request-Id": requestId });
147
+ };
148
+ /** Refuses the whole push in-protocol: the given refusals, and the collateral reason for the rest. */
149
+ const refuse = async (given, by) => {
150
+ const refusals = refuseAll(parsed.request, given);
151
+ const reasons = new Map(refusals.map((refusal) => [refusal.ref, refusal.reason]));
152
+ const reason = given[0]?.reason ?? "not updated: another update in this push was refused";
153
+ deps.audit.record({
154
+ requestId,
155
+ principal,
156
+ git,
157
+ outcome: "denied",
158
+ reason,
159
+ refs: rejectedOutcomes(parsed.request, reasons, COLLATERAL_REASON)
160
+ }, defer, requestId);
161
+ await drain(parsed.body);
162
+ deps.logger.log({
163
+ level: "info",
164
+ message: `push refused by ${by}`,
165
+ requestId,
166
+ repo: git.repo,
167
+ reason
168
+ });
169
+ const response = refusePush(parsed.request.capabilities, refusals);
170
+ response.headers.set("X-Request-Id", requestId);
171
+ return response;
172
+ };
173
+ let verdict;
174
+ try {
175
+ verdict = await judgePush(deps, git, principal, parsed.request);
176
+ } catch (error) {
177
+ return unavailable(error, "branch policy");
178
+ }
179
+ if (verdict.refusals.length > 0) return refuse(verdict.refusals, "branch policy");
180
+ let policyUpdates = null;
181
+ const { pushPolicy } = deps;
182
+ if (pushPolicy !== void 0) {
183
+ const updates = parsed.request.commands.map((command) => RefUpdate.parse(command));
184
+ const push = {
185
+ principal,
186
+ repo: git.repo,
187
+ updates
188
+ };
189
+ const policyDeps = {
190
+ pushPolicy,
191
+ backend: deps.backend,
192
+ config: deps.config
193
+ };
194
+ let refusals = [];
195
+ try {
196
+ const needs = await pushPolicyNeeds(policyDeps, push);
197
+ if (needs.changedPaths && updates.some((update) => update.newSha !== ZERO_SHA)) policyUpdates = updates;
198
+ else refusals = await judgeWithPushPolicy(policyDeps, push, updates.map(() => needs.changedPaths ? [] : null));
199
+ } catch (error) {
200
+ return unavailable(error, "push policy");
201
+ }
202
+ if (refusals.length > 0) return refuse(refusals, "push policy");
203
+ }
204
+ context.set("push", {
205
+ ...parsed,
206
+ pending: verdict.pending,
207
+ policyUpdates
208
+ });
209
+ return next();
210
+ };
211
+ }
212
+ export { COLLATERAL_REASON, MAX_DRAIN_BYTES, drain, enforceBranchPolicy, refuseAll };
213
+
214
+ //# sourceMappingURL=enforce-branch-policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enforce-branch-policy.js","names":[],"sources":["../../src/policy/enforce-branch-policy.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\nimport { isCoreError } from '@leed-ai/git-gateway-core/core-error';\nimport { PktLineReader } from '@leed-ai/git-gateway-core/pkt-line/pkt-line-reader';\nimport { parseReceivePackRequest } from '@leed-ai/git-gateway-core/receive-pack/parse-request';\nimport type { ReceivePackRequest } from '@leed-ai/git-gateway-core/schemas/receive-pack';\nimport type { MiddlewareHandler } from 'hono';\nimport { RefUpdate } from '@leed-ai/git-gateway-contract/schemas/ref-update';\nimport { ZERO_SHA } from '@leed-ai/git-gateway-contract/schemas/sha';\n\nimport { rejectedOutcomes, unknownOutcomes } from '../audit/push-report.ts';\nimport { deferWith } from '../proxy/defer.ts';\nimport type { GatewayDeps } from '../proxy/gateway-deps.ts';\nimport type { GatewayEnv } from '../proxy/gateway-env.ts';\nimport { errResponse, NO_CACHE, refusePush, textResponse, type RefRefusal } from '../proxy/git-responses.ts';\nimport { disallowedPushOptions, pushOptionsReason } from '../proxy/push-options.ts';\nimport { judgeWithPushPolicy, pushPolicyNeeds } from '../push-policy/run-push-policy.ts';\nimport { judgePush, reasonLine } from './branch-policy.ts';\n\n/** The reason given for an update refused only because another update of the same push was. */\nexport const COLLATERAL_REASON = 'not updated: another update in this push was refused';\n\n/** Most bytes of a refused push read and discarded before it is answered. */\nexport const MAX_DRAIN_BYTES = 16 * 1024 * 1024;\n\n/**\n * Reads and discards what remains of a refused push, so a client that is still sending gets its\n * answer instead of a reset connection — but at most `limit` bytes, after which the rest is\n * cancelled. Read errors (a client that hung up) are swallowed: the answer is already decided.\n */\nexport async function drain(stream: ReadableStream<Uint8Array>, limit = MAX_DRAIN_BYTES): Promise<void> {\n const reader = stream.getReader();\n let read = 0;\n try {\n for (let next = await reader.read(); !next.done; next = await reader.read()) {\n read += next.value.length;\n if (read > limit) {\n await reader.cancel();\n return;\n }\n }\n } catch {\n await reader.cancel().catch(() => undefined);\n }\n}\n\n/** Every update of a push refused: the given refusals, and the collateral reason for the rest. */\nexport function refuseAll(request: ReceivePackRequest, refusals: readonly RefRefusal[]): RefRefusal[] {\n const byRef = new Map(refusals.map((refusal) => [refusal.ref, refusal.reason]));\n return request.commands.map((command) => ({\n ref: command.ref,\n reason: byRef.get(command.ref) ?? COLLATERAL_REASON,\n }));\n}\n\n/**\n * The request body as receive-pack bytes: gunzipped when the client compressed it, and null for\n * git's auth probe (a body of just a flush packet, sent before a large chunked push).\n */\nasync function receivePackBody(request: Request): Promise<ReadableStream<Uint8Array> | null> {\n const raw = request.body ?? new Blob([]).stream();\n const body =\n request.headers.get('Content-Encoding') === 'gzip'\n ? raw.pipeThrough(new DecompressionStream('gzip'))\n : raw;\n const reader = new PktLineReader(body);\n const first = await reader.read();\n if (first?.type === 'flush' && (await reader.read()) === null) return null;\n return reader.replay();\n}\n\n/**\n * Branch-policy middleware for git-receive-pack: reads only the leading update commands of the\n * push (never the pack), refuses a push carrying a push option outside\n * `SmartHttpConfig.allowedPushOptions` (the storage host would act on it with the gateway's own\n * credential), asks the BranchPolicy about every ref, and proves fast-forwards it can\n * from storage, then runs the push policy (when there is one) — at once when it needs no changed\n * paths, or after the pack when it does. A push is forwarded only when every update is allowed —\n * otherwise the client is answered in-protocol (\"ng <ref> <reason>\" per ref) and nothing reaches storage. Updates whose\n * ancestry depends on commits in the pack are left for the receive-pack handler to prove as the\n * pack streams past.\n */\nexport function enforceBranchPolicy(deps: GatewayDeps): MiddlewareHandler<GatewayEnv> {\n return async (context, next) => {\n const requestId = context.get('requestId');\n const principal = context.get('principal');\n const git = context.get('git');\n const defer = deferWith(context);\n let parsed;\n try {\n const body = await receivePackBody(context.req.raw);\n if (body === null) {\n return new Response(null, {\n status: 200,\n headers: {\n 'Content-Type': 'application/x-git-receive-pack-result',\n ...NO_CACHE,\n 'X-Request-Id': requestId,\n },\n });\n }\n parsed = await parseReceivePackRequest(body, { maxHeadBytes: deps.config.maxPushHeadBytes });\n } catch (error) {\n if (!isCoreError(error)) throw error;\n const reason = reasonLine(`malformed push: ${error.message}`);\n deps.audit.record({ requestId, principal, git, outcome: 'denied', reason, refs: [] }, defer, requestId);\n const response = errResponse(git.service, 'rpc', reason);\n response.headers.set('X-Request-Id', requestId);\n return response;\n }\n const refusedOptions = disallowedPushOptions(parsed.request, deps.config.allowedPushOptions);\n if (refusedOptions.length > 0) {\n const reason = reasonLine(pushOptionsReason(refusedOptions));\n const refusals = parsed.request.commands.map((command) => ({ ref: command.ref, reason }));\n deps.audit.record(\n {\n requestId,\n principal,\n git,\n outcome: 'denied',\n reason,\n refs: rejectedOutcomes(parsed.request, new Map(), reason),\n },\n defer,\n requestId,\n );\n await drain(parsed.body);\n deps.logger.log({\n level: 'info',\n message: 'push refused for its push options',\n requestId,\n repo: git.repo,\n reason,\n });\n const response = refusePush(parsed.request.capabilities, refusals);\n response.headers.set('X-Request-Id', requestId);\n return response;\n }\n /** Answers 503 when a policy hook failed; nothing reaches storage. */\n const unavailable = async (error: unknown, what: string): Promise<Response> => {\n deps.logger.log({\n level: 'error',\n message: `${what} failed`,\n requestId,\n repo: git.repo,\n error: error instanceof Error ? error.message : String(error),\n });\n const reason = `The ${what} is unavailable; try again later`;\n deps.audit.record(\n { requestId, principal, git, outcome: 'failed', reason, refs: unknownOutcomes(parsed.request) },\n defer,\n requestId,\n );\n await drain(parsed.body);\n return textResponse(503, reason, { 'X-Request-Id': requestId });\n };\n /** Refuses the whole push in-protocol: the given refusals, and the collateral reason for the rest. */\n const refuse = async (given: readonly RefRefusal[], by: string): Promise<Response> => {\n const refusals = refuseAll(parsed.request, given);\n const reasons = new Map(refusals.map((refusal) => [refusal.ref, refusal.reason]));\n const reason = given[0]?.reason ?? COLLATERAL_REASON;\n deps.audit.record(\n {\n requestId,\n principal,\n git,\n outcome: 'denied',\n reason,\n refs: rejectedOutcomes(parsed.request, reasons, COLLATERAL_REASON),\n },\n defer,\n requestId,\n );\n await drain(parsed.body);\n deps.logger.log({ level: 'info', message: `push refused by ${by}`, requestId, repo: git.repo, reason });\n const response = refusePush(parsed.request.capabilities, refusals);\n response.headers.set('X-Request-Id', requestId);\n return response;\n };\n let verdict;\n try {\n verdict = await judgePush(deps, git, principal, parsed.request);\n } catch (error) {\n return unavailable(error, 'branch policy');\n }\n if (verdict.refusals.length > 0) return refuse(verdict.refusals, 'branch policy');\n let policyUpdates: readonly RefUpdate[] | null = null;\n const { pushPolicy } = deps;\n if (pushPolicy !== undefined) {\n const updates = parsed.request.commands.map((command) => RefUpdate.parse(command));\n const push = { principal, repo: git.repo, updates };\n const policyDeps = { pushPolicy, backend: deps.backend, config: deps.config };\n let refusals: readonly RefRefusal[] = [];\n try {\n const needs = await pushPolicyNeeds(policyDeps, push);\n // Changed paths come from the pack, so the check waits for it; a push of deletions only\n // brings no commits and is checked now.\n if (needs.changedPaths && updates.some((update) => update.newSha !== ZERO_SHA))\n policyUpdates = updates;\n else\n refusals = await judgeWithPushPolicy(\n policyDeps,\n push,\n updates.map(() => (needs.changedPaths ? [] : null)),\n );\n } catch (error) {\n return unavailable(error, 'push policy');\n }\n if (refusals.length > 0) return refuse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