-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel-zero.policy.json
More file actions
390 lines (390 loc) · 11.5 KB
/
Copy pathkernel-zero.policy.json
File metadata and controls
390 lines (390 loc) · 11.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
{
"apiVersion": "kernel-zero.dev/v1",
"kind": "RepositoryPolicy",
"metadata": {
"name": "kernel-zero-self-policy",
"revision": 1,
"description": "Deterministic architecture rules for the KERNEL ZERO repository."
},
"scope": {
"languages": [
"typescript",
"tsx"
],
"include": [
"apps/**/*.ts",
"apps/**/*.tsx",
"packages/**/*.ts"
],
"exclude": [
"**/*.test.ts",
"**/fixtures/**",
"packages/persistence/src/client.ts"
]
},
"layers": {
"ui": [
"apps/control/src/app/**/page.tsx",
"apps/control/src/app/**/layout.tsx"
],
"transport": [
"apps/control/src/app/api/**/*.ts"
],
"service": [
"apps/control/src/server/**/*.ts"
],
"persistence": [
"packages/persistence/src/**/*.ts"
],
"kernel": [
"packages/domain/**/*.ts",
"packages/contracts/**/*.ts",
"packages/persistence/**/*.ts"
],
"validator": [
"packages/validator/**/*.ts"
]
},
"rules": [
{
"id": "server-modules-declare-boundary",
"title": "Server modules declare their runtime boundary",
"level": "error",
"check": {
"kind": "require-import",
"files": [
"layer:service",
"layer:persistence"
],
"module": "server-only",
"allowTypeOnly": false
},
"remediation": "Add the server-only side-effect import at the module boundary."
},
{
"id": "ui-does-not-import-persistence",
"title": "UI routes use application services",
"level": "error",
"check": {
"kind": "forbid-import-edge",
"from": [
"layer:ui"
],
"deny": [
"module:@kernel-zero/persistence",
"module:@prisma/client"
]
},
"remediation": "Move persistence access behind a server application service."
},
{
"id": "transport-does-not-import-repositories",
"title": "Transport routes call services rather than repositories",
"level": "error",
"check": {
"kind": "forbid-import-edge",
"from": [
"layer:transport"
],
"deny": [
"module:@kernel-zero/persistence",
"module:@prisma/client"
]
},
"remediation": "Parse at ingress and call one application service."
},
{
"id": "public-evidence-is-parsed",
"title": "Evidence ingress parses the public contract",
"level": "error",
"check": {
"kind": "require-boundary-parse",
"files": [
"apps/control/src/server/evidence/evidence-service.ts"
],
"boundaryCalls": [
"verifyEvidenceAttestation"
],
"parserCalls": [
"profile.evidenceSchema.safeParse"
]
},
"remediation": "Pass only a value proven by the strict evidence schema to the service."
},
{
"id": "tenant-selector-requires-workspace",
"title": "Tenant selectors require workspace context",
"level": "error",
"check": {
"kind": "require-tenant-parameter",
"files": [
"packages/persistence/src/tenancy.ts"
],
"symbols": "tenantSelector",
"parameter": "workspaceId"
},
"remediation": "Require the exact workspace identifier in every tenant selector."
},
{
"id": "governed-actions-have-closed-metadata",
"title": "Governed actions declare enforcement metadata",
"level": "error",
"check": {
"kind": "require-governed-operation",
"files": [
"apps/control/src/server/governed-actions.ts"
],
"registryExport": "GOVERNED_ACTIONS",
"requiredKeys": [
"tenantScope",
"audit",
"idempotency"
],
"declarationCalls": [
"defineGovernedAction"
]
},
"remediation": "Declare every governed action through the closed registry contract."
},
{
"id": "raw-database-client-is-contained",
"title": "Raw database clients stay in persistence",
"level": "error",
"check": {
"kind": "forbid-import-edge",
"from": [
"apps/**/*.ts",
"apps/**/*.tsx",
"packages/contracts/**/*.ts",
"packages/domain/**/*.ts",
"packages/validator/**/*.ts"
],
"deny": [
"module:@prisma/client"
]
},
"remediation": "Use the tenant-scoped persistence package instead of the raw client."
},
{
"id": "kernel-does-not-import-profiles",
"title": "Kernel packages never depend on a profile",
"level": "error",
"check": {
"kind": "forbid-import-edge",
"from": [
"layer:kernel"
],
"deny": [
"module:@kernel-zero/profiles",
"module:@kernel-zero/profile-software-architecture",
"module:@kernel-zero/profile-manifest"
]
},
"remediation": "Move profile-specific logic behind the Profile interface and look it up through @kernel-zero/profiles from the control application."
},
{
"id": "validator-stays-network-and-database-free",
"title": "The standalone validator never depends on the control plane",
"level": "error",
"check": {
"kind": "forbid-import-edge",
"from": [
"layer:validator"
],
"deny": [
"module:@kernel-zero/persistence",
"module:@kernel-zero/profiles",
"module:@prisma/client",
"module-prefix:next"
]
},
"remediation": "Keep the validator on contracts, domain, and its profile."
},
{
"id": "tenant-queries-carry-workspace",
"title": "Tenant queries carry the workspace identifier",
"level": "error",
"check": {
"kind": "require-call-argument",
"files": [
"layer:persistence"
],
"callee": [
"*.findFirst",
"*.findMany",
"*.updateMany",
"*.deleteMany",
"*.count"
],
"argument": 0,
"requiredPath": "where.workspaceId",
"allowFrom": [
"packages/persistence/src/audit.ts"
]
},
"remediation": "Put workspaceId in the where selector of every tenant-scoped query so a sibling tenant's rows are never reachable."
},
{
"id": "policy-revision-state-is-governed",
"title": "Policy revision state changes only through the governed lifecycle",
"level": "error",
"check": {
"kind": "restrict-state-transition",
"callee": [
"*.policyRevision.updateMany"
],
"argument": 0,
"field": "data.state",
"allowFrom": [
"packages/persistence/src/policies.ts"
],
"transitions": [
{
"from": "draft",
"to": "approved"
},
{
"from": "approved",
"to": "active"
},
{
"from": "active",
"to": "superseded"
}
]
},
"remediation": "Change a policy revision's state only from policies.ts, with a literal where.state predicate, through draft->approved, approved->active, or active->superseded."
},
{
"id": "route-handlers-parse-their-input-get",
"title": "GET route handlers parse their input before it escapes",
"level": "error",
"check": {
"kind": "require-ingress-parse",
"files": [
"layer:transport"
],
"symbols": "GET",
"parserCalls": [
"readEvidenceRequest"
],
"readerCalls": [
"dependencies.resolveSubmission"
],
"allowedCalls": [
"dependencies.service.submit",
"errorResponse"
]
},
"remediation": "Pass the request only to the request-context reader and readEvidenceRequest; hand parsed values to one application service and build every response through errorResponse or Response.json."
},
{
"id": "route-handlers-parse-their-input-post",
"title": "POST route handlers parse their input before it escapes",
"level": "error",
"check": {
"kind": "require-ingress-parse",
"files": [
"layer:transport"
],
"symbols": "POST",
"parserCalls": [
"readEvidenceRequest"
],
"readerCalls": [
"dependencies.resolveSubmission"
],
"allowedCalls": [
"dependencies.service.submit",
"errorResponse"
]
},
"remediation": "Pass the request only to the request-context reader and readEvidenceRequest; hand parsed values to one application service and build every response through errorResponse or Response.json."
},
{
"id": "route-handlers-parse-their-input-put",
"title": "PUT route handlers parse their input before it escapes",
"level": "error",
"check": {
"kind": "require-ingress-parse",
"files": [
"layer:transport"
],
"symbols": "PUT",
"parserCalls": [
"readEvidenceRequest"
],
"readerCalls": [
"dependencies.resolveSubmission"
],
"allowedCalls": [
"dependencies.service.submit",
"errorResponse"
]
},
"remediation": "Pass the request only to the request-context reader and readEvidenceRequest; hand parsed values to one application service and build every response through errorResponse or Response.json."
},
{
"id": "route-handlers-parse-their-input-patch",
"title": "PATCH route handlers parse their input before it escapes",
"level": "error",
"check": {
"kind": "require-ingress-parse",
"files": [
"layer:transport"
],
"symbols": "PATCH",
"parserCalls": [
"readEvidenceRequest"
],
"readerCalls": [
"dependencies.resolveSubmission"
],
"allowedCalls": [
"dependencies.service.submit",
"errorResponse"
]
},
"remediation": "Pass the request only to the request-context reader and readEvidenceRequest; hand parsed values to one application service and build every response through errorResponse or Response.json."
},
{
"id": "route-handlers-parse-their-input-delete",
"title": "DELETE route handlers parse their input before it escapes",
"level": "error",
"check": {
"kind": "require-ingress-parse",
"files": [
"layer:transport"
],
"symbols": "DELETE",
"parserCalls": [
"readEvidenceRequest"
],
"readerCalls": [
"dependencies.resolveSubmission"
],
"allowedCalls": [
"dependencies.service.submit",
"errorResponse"
]
},
"remediation": "Pass the request only to the request-context reader and readEvidenceRequest; hand parsed values to one application service and build every response through errorResponse or Response.json."
},
{
"id": "runtime-opens-at-the-boundary",
"title": "The runtime is opened only where a request enters",
"level": "error",
"check": {
"kind": "restrict-call-site",
"callee": [
"getRuntime"
],
"allowFrom": [
"layer:transport",
"apps/control/src/app/app/route-context.ts"
]
},
"remediation": "Receive the runtime (or its prisma client and config) as a parameter from the route or page context instead of opening it inside a service or view."
}
]
}