@uns-kit/core 3.0.33 → 3.0.34

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 (31) hide show
  1. package/MIGRATIONS.md +25 -0
  2. package/dist/runtime/process-group-authorization.d.ts +72 -0
  3. package/dist/runtime/process-group-authorization.d.ts.map +1 -1
  4. package/dist/runtime/process-group-authorization.js +31 -0
  5. package/dist/runtime/process-group-authorization.js.map +1 -1
  6. package/dist/runtime/process-group-contract.d.ts +1 -0
  7. package/dist/runtime/process-group-contract.d.ts.map +1 -1
  8. package/dist/runtime/process-group-contract.js +2 -1
  9. package/dist/runtime/process-group-contract.js.map +1 -1
  10. package/dist/runtime/process-group-direct-contract.d.ts +181 -0
  11. package/dist/runtime/process-group-direct-contract.d.ts.map +1 -0
  12. package/dist/runtime/process-group-direct-contract.js +151 -0
  13. package/dist/runtime/process-group-direct-contract.js.map +1 -0
  14. package/dist/runtime/process-group-direct-review.d.ts +203 -0
  15. package/dist/runtime/process-group-direct-review.d.ts.map +1 -0
  16. package/dist/runtime/process-group-direct-review.js +263 -0
  17. package/dist/runtime/process-group-direct-review.js.map +1 -0
  18. package/dist/runtime/process-group-direct-runtime.d.ts +18 -0
  19. package/dist/runtime/process-group-direct-runtime.d.ts.map +1 -0
  20. package/dist/runtime/process-group-direct-runtime.js +154 -0
  21. package/dist/runtime/process-group-direct-runtime.js.map +1 -0
  22. package/dist/runtime/process-group-snapshot.mjs +44 -0
  23. package/dist/uns-mqtt/mqtt-proxy.d.ts +1 -0
  24. package/dist/uns-mqtt/mqtt-proxy.d.ts.map +1 -1
  25. package/dist/uns-mqtt/mqtt-proxy.js +5 -0
  26. package/dist/uns-mqtt/mqtt-proxy.js.map +1 -1
  27. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts +6 -0
  28. package/dist/uns-mqtt/uns-mqtt-proxy.d.ts.map +1 -1
  29. package/dist/uns-mqtt/uns-mqtt-proxy.js +14 -0
  30. package/dist/uns-mqtt/uns-mqtt-proxy.js.map +1 -1
  31. package/package.json +1 -1
package/MIGRATIONS.md CHANGED
@@ -9,6 +9,31 @@ Agents must inspect the application's existing ownership and shutdown flow
9
9
  before editing it. The examples below describe the intended behavior, not a
10
10
  mechanical search-and-replace operation.
11
11
 
12
+ ## 3.0.34 - Optional paired-input retirement to one direct process
13
+
14
+ When crossing `<3.0.34` to `>=3.0.34`, ordinary applications require no change.
15
+ Packages opting into `unsDatahub.processGroupDirectRuntime` use shared declaration,
16
+ resource review and startup/readiness helpers under `runtime/process-group-direct-*`.
17
+ The authenticated host must stop receiver first, drain the same input journal,
18
+ prove both original exits and persist one launch intent before starting one direct
19
+ successor. Preserve business profiles, paths, units, journal UUID and original policy.
20
+
21
+ Schema5 retirement evidence fences old journal owners and original profiles.
22
+ Open recovery pins exact direct configuration/artifact/placement/launch; explicit
23
+ closure releases ordinary direct management but retains the old journal and fences.
24
+ Unknown outcomes stay blocked in the same operation. Never remove policy/journal
25
+ files, rename an owner or force a second launch to bypass review.
26
+
27
+ `UnsMqttProxy.getInputReadiness()` exposes current SUBACK evidence. Register normal
28
+ signal/drain handlers and confirm output before declaring direct readiness; perform
29
+ confirmation asynchronously when the configured queue must accept during outages.
30
+ No Controller heartbeat is required for normal application cleanup.
31
+
32
+ Backup snapshots with retirement evidence use internal manifest2 and include exact
33
+ retirement/original-policy bytes. Update the transport helper from the same SDK
34
+ asset before activation; older transports fail closed. Restore remains offline
35
+ review only. See [declaration, API example and limits](https://github.com/uns-openhub/uns-kit/blob/master/docs/process-group-direct-retirement.md).
36
+
12
37
  ## 3.0.33 - Explicit queue disablement and generic clean MQTT migration
13
38
 
14
39
  When crossing `<3.0.33` to `>=3.0.33`, existing applications require no change.
@@ -83,6 +83,78 @@ export declare const hvAuthorizationSchema: z.ZodObject<{
83
83
  }, z.core.$strict>>;
84
84
  }, z.core.$strict>;
85
85
  export declare const productionGroupIds: readonly ["hv", "vv", "jek"];
86
+ /** A retirement keeps the original journal/policy bound; older readers fail closed on schema5. */
87
+ export declare function parseProcessGroupRetirementPolicy(value: unknown): {
88
+ schemaVersion: 5;
89
+ kind: "uns-process-group-direct-retirement";
90
+ protocolVersion: 1;
91
+ operationId: string;
92
+ packageName: string;
93
+ namespace: string;
94
+ groupId: string;
95
+ controllerName: string;
96
+ stateRoot: string;
97
+ recovery: "closed" | "open";
98
+ journal: {
99
+ directory: string;
100
+ journalId: string;
101
+ journalContractSha256: string;
102
+ generationId: string;
103
+ maxRecords: number;
104
+ maxBytes: number;
105
+ minFreeBytes: number;
106
+ profiles: {
107
+ processName: string;
108
+ mappingSha256: string;
109
+ dataGroup: string;
110
+ }[];
111
+ groupSha256?: string;
112
+ contractVersion?: 1 | 2;
113
+ };
114
+ sourcePolicyJson: string;
115
+ sourcePolicySha256: string;
116
+ source: {
117
+ publisher: {
118
+ placement: {
119
+ controller: string;
120
+ rttNode: string;
121
+ version: string;
122
+ instanceId: string;
123
+ };
124
+ processName: string;
125
+ configurationSha256: string;
126
+ artifactSha256: string;
127
+ policyConfigurationSha256: string;
128
+ };
129
+ receiver: {
130
+ placement: {
131
+ controller: string;
132
+ rttNode: string;
133
+ version: string;
134
+ instanceId: string;
135
+ };
136
+ processName: string;
137
+ configurationSha256: string;
138
+ artifactSha256: string;
139
+ policyConfigurationSha256: string;
140
+ };
141
+ };
142
+ target: {
143
+ placement: {
144
+ controller: string;
145
+ rttNode: string;
146
+ version: string;
147
+ instanceId: string;
148
+ };
149
+ processName: string;
150
+ configurationSha256: string;
151
+ artifactSha256: string;
152
+ packageRoot: string;
153
+ descriptorSha256: string;
154
+ resourceSha256: string;
155
+ channelsSha256: string;
156
+ };
157
+ };
86
158
  /** Bounded private registry enumeration; retained state without its policy fails closed.
87
159
  * New groups are operator-owned data and never a release-time enum in the Controller.
88
160
  */
@@ -1 +1 @@
1
- {"version":3,"file":"process-group-authorization.d.ts","sourceRoot":"","sources":["../../src/runtime/process-group-authorization.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE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B,cAAc,EAAE,MAAM,EACtB,UAAU,UAAQ,6BAUnB;AACD,wBAAgB,sCAAsC,CACpD,KAAK,EAAE,yBAAyB,GAAG,SAAS,EAC5C,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,SAAS,GAC5B,IAAI,CAON;AACD,eAAO,MAAM,4BAA4B,+CAAyC,CAAC;AACnF,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,yBAAyB,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAgBjG;AACD,eAAO,MAAM,kBAAkB,qCAA+B,CAAC;AAC/D,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,QAAQ,EAAE,MAAM,GAAG,SAAS,GAC3B,IAAI,CAwBN;AACD,eAAO,MAAM,oBAAoB,uCAAiC,CAAC"}
@@ -3,6 +3,7 @@ import path from "node:path";
3
3
  import { z } from "zod";
4
4
  import * as legacy from "./compatibility/energenti-authorization-v1.js";
5
5
  import { configurationGroupAuthorizationSchema, configurationGroupPolicyIdentity, verifyConfigurationGroupPolicy } from "./configuration-group-authorization.js";
6
+ import { processGroupRetirementPolicySchema } from "./process-group-direct-contract.js";
6
7
  import { normalizeProcessGroupConfiguration, processGroupDescriptor, resolvedProcessGroupChannels, } from "./process-group-contract.js";
7
8
  import { configurationAuthorizationHash, groupArtifactHash, groupChannelsHash, readProcessGroupResource as read, sha256 as sha, assertPrivateProcessGroupDirectory, } from "./process-group-resources.js";
8
9
  export { configurationAuthorizationHash, groupArtifactHash, groupChannelsHash } from "./process-group-resources.js";
@@ -54,6 +55,26 @@ export const hvAuthorizationSchema = legacy.hvAuthorizationSchema;
54
55
  export const productionGroupIds = legacy.productionGroupIds;
55
56
  const issued = new WeakSet();
56
57
  const privateDirectory = assertPrivateProcessGroupDirectory;
58
+ /** A retirement keeps the original journal/policy bound; older readers fail closed on schema5. */
59
+ export function parseProcessGroupRetirementPolicy(value) {
60
+ const p = processGroupRetirementPolicySchema.parse(value);
61
+ if (sha(p.sourcePolicyJson) !== p.sourcePolicySha256)
62
+ throw Error("Original retirement policy bytes changed");
63
+ const raw = JSON.parse(p.sourcePolicyJson), original = raw.schemaVersion === 4 ? configurationGroupAuthorizationSchema.parse(raw) : processGroupAuthorizationSchema.parse(raw);
64
+ const policyId = original.schemaVersion === 4 ? original.generationId : original.groupId;
65
+ if (original.packageName !== p.packageName || original.namespace !== p.namespace || original.groupId !== p.groupId || original.controllerName !== p.controllerName || original.stateRoot !== p.stateRoot || original.directory !== p.journal.directory || original.journalId !== p.journal.journalId || policyId !== p.journal.generationId || original.directory !== path.join(p.stateRoot, p.namespace, "admission", policyId) || original.channelsSha256 !== p.target.channelsSha256)
66
+ throw Error("Retirement journal or authority differs from original policy");
67
+ if ((original.schemaVersion === 4 ? original.groupSha256 : original.groupManifestSha256) !== p.target.resourceSha256)
68
+ throw Error("Retirement resource differs from original policy");
69
+ for (const role of ["publisher", "receiver"]) {
70
+ const m = p.source[role], before = original.placements.find(x => x.role === (role === "publisher" ? "target" : "receiver"));
71
+ if (!before || before.instanceId !== m.placement.instanceId || before.processName !== m.processName || before.configurationSha256 !== m.policyConfigurationSha256 || original.artifactSha256 !== m.artifactSha256 || m.placement.rttNode !== p.packageName)
72
+ throw Error("Retirement source placement differs from original policy");
73
+ }
74
+ if (p.target.placement.rttNode !== p.packageName || p.journal.profiles.some(x => !original.placements.some(y => y.role === "source" && y.processName === x.processName)))
75
+ throw Error("Retirement profile ownership differs");
76
+ return p;
77
+ }
57
78
  function registryRoot(root, dir) {
58
79
  if (!path.isAbsolute(root) || path.resolve(root) !== root || path.resolve(dir) !== dir)
59
80
  throw Error("Invalid policy registry");
@@ -187,6 +208,16 @@ export function configuredGroupProcessNames() {
187
208
  const result = new Set();
188
209
  for (const file of files) {
189
210
  const raw = JSON.parse(read(file, true).toString());
211
+ if (raw.schemaVersion === 5) {
212
+ const p = parseProcessGroupRetirementPolicy(raw);
213
+ if (p.stateRoot !== root || file !== path.join(root, p.namespace, "authorizations", p.journal.generationId + ".json"))
214
+ throw Error("Retirement registry binding differs");
215
+ privateDirectory(root);
216
+ privateDirectory(path.dirname(file));
217
+ for (const member of [...p.journal.profiles, p.source.publisher, p.source.receiver])
218
+ result.add(member.processName);
219
+ continue;
220
+ }
190
221
  const p = raw.schemaVersion === 4 ? configurationGroupAuthorizationSchema.parse(raw) : raw.schemaVersion === 3
191
222
  ? processGroupAuthorizationSchema.parse(raw)
192
223
  : z.union([legacy.hvAuthorizationSchema, legacy.processGroupAuthorizationSchema]).parse(raw);
@@ -1 +1 @@
1
- {"version":3,"file":"process-group-authorization.js","sourceRoot":"","sources":["../../src/runtime/process-group-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,MAAM,MAAM,+CAA+C,CAAC;AACxE,OAAO,EAAE,qCAAqC,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACjK,OAAO,EAEL,kCAAkC,EAClC,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,8BAA8B,EAC9B,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,IAAI,IAAI,EAChC,MAAM,IAAI,GAAG,EACb,kCAAkC,GACnC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEpH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,4BAA4B,CAAC;AAChF,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAC/C,EAAE,GAAG,CAAC,CAAC,MAAM,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I,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,gCAAgC,CAAC,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC;QAC9F,IACE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC,OAAO;YACjD,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,OAAO;YAC9C,CAAC,CAAC,WAAW,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI,KAAK,QAAQ;YACnB,CAAC,CAAC,UAAU,EAAE,QAAQ,KAAK,QAAQ;YACnC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,OAAO;YAC7D,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,OAAO;YAElD,MAAM,KAAK,EAAE,CAAC;QAChB,IAAI,0BAA0B,IAAI,KAAK,IAAI,KAAK,CAAC,wBAAwB,KAAK,SAAS;YACrF,CAAC,CAAC,CAAC,wBAAwB,KAAK,KAAK,CAAC,wBAAwB,IAAI,CAAC,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY,CAAC;YAAE,MAAM,KAAK,EAAE,CAAC;IAC5H,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,KAAK,CAAC,0EAA0E,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC;AACD,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\n\nimport * as legacy from \"./compatibility/energenti-authorization-v1.js\";\nimport { configurationGroupAuthorizationSchema, configurationGroupPolicyIdentity, verifyConfigurationGroupPolicy } from \"./configuration-group-authorization.js\";\nimport {\n type ProcessGroupRuntimeDescriptor,\n normalizeProcessGroupConfiguration,\n processGroupDescriptor,\n resolvedProcessGroupChannels,\n} from \"./process-group-contract.js\";\nimport {\n configurationAuthorizationHash,\n groupArtifactHash,\n groupChannelsHash,\n readProcessGroupResource as read,\n sha256 as sha,\n assertPrivateProcessGroupDirectory,\n} from \"./process-group-resources.js\";\n\nexport { configurationAuthorizationHash, groupArtifactHash, groupChannelsHash } from \"./process-group-resources.js\";\n\nexport const hasProcessGroupAuthorization = legacy.hasProcessGroupAuthorization;\nconst digest = z.string().regex(/^[a-f0-9]{64}$/),\n id = z.string().regex(/^[a-z][a-z0-9-]{0,99}$/);\nconst absolute = z\n .string()\n .max(512)\n .refine((v) => path.isAbsolute(v) && path.resolve(v) === v);\nconst placement = z.strictObject({\n instanceId: z.string().regex(/^[a-zA-Z0-9-]{1,100}$/),\n processName: id,\n role: z.enum([\"source\", \"target\", \"receiver\"]),\n configurationSha256: digest,\n});\nexport const processGroupAuthorizationSchema = z.strictObject({\n schemaVersion: z.literal(3),\n kind: z.literal(\"uns-process-group-runtime-authorization\"),\n protocolVersion: z.literal(1),\n packageName: z.string().min(1).max(214),\n namespace: id,\n groupId: id,\n descriptorSha256: digest,\n controllerName: z.string().min(1).max(100),\n packageRoot: absolute,\n artifactSha256: digest,\n groupManifestSha256: digest,\n channelsSha256: digest,\n stateRoot: absolute,\n directory: absolute,\n journalId: z.string().uuid().nullable(),\n placements: z.array(placement).min(4).max(18),\n});\nexport type ProcessGroupAuthorizationPolicy = z.infer<typeof processGroupAuthorizationSchema>;\nexport const processGroupManifestSchema = z.strictObject({\n schemaVersion: z.literal(1),\n id,\n inputTopic: z\n .string()\n .min(1)\n .max(512)\n .regex(/^[^#+\\0]+$/),\n processName: id,\n profiles: z\n .array(z.strictObject({ id, processName: id, mappingFile: z.string().min(1).max(512), mappingSha256: digest, dataGroup: id }))\n .min(2)\n .max(16),\n});\ninterface GenericAuthorization {\n readonly sha256: string;\n readonly file: string;\n readonly directory: string;\n readonly journalId: string | null;\n readonly role: \"source\" | \"target\" | \"receiver\";\n readonly groupId: string;\n readonly groupProcessName: string;\n readonly namespace: string;\n readonly generationId?: string;\n readonly configurationGroupSha256?: string;\n}\nexport type ProcessGroupAuthorization = legacy.HvAuthorization | GenericAuthorization;\nexport type HvAuthorization = ProcessGroupAuthorization;\nexport type HvAuthorizationPolicy = legacy.HvAuthorizationPolicy;\nexport const hvAuthorizationSchema = legacy.hvAuthorizationSchema;\nexport const productionGroupIds = legacy.productionGroupIds;\nconst issued = new WeakSet<object>();\nconst privateDirectory = assertPrivateProcessGroupDirectory;\nfunction registryRoot(root: string, dir: string): string {\n if (!path.isAbsolute(root) || path.resolve(root) !== root || path.resolve(dir) !== dir) throw Error(\"Invalid policy registry\");\n privateDirectory(root);\n if (dir === root) return \"*\"; // Explicit collection of independently owned namespaces.\n const relative = path.relative(root, dir);\n if (!path.isAbsolute(root) || path.resolve(root) !== root || !/^([a-z][a-z0-9-]{0,99})\\/authorizations$/.test(relative))\n throw Error(\"Invalid policy registry\");\n privateDirectory(root);\n privateDirectory(dir);\n return relative.split(\"/\")[0]!;\n}\nfunction selectedFile(pkg: string, raw: Record<string, unknown>, root: string, explicit?: string): string {\n const configured = configurationGroupPolicyIdentity(pkg, raw);\n if (configured) {\n if (explicit) return explicit;\n const directory = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (directory) {\n const selected = registryRoot(root, directory);\n if (selected !== \"*\" && selected !== configured.namespace) throw Error(\"Foreign runtime registry\");\n const registry = selected === \"*\" ? path.join(root, configured.namespace, \"authorizations\") : directory;\n privateDirectory(registry);\n return path.join(registry, configured.generationId + \".json\");\n }\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (!single) throw Error(\"No selected policy\");\n return single;\n }\n const descriptor = processGroupDescriptor(pkg);\n if (!descriptor) throw Error(\"Missing runtime contract\");\n const c = normalizeProcessGroupConfiguration(raw, descriptor),\n journal = c.journal as Record<string, unknown> | undefined;\n const manifest = descriptor.manifests.find((m) => m.file === journal?.[\"groupManifest\"]);\n if (!manifest) throw Error(\"Unregistered group manifest\");\n const dir = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (explicit) return explicit;\n if (dir) {\n const selected = registryRoot(root, dir);\n if (selected !== \"*\" && selected !== descriptor.namespace) throw Error(\"Foreign runtime registry\");\n const registry = selected === \"*\" ? path.join(root, descriptor.namespace, \"authorizations\") : dir;\n privateDirectory(registry);\n return path.join(registry, manifest.id + \".json\");\n }\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (!single) throw Error(\"No selected policy\");\n return single;\n}\n/** Bounded private registry enumeration; retained state without its policy fails closed.\n * New groups are operator-owned data and never a release-time enum in the Controller.\n */\nexport function configuredGroupProcessNames(): Set<string> {\n if (!hasProcessGroupAuthorization()) return new Set();\n try {\n const root = process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root) throw Error();\n const files = new Set<string>();\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (single) files.add(single);\n const dir = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (dir) {\n const selected = registryRoot(root, dir);\n let registries: { namespace: string; directory: string }[];\n if (selected === \"*\") {\n const namespaces = fs.readdirSync(root, { withFileTypes: true });\n if (namespaces.length > 64 || namespaces.some((e) => e.isSymbolicLink())) throw Error(\"Registry namespace budget or link violation\");\n registries = namespaces\n .filter((e) => e.isDirectory())\n .map((e) => {\n if (!id.safeParse(e.name).success) throw Error(\"Invalid registry namespace\");\n privateDirectory(path.join(root, e.name));\n return { namespace: e.name, directory: path.join(root, e.name, \"authorizations\") };\n });\n } else registries = [{ namespace: selected, directory: dir }];\n for (const registry of registries) {\n let entries: fs.Dirent[] = [];\n try {\n privateDirectory(registry.directory);\n entries = fs.readdirSync(registry.directory, { withFileTypes: true });\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"ENOENT\") throw e;\n }\n if (entries.length > 64) throw Error(\"Policy registry budget exceeded\");\n for (const entry of entries)\n if (entry.name.endsWith(\".json\")) {\n if (!/^[a-z][a-z0-9-]{0,99}\\.json$/.test(entry.name)) throw Error(\"Invalid registry entry\");\n files.add(path.join(registry.directory, entry.name));\n if (files.size > 64) throw Error(\"Total policy registry budget exceeded\");\n }\n const journals = path.join(root, registry.namespace, \"admission\");\n try {\n // Root/registry permissions already protect visibility; retain old parent modes.\n for (let parent = journals; parent !== path.dirname(parent); parent = path.dirname(parent))\n if (fs.lstatSync(parent).isSymbolicLink()) throw Error(\"Linked journal registry\");\n const retained = fs.readdirSync(journals, { withFileTypes: true });\n if (retained.length > 64) throw Error(\"Retained journal budget exceeded\");\n for (const entry of retained)\n if (\n !id.safeParse(entry.name).success ||\n entry.isSymbolicLink() ||\n !entry.isDirectory() ||\n !files.has(path.join(registry.directory, entry.name + \".json\"))\n )\n throw Error(\"Retained journal has no reviewed policy\");\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"ENOENT\") throw e;\n }\n }\n }\n const result = new Set<string>();\n for (const file of files) {\n const raw = JSON.parse(read(file, true).toString());\n const p =\n raw.schemaVersion === 4 ? configurationGroupAuthorizationSchema.parse(raw) : raw.schemaVersion === 3\n ? processGroupAuthorizationSchema.parse(raw)\n : z.union([legacy.hvAuthorizationSchema, legacy.processGroupAuthorizationSchema]).parse(raw);\n const { namespace, group } = p.schemaVersion === 4 ? { namespace: p.namespace, group: p.generationId }\n : p.schemaVersion === 3 ? { namespace: p.namespace, group: p.groupId } : legacy.legacyPolicyIdentity(p);\n if (\n p.stateRoot !== root ||\n file !== path.join(root, namespace, \"authorizations\", group + \".json\") ||\n p.directory !== path.join(root, namespace, \"admission\", group)\n )\n throw Error();\n privateDirectory(root);\n privateDirectory(path.dirname(file));\n for (const role of p.placements) result.add(role.processName);\n }\n return result;\n } catch {\n throw Error(\"Process-group authorization registry is missing, changed or insecure; review required\");\n }\n}\nexport interface ProcessGroupAuthorizationContext {\n packageRoot: string;\n instanceDirectory: string;\n rawConfiguration: Record<string, unknown>;\n channels: unknown[];\n controllerName: string;\n file?: string;\n stateRoot?: string;\n initialize?: boolean;\n}\nfunction verifyRuntimePolicy(context: ProcessGroupAuthorizationContext, candidate?: Buffer): ProcessGroupAuthorization {\n try {\n const root = context.stateRoot ?? process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root || !context.controllerName) throw Error();\n const file = selectedFile(context.packageRoot, context.rawConfiguration, root, context.file),\n bytes = candidate ?? read(file, true),\n unparsed = JSON.parse(bytes.toString());\n if (unparsed.schemaVersion === 4) {\n const result = verifyConfigurationGroupPolicy(context, bytes, root, file);\n if (!candidate) issued.add(result);\n return result;\n }\n if (unparsed.schemaVersion !== 3) {\n if (candidate) throw Error(\"Only generic policies can be staged\");\n return legacy.authorizeHvRuntime({ ...context, file, stateRoot: root });\n }\n const p = processGroupAuthorizationSchema.parse(unparsed),\n d = processGroupDescriptor(context.packageRoot);\n if (!d || d.legacy) throw Error(\"Generic runtime descriptor required\");\n const pkg = JSON.parse(read(path.join(context.packageRoot, \"package.json\")).toString());\n const manifest = d.manifests.find((m) => m.id === p.groupId);\n if (\n !manifest ||\n p.packageName !== pkg.name ||\n p.namespace !== d.namespace ||\n p.descriptorSha256 !== configurationAuthorizationHash(pkg.unsDatahub.processGroupRuntime) ||\n p.packageRoot !== context.packageRoot ||\n p.controllerName !== context.controllerName ||\n p.stateRoot !== root ||\n file !== path.join(root, d.namespace, \"authorizations\", p.groupId + \".json\") ||\n p.directory !== path.join(root, d.namespace, \"admission\", p.groupId)\n )\n throw Error();\n privateDirectory(root);\n privateDirectory(path.dirname(file));\n if (groupArtifactHash(context.packageRoot) !== p.artifactSha256 || groupChannelsHash(context.channels) !== p.channelsSha256) throw Error();\n const manifestBytes = read(path.join(context.packageRoot, manifest.file));\n if (sha(manifestBytes) !== p.groupManifestSha256) throw Error();\n const m = processGroupManifestSchema.parse(JSON.parse(manifestBytes.toString()));\n if (m.id !== p.groupId) throw Error();\n const receiver = m.processName + \"-admission\";\n if (\n new Set(m.profiles.map((x) => x.id)).size !== m.profiles.length ||\n new Set(m.profiles.map((x) => x.processName)).size !== m.profiles.length ||\n m.profiles.some((x) => x.processName === m.processName || x.processName === receiver)\n )\n throw Error();\n for (const member of m.profiles) {\n const f = path.resolve(context.packageRoot, path.dirname(manifest.file), member.mappingFile);\n if (!f.startsWith(context.packageRoot + path.sep) || sha(read(f)) !== member.mappingSha256) throw Error();\n }\n const expected = new Map([\n ...m.profiles.map((x) => [x.processName, \"source\"] as const),\n [m.processName, \"target\"] as const,\n [receiver, \"receiver\"] as const,\n ]);\n if (\n p.placements.length !== expected.size ||\n new Set(p.placements.map((x) => x.instanceId)).size !== expected.size ||\n new Set(p.placements.map((x) => x.processName)).size !== expected.size ||\n p.placements.some((x) => expected.get(x.processName) !== x.role)\n )\n throw Error();\n const entry = p.placements.find((x) => context.instanceDirectory === path.join(context.packageRoot, \"instances\", x.instanceId));\n const c = normalizeProcessGroupConfiguration(context.rawConfiguration, d),\n j = c.journal as Record<string, unknown> | undefined,\n k = c.publisher;\n if (\n !entry ||\n !c.matches ||\n entry.processName !== c.uns?.[\"processName\"] ||\n entry.configurationSha256 !== configurationAuthorizationHash(context.rawConfiguration) ||\n !j ||\n j[\"directory\"] !== p.directory ||\n (j[\"journalId\"] ?? null) !== p.journalId ||\n j[\"groupManifest\"] !== manifest.file\n )\n throw Error();\n if (context.initialize ? p.journalId !== null || entry.role !== \"receiver\" : p.journalId === null) throw Error();\n if (entry.role === \"receiver\" ? c.runtimeRole !== \"admission\" : c.runtimeRole !== undefined && c.runtimeRole !== \"publisher\") throw Error();\n const member = m.profiles.find((x) => x.processName === entry.processName),\n mapping = path.resolve(context.packageRoot, String(k[\"mappingFile\"]));\n if (\n entry.role !== \"source\"\n ? k[\"groupManifest\"] !== manifest.file\n : k[\"groupManifest\"] !== undefined ||\n k[\"dataGroup\"] !== member?.dataGroup ||\n !mapping.startsWith(context.packageRoot + path.sep) ||\n sha(read(mapping)) !== member?.mappingSha256\n )\n throw Error();\n const result = Object.freeze({\n sha256: sha(bytes),\n file,\n directory: p.directory,\n journalId: p.journalId,\n role: entry.role,\n groupId: p.groupId,\n groupProcessName: m.processName,\n namespace: d.namespace,\n });\n if (!candidate) issued.add(result);\n return result;\n } catch {\n throw Error(\"Process-group runtime authorization is missing, changed or does not match this installed placement; review required\");\n }\n}\n/** Live authority always comes from the current canonical private policy. */\nexport function authorizeProcessGroupRuntime(context: ProcessGroupAuthorizationContext): ProcessGroupAuthorization {\n return verifyRuntimePolicy(context);\n}\n/** Review only: never issues an authorization accepted by runtime/launch checks. */\nexport function validateProcessGroupPolicyCandidate(context: ProcessGroupAuthorizationContext, bytes: Buffer): void {\n verifyRuntimePolicy(context, bytes);\n}\nexport function processGroupAuthorizationFile(context: ProcessGroupAuthorizationContext): string {\n const root = context.stateRoot ?? process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root) throw Error(\"Missing process-group state root\");\n return selectedFile(context.packageRoot, context.rawConfiguration, root, context.file);\n}\nexport const authorizeHvRuntime = authorizeProcessGroupRuntime;\nexport function authorizeConfiguredProcessGroupRuntime(\n pkg: string,\n dir: string,\n raw: Record<string, unknown>,\n controllerName: string,\n initialize = false,\n) {\n return authorizeProcessGroupRuntime({\n packageRoot: pkg,\n instanceDirectory: dir,\n rawConfiguration: raw,\n channels: resolvedProcessGroupChannels(raw),\n controllerName,\n initialize,\n });\n}\nexport function assertProcessGroupJournalAuthorization(\n value: ProcessGroupAuthorization | undefined,\n directory: string,\n journalId: string | undefined,\n): void {\n if (value && issued.has(value)) {\n if (value.directory !== directory || value.journalId !== (journalId ?? null) || sha(read(value.file, true)) !== value.sha256)\n throw Error(\"Exact reviewed process-group authorization required\");\n return;\n }\n legacy.assertHvJournalAuthorization(value as legacy.HvAuthorization | undefined, directory, journalId);\n}\nexport const assertHvJournalAuthorization = assertProcessGroupJournalAuthorization;\nexport function assertProcessGroupStateMount(value: ProcessGroupAuthorization, root: string): void {\n if (!issued.has(value)) {\n legacy.assertHvStateMount(value as legacy.HvAuthorization, root);\n return;\n }\n assertProcessGroupJournalAuthorization(value, value.directory, value.journalId ?? undefined);\n if (process.platform !== \"linux\" || !(\"namespace\" in value) || value.directory !== path.join(root, value.namespace, \"admission\", value.generationId ?? value.groupId))\n throw Error(\"Process group requires its reviewed Linux state mount\");\n const mount = fs\n .readFileSync(\"/proc/self/mountinfo\", \"utf8\")\n .split(\"\\n\")\n .map((l) => l.split(\" \"))\n .filter((f) => f[4] === root)\n .at(-1);\n if (!mount || !mount[5]?.split(\",\").includes(\"rw\") || ![\"xfs\", \"ext4\", \"btrfs\", \"zfs\"].includes(mount[mount.indexOf(\"-\") + 1] ?? \"\"))\n throw Error(\"Process-group state root must be an explicit writable local Linux filesystem mount\");\n}\nexport const assertHvStateMount = assertProcessGroupStateMount;\nexport function assertProcessGroupTargetLaunch(\n value: ProcessGroupAuthorization,\n dir: string,\n operationId: string | undefined,\n launchId: string | undefined,\n): void {\n if (!issued.has(value)) {\n legacy.assertHvTargetLaunch(value as legacy.HvAuthorization, dir, operationId, launchId);\n return;\n }\n if (value.role !== \"target\") return;\n try {\n assertProcessGroupJournalAuthorization(value, value.directory, value.journalId ?? undefined);\n const r = JSON.parse(read(path.join(dir, \"process-group-reservation.json\"), true).toString());\n if (\n !z.string().uuid().safeParse(operationId).success ||\n !z.string().uuid().safeParse(launchId).success ||\n r.operationId !== operationId ||\n r.role !== \"target\" ||\n r.lastLaunch?.launchId !== launchId ||\n !z.string().uuid().safeParse(r.lastLaunch?.requestId).success ||\n !digest.safeParse(r.configurationChecksum).success\n )\n throw Error();\n if (\"configurationGroupSha256\" in value && value.configurationGroupSha256 !== undefined &&\n (r.configurationGroupSha256 !== value.configurationGroupSha256 || r.generationId !== value.generationId)) throw Error();\n } catch {\n throw Error(\"Target requires its exact reviewed group reservation and launch identity\");\n }\n}\nexport const assertHvTargetLaunch = assertProcessGroupTargetLaunch;\n"]}
1
+ {"version":3,"file":"process-group-authorization.js","sourceRoot":"","sources":["../../src/runtime/process-group-authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,MAAM,MAAM,+CAA+C,CAAC;AACxE,OAAO,EAAE,qCAAqC,EAAE,gCAAgC,EAAE,8BAA8B,EAAE,MAAM,wCAAwC,CAAC;AACjK,OAAO,EAAE,kCAAkC,EAAE,MAAM,oCAAoC,CAAC;AACxF,OAAO,EAEL,kCAAkC,EAClC,sBAAsB,EACtB,4BAA4B,GAC7B,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,8BAA8B,EAC9B,iBAAiB,EACjB,iBAAiB,EACjB,wBAAwB,IAAI,IAAI,EAChC,MAAM,IAAI,GAAG,EACb,kCAAkC,GACnC,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,8BAA8B,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEpH,MAAM,CAAC,MAAM,4BAA4B,GAAG,MAAM,CAAC,4BAA4B,CAAC;AAChF,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,gBAAgB,CAAC,EAC/C,EAAE,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAClD,MAAM,QAAQ,GAAG,CAAC;KACf,MAAM,EAAE;KACR,GAAG,CAAC,GAAG,CAAC;KACR,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAC9D,MAAM,SAAS,GAAG,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KAAK,CAAC,wBAAwB,KAAK,SAAS;YACrF,CAAC,CAAC,CAAC,wBAAwB,KAAK,KAAK,CAAC,wBAAwB,IAAI,CAAC,CAAC,YAAY,KAAK,KAAK,CAAC,YAAY,CAAC;YAAE,MAAM,KAAK,EAAE,CAAC;IAC5H,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,KAAK,CAAC,0EAA0E,CAAC,CAAC;IAC1F,CAAC;AACH,CAAC;AACD,MAAM,CAAC,MAAM,oBAAoB,GAAG,8BAA8B,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\n\nimport * as legacy from \"./compatibility/energenti-authorization-v1.js\";\nimport { configurationGroupAuthorizationSchema, configurationGroupPolicyIdentity, verifyConfigurationGroupPolicy } from \"./configuration-group-authorization.js\";\nimport { processGroupRetirementPolicySchema } from \"./process-group-direct-contract.js\";\nimport {\n type ProcessGroupRuntimeDescriptor,\n normalizeProcessGroupConfiguration,\n processGroupDescriptor,\n resolvedProcessGroupChannels,\n} from \"./process-group-contract.js\";\nimport {\n configurationAuthorizationHash,\n groupArtifactHash,\n groupChannelsHash,\n readProcessGroupResource as read,\n sha256 as sha,\n assertPrivateProcessGroupDirectory,\n} from \"./process-group-resources.js\";\n\nexport { configurationAuthorizationHash, groupArtifactHash, groupChannelsHash } from \"./process-group-resources.js\";\n\nexport const hasProcessGroupAuthorization = legacy.hasProcessGroupAuthorization;\nconst digest = z.string().regex(/^[a-f0-9]{64}$/),\n id = z.string().regex(/^[a-z][a-z0-9-]{0,99}$/);\nconst absolute = z\n .string()\n .max(512)\n .refine((v) => path.isAbsolute(v) && path.resolve(v) === v);\nconst placement = z.strictObject({\n instanceId: z.string().regex(/^[a-zA-Z0-9-]{1,100}$/),\n processName: id,\n role: z.enum([\"source\", \"target\", \"receiver\"]),\n configurationSha256: digest,\n});\nexport const processGroupAuthorizationSchema = z.strictObject({\n schemaVersion: z.literal(3),\n kind: z.literal(\"uns-process-group-runtime-authorization\"),\n protocolVersion: z.literal(1),\n packageName: z.string().min(1).max(214),\n namespace: id,\n groupId: id,\n descriptorSha256: digest,\n controllerName: z.string().min(1).max(100),\n packageRoot: absolute,\n artifactSha256: digest,\n groupManifestSha256: digest,\n channelsSha256: digest,\n stateRoot: absolute,\n directory: absolute,\n journalId: z.string().uuid().nullable(),\n placements: z.array(placement).min(4).max(18),\n});\nexport type ProcessGroupAuthorizationPolicy = z.infer<typeof processGroupAuthorizationSchema>;\nexport const processGroupManifestSchema = z.strictObject({\n schemaVersion: z.literal(1),\n id,\n inputTopic: z\n .string()\n .min(1)\n .max(512)\n .regex(/^[^#+\\0]+$/),\n processName: id,\n profiles: z\n .array(z.strictObject({ id, processName: id, mappingFile: z.string().min(1).max(512), mappingSha256: digest, dataGroup: id }))\n .min(2)\n .max(16),\n});\ninterface GenericAuthorization {\n readonly sha256: string;\n readonly file: string;\n readonly directory: string;\n readonly journalId: string | null;\n readonly role: \"source\" | \"target\" | \"receiver\";\n readonly groupId: string;\n readonly groupProcessName: string;\n readonly namespace: string;\n readonly generationId?: string;\n readonly configurationGroupSha256?: string;\n}\nexport type ProcessGroupAuthorization = legacy.HvAuthorization | GenericAuthorization;\nexport type HvAuthorization = ProcessGroupAuthorization;\nexport type HvAuthorizationPolicy = legacy.HvAuthorizationPolicy;\nexport const hvAuthorizationSchema = legacy.hvAuthorizationSchema;\nexport const productionGroupIds = legacy.productionGroupIds;\nconst issued = new WeakSet<object>();\nconst privateDirectory = assertPrivateProcessGroupDirectory;\n/** A retirement keeps the original journal/policy bound; older readers fail closed on schema5. */\nexport function parseProcessGroupRetirementPolicy(value:unknown) {\n const p=processGroupRetirementPolicySchema.parse(value);\n if(sha(p.sourcePolicyJson)!==p.sourcePolicySha256)throw Error(\"Original retirement policy bytes changed\");\n const raw=JSON.parse(p.sourcePolicyJson), original=raw.schemaVersion===4?configurationGroupAuthorizationSchema.parse(raw):processGroupAuthorizationSchema.parse(raw);\n const policyId=original.schemaVersion===4?original.generationId:original.groupId;\n if(original.packageName!==p.packageName||original.namespace!==p.namespace||original.groupId!==p.groupId||original.controllerName!==p.controllerName||original.stateRoot!==p.stateRoot||original.directory!==p.journal.directory||original.journalId!==p.journal.journalId||policyId!==p.journal.generationId||original.directory!==path.join(p.stateRoot,p.namespace,\"admission\",policyId)||original.channelsSha256!==p.target.channelsSha256)\n throw Error(\"Retirement journal or authority differs from original policy\");\n if((original.schemaVersion===4?original.groupSha256:original.groupManifestSha256)!==p.target.resourceSha256)\n throw Error(\"Retirement resource differs from original policy\");\n for(const role of [\"publisher\",\"receiver\"] as const){\n const m=p.source[role], before=original.placements.find(x=>x.role===(role===\"publisher\"?\"target\":\"receiver\"));\n if(!before||before.instanceId!==m.placement.instanceId||before.processName!==m.processName||before.configurationSha256!==m.policyConfigurationSha256||original.artifactSha256!==m.artifactSha256||m.placement.rttNode!==p.packageName)\n throw Error(\"Retirement source placement differs from original policy\");\n }\n if(p.target.placement.rttNode!==p.packageName||p.journal.profiles.some(x=>!original.placements.some(y=>y.role===\"source\"&&y.processName===x.processName)))\n throw Error(\"Retirement profile ownership differs\");\n return p;\n}\nfunction registryRoot(root: string, dir: string): string {\n if (!path.isAbsolute(root) || path.resolve(root) !== root || path.resolve(dir) !== dir) throw Error(\"Invalid policy registry\");\n privateDirectory(root);\n if (dir === root) return \"*\"; // Explicit collection of independently owned namespaces.\n const relative = path.relative(root, dir);\n if (!path.isAbsolute(root) || path.resolve(root) !== root || !/^([a-z][a-z0-9-]{0,99})\\/authorizations$/.test(relative))\n throw Error(\"Invalid policy registry\");\n privateDirectory(root);\n privateDirectory(dir);\n return relative.split(\"/\")[0]!;\n}\nfunction selectedFile(pkg: string, raw: Record<string, unknown>, root: string, explicit?: string): string {\n const configured = configurationGroupPolicyIdentity(pkg, raw);\n if (configured) {\n if (explicit) return explicit;\n const directory = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (directory) {\n const selected = registryRoot(root, directory);\n if (selected !== \"*\" && selected !== configured.namespace) throw Error(\"Foreign runtime registry\");\n const registry = selected === \"*\" ? path.join(root, configured.namespace, \"authorizations\") : directory;\n privateDirectory(registry);\n return path.join(registry, configured.generationId + \".json\");\n }\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (!single) throw Error(\"No selected policy\");\n return single;\n }\n const descriptor = processGroupDescriptor(pkg);\n if (!descriptor) throw Error(\"Missing runtime contract\");\n const c = normalizeProcessGroupConfiguration(raw, descriptor),\n journal = c.journal as Record<string, unknown> | undefined;\n const manifest = descriptor.manifests.find((m) => m.file === journal?.[\"groupManifest\"]);\n if (!manifest) throw Error(\"Unregistered group manifest\");\n const dir = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (explicit) return explicit;\n if (dir) {\n const selected = registryRoot(root, dir);\n if (selected !== \"*\" && selected !== descriptor.namespace) throw Error(\"Foreign runtime registry\");\n const registry = selected === \"*\" ? path.join(root, descriptor.namespace, \"authorizations\") : dir;\n privateDirectory(registry);\n return path.join(registry, manifest.id + \".json\");\n }\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (!single) throw Error(\"No selected policy\");\n return single;\n}\n/** Bounded private registry enumeration; retained state without its policy fails closed.\n * New groups are operator-owned data and never a release-time enum in the Controller.\n */\nexport function configuredGroupProcessNames(): Set<string> {\n if (!hasProcessGroupAuthorization()) return new Set();\n try {\n const root = process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root) throw Error();\n const files = new Set<string>();\n const single = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_FILE\"];\n if (single) files.add(single);\n const dir = process.env[\"UNS_PROCESS_GROUP_AUTHORIZATION_DIRECTORY\"];\n if (dir) {\n const selected = registryRoot(root, dir);\n let registries: { namespace: string; directory: string }[];\n if (selected === \"*\") {\n const namespaces = fs.readdirSync(root, { withFileTypes: true });\n if (namespaces.length > 64 || namespaces.some((e) => e.isSymbolicLink())) throw Error(\"Registry namespace budget or link violation\");\n registries = namespaces\n .filter((e) => e.isDirectory())\n .map((e) => {\n if (!id.safeParse(e.name).success) throw Error(\"Invalid registry namespace\");\n privateDirectory(path.join(root, e.name));\n return { namespace: e.name, directory: path.join(root, e.name, \"authorizations\") };\n });\n } else registries = [{ namespace: selected, directory: dir }];\n for (const registry of registries) {\n let entries: fs.Dirent[] = [];\n try {\n privateDirectory(registry.directory);\n entries = fs.readdirSync(registry.directory, { withFileTypes: true });\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"ENOENT\") throw e;\n }\n if (entries.length > 64) throw Error(\"Policy registry budget exceeded\");\n for (const entry of entries)\n if (entry.name.endsWith(\".json\")) {\n if (!/^[a-z][a-z0-9-]{0,99}\\.json$/.test(entry.name)) throw Error(\"Invalid registry entry\");\n files.add(path.join(registry.directory, entry.name));\n if (files.size > 64) throw Error(\"Total policy registry budget exceeded\");\n }\n const journals = path.join(root, registry.namespace, \"admission\");\n try {\n // Root/registry permissions already protect visibility; retain old parent modes.\n for (let parent = journals; parent !== path.dirname(parent); parent = path.dirname(parent))\n if (fs.lstatSync(parent).isSymbolicLink()) throw Error(\"Linked journal registry\");\n const retained = fs.readdirSync(journals, { withFileTypes: true });\n if (retained.length > 64) throw Error(\"Retained journal budget exceeded\");\n for (const entry of retained)\n if (\n !id.safeParse(entry.name).success ||\n entry.isSymbolicLink() ||\n !entry.isDirectory() ||\n !files.has(path.join(registry.directory, entry.name + \".json\"))\n )\n throw Error(\"Retained journal has no reviewed policy\");\n } catch (e) {\n if ((e as NodeJS.ErrnoException).code !== \"ENOENT\") throw e;\n }\n }\n }\n const result = new Set<string>();\n for (const file of files) {\n const raw = JSON.parse(read(file, true).toString());\n if(raw.schemaVersion===5){\n const p=parseProcessGroupRetirementPolicy(raw);\n if(p.stateRoot!==root||file!==path.join(root,p.namespace,\"authorizations\",p.journal.generationId+\".json\"))throw Error(\"Retirement registry binding differs\");\n privateDirectory(root);privateDirectory(path.dirname(file));\n for(const member of [...p.journal.profiles,p.source.publisher,p.source.receiver])result.add(member.processName);\n continue;\n }\n const p =\n raw.schemaVersion === 4 ? configurationGroupAuthorizationSchema.parse(raw) : raw.schemaVersion === 3\n ? processGroupAuthorizationSchema.parse(raw)\n : z.union([legacy.hvAuthorizationSchema, legacy.processGroupAuthorizationSchema]).parse(raw);\n const { namespace, group } = p.schemaVersion === 4 ? { namespace: p.namespace, group: p.generationId }\n : p.schemaVersion === 3 ? { namespace: p.namespace, group: p.groupId } : legacy.legacyPolicyIdentity(p);\n if (\n p.stateRoot !== root ||\n file !== path.join(root, namespace, \"authorizations\", group + \".json\") ||\n p.directory !== path.join(root, namespace, \"admission\", group)\n )\n throw Error();\n privateDirectory(root);\n privateDirectory(path.dirname(file));\n for (const role of p.placements) result.add(role.processName);\n }\n return result;\n } catch {\n throw Error(\"Process-group authorization registry is missing, changed or insecure; review required\");\n }\n}\nexport interface ProcessGroupAuthorizationContext {\n packageRoot: string;\n instanceDirectory: string;\n rawConfiguration: Record<string, unknown>;\n channels: unknown[];\n controllerName: string;\n file?: string;\n stateRoot?: string;\n initialize?: boolean;\n}\nfunction verifyRuntimePolicy(context: ProcessGroupAuthorizationContext, candidate?: Buffer): ProcessGroupAuthorization {\n try {\n const root = context.stateRoot ?? process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root || !context.controllerName) throw Error();\n const file = selectedFile(context.packageRoot, context.rawConfiguration, root, context.file),\n bytes = candidate ?? read(file, true),\n unparsed = JSON.parse(bytes.toString());\n if (unparsed.schemaVersion === 4) {\n const result = verifyConfigurationGroupPolicy(context, bytes, root, file);\n if (!candidate) issued.add(result);\n return result;\n }\n if (unparsed.schemaVersion !== 3) {\n if (candidate) throw Error(\"Only generic policies can be staged\");\n return legacy.authorizeHvRuntime({ ...context, file, stateRoot: root });\n }\n const p = processGroupAuthorizationSchema.parse(unparsed),\n d = processGroupDescriptor(context.packageRoot);\n if (!d || d.legacy) throw Error(\"Generic runtime descriptor required\");\n const pkg = JSON.parse(read(path.join(context.packageRoot, \"package.json\")).toString());\n const manifest = d.manifests.find((m) => m.id === p.groupId);\n if (\n !manifest ||\n p.packageName !== pkg.name ||\n p.namespace !== d.namespace ||\n p.descriptorSha256 !== configurationAuthorizationHash(pkg.unsDatahub.processGroupRuntime) ||\n p.packageRoot !== context.packageRoot ||\n p.controllerName !== context.controllerName ||\n p.stateRoot !== root ||\n file !== path.join(root, d.namespace, \"authorizations\", p.groupId + \".json\") ||\n p.directory !== path.join(root, d.namespace, \"admission\", p.groupId)\n )\n throw Error();\n privateDirectory(root);\n privateDirectory(path.dirname(file));\n if (groupArtifactHash(context.packageRoot) !== p.artifactSha256 || groupChannelsHash(context.channels) !== p.channelsSha256) throw Error();\n const manifestBytes = read(path.join(context.packageRoot, manifest.file));\n if (sha(manifestBytes) !== p.groupManifestSha256) throw Error();\n const m = processGroupManifestSchema.parse(JSON.parse(manifestBytes.toString()));\n if (m.id !== p.groupId) throw Error();\n const receiver = m.processName + \"-admission\";\n if (\n new Set(m.profiles.map((x) => x.id)).size !== m.profiles.length ||\n new Set(m.profiles.map((x) => x.processName)).size !== m.profiles.length ||\n m.profiles.some((x) => x.processName === m.processName || x.processName === receiver)\n )\n throw Error();\n for (const member of m.profiles) {\n const f = path.resolve(context.packageRoot, path.dirname(manifest.file), member.mappingFile);\n if (!f.startsWith(context.packageRoot + path.sep) || sha(read(f)) !== member.mappingSha256) throw Error();\n }\n const expected = new Map([\n ...m.profiles.map((x) => [x.processName, \"source\"] as const),\n [m.processName, \"target\"] as const,\n [receiver, \"receiver\"] as const,\n ]);\n if (\n p.placements.length !== expected.size ||\n new Set(p.placements.map((x) => x.instanceId)).size !== expected.size ||\n new Set(p.placements.map((x) => x.processName)).size !== expected.size ||\n p.placements.some((x) => expected.get(x.processName) !== x.role)\n )\n throw Error();\n const entry = p.placements.find((x) => context.instanceDirectory === path.join(context.packageRoot, \"instances\", x.instanceId));\n const c = normalizeProcessGroupConfiguration(context.rawConfiguration, d),\n j = c.journal as Record<string, unknown> | undefined,\n k = c.publisher;\n if (\n !entry ||\n !c.matches ||\n entry.processName !== c.uns?.[\"processName\"] ||\n entry.configurationSha256 !== configurationAuthorizationHash(context.rawConfiguration) ||\n !j ||\n j[\"directory\"] !== p.directory ||\n (j[\"journalId\"] ?? null) !== p.journalId ||\n j[\"groupManifest\"] !== manifest.file\n )\n throw Error();\n if (context.initialize ? p.journalId !== null || entry.role !== \"receiver\" : p.journalId === null) throw Error();\n if (entry.role === \"receiver\" ? c.runtimeRole !== \"admission\" : c.runtimeRole !== undefined && c.runtimeRole !== \"publisher\") throw Error();\n const member = m.profiles.find((x) => x.processName === entry.processName),\n mapping = path.resolve(context.packageRoot, String(k[\"mappingFile\"]));\n if (\n entry.role !== \"source\"\n ? k[\"groupManifest\"] !== manifest.file\n : k[\"groupManifest\"] !== undefined ||\n k[\"dataGroup\"] !== member?.dataGroup ||\n !mapping.startsWith(context.packageRoot + path.sep) ||\n sha(read(mapping)) !== member?.mappingSha256\n )\n throw Error();\n const result = Object.freeze({\n sha256: sha(bytes),\n file,\n directory: p.directory,\n journalId: p.journalId,\n role: entry.role,\n groupId: p.groupId,\n groupProcessName: m.processName,\n namespace: d.namespace,\n });\n if (!candidate) issued.add(result);\n return result;\n } catch {\n throw Error(\"Process-group runtime authorization is missing, changed or does not match this installed placement; review required\");\n }\n}\n/** Live authority always comes from the current canonical private policy. */\nexport function authorizeProcessGroupRuntime(context: ProcessGroupAuthorizationContext): ProcessGroupAuthorization {\n return verifyRuntimePolicy(context);\n}\n/** Review only: never issues an authorization accepted by runtime/launch checks. */\nexport function validateProcessGroupPolicyCandidate(context: ProcessGroupAuthorizationContext, bytes: Buffer): void {\n verifyRuntimePolicy(context, bytes);\n}\nexport function processGroupAuthorizationFile(context: ProcessGroupAuthorizationContext): string {\n const root = context.stateRoot ?? process.env[\"UNS_PROCESS_GROUP_STATE_ROOT\"];\n if (!root) throw Error(\"Missing process-group state root\");\n return selectedFile(context.packageRoot, context.rawConfiguration, root, context.file);\n}\nexport const authorizeHvRuntime = authorizeProcessGroupRuntime;\nexport function authorizeConfiguredProcessGroupRuntime(\n pkg: string,\n dir: string,\n raw: Record<string, unknown>,\n controllerName: string,\n initialize = false,\n) {\n return authorizeProcessGroupRuntime({\n packageRoot: pkg,\n instanceDirectory: dir,\n rawConfiguration: raw,\n channels: resolvedProcessGroupChannels(raw),\n controllerName,\n initialize,\n });\n}\nexport function assertProcessGroupJournalAuthorization(\n value: ProcessGroupAuthorization | undefined,\n directory: string,\n journalId: string | undefined,\n): void {\n if (value && issued.has(value)) {\n if (value.directory !== directory || value.journalId !== (journalId ?? null) || sha(read(value.file, true)) !== value.sha256)\n throw Error(\"Exact reviewed process-group authorization required\");\n return;\n }\n legacy.assertHvJournalAuthorization(value as legacy.HvAuthorization | undefined, directory, journalId);\n}\nexport const assertHvJournalAuthorization = assertProcessGroupJournalAuthorization;\nexport function assertProcessGroupStateMount(value: ProcessGroupAuthorization, root: string): void {\n if (!issued.has(value)) {\n legacy.assertHvStateMount(value as legacy.HvAuthorization, root);\n return;\n }\n assertProcessGroupJournalAuthorization(value, value.directory, value.journalId ?? undefined);\n if (process.platform !== \"linux\" || !(\"namespace\" in value) || value.directory !== path.join(root, value.namespace, \"admission\", value.generationId ?? value.groupId))\n throw Error(\"Process group requires its reviewed Linux state mount\");\n const mount = fs\n .readFileSync(\"/proc/self/mountinfo\", \"utf8\")\n .split(\"\\n\")\n .map((l) => l.split(\" \"))\n .filter((f) => f[4] === root)\n .at(-1);\n if (!mount || !mount[5]?.split(\",\").includes(\"rw\") || ![\"xfs\", \"ext4\", \"btrfs\", \"zfs\"].includes(mount[mount.indexOf(\"-\") + 1] ?? \"\"))\n throw Error(\"Process-group state root must be an explicit writable local Linux filesystem mount\");\n}\nexport const assertHvStateMount = assertProcessGroupStateMount;\nexport function assertProcessGroupTargetLaunch(\n value: ProcessGroupAuthorization,\n dir: string,\n operationId: string | undefined,\n launchId: string | undefined,\n): void {\n if (!issued.has(value)) {\n legacy.assertHvTargetLaunch(value as legacy.HvAuthorization, dir, operationId, launchId);\n return;\n }\n if (value.role !== \"target\") return;\n try {\n assertProcessGroupJournalAuthorization(value, value.directory, value.journalId ?? undefined);\n const r = JSON.parse(read(path.join(dir, \"process-group-reservation.json\"), true).toString());\n if (\n !z.string().uuid().safeParse(operationId).success ||\n !z.string().uuid().safeParse(launchId).success ||\n r.operationId !== operationId ||\n r.role !== \"target\" ||\n r.lastLaunch?.launchId !== launchId ||\n !z.string().uuid().safeParse(r.lastLaunch?.requestId).success ||\n !digest.safeParse(r.configurationChecksum).success\n )\n throw Error();\n if (\"configurationGroupSha256\" in value && value.configurationGroupSha256 !== undefined &&\n (r.configurationGroupSha256 !== value.configurationGroupSha256 || r.generationId !== value.generationId)) throw Error();\n } catch {\n throw Error(\"Target requires its exact reviewed group reservation and launch identity\");\n }\n}\nexport const assertHvTargetLaunch = assertProcessGroupTargetLaunch;\n"]}
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  export { legacyDescriptorForPackage, legacyEnergentiDescriptor } from "./compatibility/energenti-descriptor-v1.js";
3
3
  export declare const processGroupProtocolVersion: 1;
4
+ export declare const processGroupConfigurationSelectorSchema: z.ZodArray<z.ZodString>;
4
5
  export declare const processGroupRuntimeDescriptorSchema: z.ZodObject<{
5
6
  protocolVersion: z.ZodLiteral<1>;
6
7
  namespace: z.ZodString;
@@ -1 +1 @@
1
- {"version":3,"file":"process-group-contract.d.ts","sourceRoot":"","sources":["../../src/runtime/process-group-contract.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEnH,eAAO,MAAM,2BAA2B,EAAG,CAAU,CAAC;AAgBtD,eAAO,MAAM,mCAAmC;;;;;;;;;;;;;;;;kBAqB5C,CAAC;AACL,MAAM,MAAM,6BAA6B,GAAG,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CAAC,MAAM,EAAE,OAAO,CAAC,+DAE5E;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE;IAChD,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7B,OAAO,CAAC,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC;CACjC,GAAG,MAAM,CAUT;AACD,wBAAgB,2BAA2B,CACzC,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,IAAI,CAAC,gCAAgC,EAAE,YAAY,GAAG,UAAU,CAAC,EACzE,QAAQ,EAAE,0BAA0B,EAAE,GACrC,MAAM,CAUR"}
@@ -10,13 +10,14 @@ import { readProcessGroupResource, sha256 } from "./process-group-resources.js";
10
10
  export { legacyDescriptorForPackage, legacyEnergentiDescriptor } from "./compatibility/energenti-descriptor-v1.js";
11
11
  export const processGroupProtocolVersion = 1;
12
12
  const identity = z.string().regex(/^[a-z][a-z0-9-]{0,99}$/);
13
- const selector = z
13
+ export const processGroupConfigurationSelectorSchema = z
14
14
  .array(z
15
15
  .string()
16
16
  .regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/)
17
17
  .refine((v) => !["__proto__", "constructor", "prototype"].includes(v)))
18
18
  .min(1)
19
19
  .max(8);
20
+ const selector = processGroupConfigurationSelectorSchema;
20
21
  const relative = z
21
22
  .string()
22
23
  .min(1)
@@ -1 +1 @@
1
- {"version":3,"file":"process-group-contract.js","sourceRoot":"","sources":["../../src/runtime/process-group-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAA0B,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;A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AAC,KAAK,IAAI,EAAE;QACxB,OAAO,EAAE,KAAK,CAAC,OAAO,IAAI,EAAE;KAC7B,CAAC,CACH,CAAC;AACJ,CAAC;AACD,MAAM,UAAU,2BAA2B,CACzC,cAAsB,EACtB,MAAyE,EACzE,QAAsC;IAEtC,OAAO,IAAI,CAAC,SAAS,CAAC;QACpB,OAAO,EAAE,CAAC;QACV,cAAc;QACd,UAAU,EAAE,MAAM,CAAC,UAAU;QAC7B,QAAQ,EAAE,MAAM,CAAC,QAAQ;QACzB,QAAQ,EAAE,QAAQ;aACf,GAAG,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,WAAW,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC,CAAC;aAC/F,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC;KAC9D,CAAC,CAAC;AACL,CAAC","sourcesContent":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\n\nimport { type MqttChannelConfig, resolveMqttChannel } from \"../uns-config/mqtt-channel.js\";\nimport { legacyDescriptorForPackage, legacyEnergentiDescriptor } from \"./compatibility/energenti-descriptor-v1.js\";\n/** Versioned, data-only contract for same-host MQTT journal process groups.\n * Package declarations describe resources; only private operator policies grant authority.\n */\nimport { readProcessGroupResource, sha256 } from \"./process-group-resources.js\";\n\nexport { legacyDescriptorForPackage, legacyEnergentiDescriptor } from \"./compatibility/energenti-descriptor-v1.js\";\n\nexport const processGroupProtocolVersion = 1 as const;\nconst identity = z.string().regex(/^[a-z][a-z0-9-]{0,99}$/);\nconst selector = z\n .array(\n z\n .string()\n .regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/)\n .refine((v) => ![\"__proto__\", \"constructor\", \"prototype\"].includes(v)),\n )\n .min(1)\n .max(8);\nconst relative = z\n .string()\n .min(1)\n .max(512)\n .refine((v) => !path.isAbsolute(v) && path.normalize(v) === v && !v.split(/[\\\\/]/).some((x) => x === \"..\" || x === \".\") && !v.includes(\"\\0\"));\nexport const processGroupRuntimeDescriptorSchema = z\n .strictObject({\n protocolVersion: z.literal(1),\n namespace: identity,\n publisherPath: selector,\n journalPath: selector,\n runtimeRolePath: selector,\n receiverRole: identity,\n defaultDataGroup: identity.optional(),\n match: z.strictObject({ path: selector, value: z.string().min(1).max(100) }).optional(),\n manifests: z\n .array(z.strictObject({ id: identity, file: relative }))\n .min(1)\n .max(64),\n })\n .superRefine((d, c) => {\n if (new Set(d.manifests.map((v) => v.id)).size !== d.manifests.length || new Set(d.manifests.map((v) => v.file)).size !== d.manifests.length)\n c.addIssue({ code: \"custom\", message: \"Distinct group manifests required\" });\n const paths = [d.publisherPath, d.journalPath, d.runtimeRolePath].map((v) => v.join(\".\"));\n if (new Set(paths).size !== paths.length || paths.some((p, i) => paths.some((other, j) => i !== j && other.startsWith(p + \".\"))))\n c.addIssue({ code: \"custom\", message: \"Distinct configuration selectors required\" });\n });\nexport type ProcessGroupRuntimeDescriptor = z.infer<typeof processGroupRuntimeDescriptorSchema> & { legacy?: true };\nexport function readConfigurationSelector(raw: unknown, keys: readonly string[]): unknown {\n let value: unknown = raw;\n for (const key of keys) {\n if (!value || typeof value !== \"object\" || Array.isArray(value) || !Object.hasOwn(value, key)) return undefined;\n value = (value as Record<string, unknown>)[key];\n }\n return value;\n}\n/** Strictly bounded package metadata, no executable application adapter in the Controller. */\nexport function processGroupDescriptor(packageRoot: string): ProcessGroupRuntimeDescriptor | undefined {\n const file = path.join(packageRoot, \"package.json\");\n if (!fs.existsSync(file)) return undefined;\n // Discovery must not impose journal path rules on unrelated Node/Python packages.\n const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);\n let bytes: Buffer;\n try {\n const stat = fs.fstatSync(fd);\n if (!stat.isFile() || stat.size > 1024 * 1024) throw Error(\"Invalid installed runtime metadata\");\n bytes = fs.readFileSync(fd);\n if (bytes.length > 1024 * 1024) throw Error(\"Installed runtime metadata is too large\");\n } finally {\n fs.closeSync(fd);\n }\n const pkg = JSON.parse(bytes.toString());\n const declared = pkg.unsDatahub?.processGroupRuntime;\n const descriptor =\n declared !== undefined\n ? processGroupRuntimeDescriptorSchema.parse(declared)\n : [1, 2, 3].includes(pkg.unsDatahub?.processGroupProductionAuthorization)\n ? legacyDescriptorForPackage(String(pkg.name))\n : undefined;\n // Opted-in groups still require canonical, unchanged, unlinked installed resources.\n if (descriptor && !readProcessGroupResource(file).equals(bytes)) throw Error(\"Installed runtime metadata changed during discovery\");\n return descriptor;\n}\nexport function normalizeProcessGroupConfiguration(raw: Record<string, unknown>, d: ProcessGroupRuntimeDescriptor) {\n const publisher = readConfigurationSelector(raw, d.publisherPath) as Record<string, unknown> | undefined;\n const role = readConfigurationSelector(raw, d.runtimeRolePath);\n return {\n ...raw,\n uns: raw[\"uns\"] as Record<string, unknown>,\n publisher: publisher ?? {},\n journal: readConfigurationSelector(raw, d.journalPath),\n runtimeRole: role === d.receiverRole ? \"admission\" : role,\n matches: !d.match || readConfigurationSelector(raw, d.match.path) === d.match.value,\n };\n}\nexport function projectProcessGroupConfiguration(\n raw: Record<string, unknown>,\n d: ProcessGroupRuntimeDescriptor,\n uns: Record<string, unknown>,\n authorizationSha256?: string,\n): Record<string, unknown> {\n const projection = structuredClone(raw);\n projection[\"uns\"] = uns;\n let value = projection;\n for (const key of d.publisherPath.slice(0, -1)) {\n const child = value[key];\n if (!child || typeof child !== \"object\" || Array.isArray(child)) throw Error(\"Invalid publisher projection\");\n value = child as Record<string, unknown>;\n }\n delete value[d.publisherPath.at(-1)!];\n if (authorizationSha256) projection[\"authorizationSha256\"] = authorizationSha256;\n return projection;\n}\nexport function resolvedProcessGroupChannels(raw: Record<string, unknown>, _d?: ProcessGroupRuntimeDescriptor) {\n const infra = (raw[\"infra\"] ?? {}) as MqttChannelConfig;\n return [\n resolveMqttChannel(infra),\n resolveMqttChannel(infra, (raw[\"input\"] ?? {}) as MqttChannelConfig),\n resolveMqttChannel(infra, (raw[\"output\"] ?? {}) as MqttChannelConfig),\n ];\n}\nexport function isLocalPilotPath(value: string, platform = process.platform): boolean {\n return path.resolve(value) === value && (value.startsWith(\"/private/tmp/\") || (platform === \"linux\" && value.startsWith(\"/tmp/\")));\n}\nexport function isProcessGroupJournalPath(root: string, directory: string, namespace: string): boolean {\n return (\n path.isAbsolute(root) &&\n path.resolve(root) === root &&\n new RegExp(`^${namespace}/admission/[a-z][a-z0-9-]{0,99}$`).test(path.relative(root, directory))\n );\n}\nexport const processGroupJournalSchema = z.strictObject({\n directory: z.string().startsWith(\"/\").max(512),\n journalId: z.string().uuid().optional(),\n minFreeBytes: z\n .number()\n .int()\n .min(1024 * 1024)\n .max(1024 * 1024 * 1024)\n .default(64 * 1024 * 1024),\n groupManifest: z.string().min(1).max(512),\n maxRecords: z.number().int().min(1).max(100000).default(20000),\n maxBytes: z\n .number()\n .int()\n .min(1024)\n .max(256 * 1024 * 1024)\n .default(32 * 1024 * 1024),\n});\nexport type ProcessGroupJournalConfiguration = z.infer<typeof processGroupJournalSchema>;\nexport interface ProcessGroupJournalProfile {\n processName: string;\n mappingSha256: string;\n dataGroup: string;\n}\nexport interface ProcessGroupJournalTask {\n profile: string;\n payload: string;\n}\n\nexport function resolvedProcessGroupInputChannel(raw: Record<string, unknown>) {\n return resolveMqttChannel((raw[\"infra\"] ?? {}) as MqttChannelConfig, (raw[\"input\"] ?? {}) as MqttChannelConfig);\n}\n\nexport function processGroupSourceIdentity(input: {\n host: string;\n port?: number | undefined;\n protocol?: string | undefined;\n hosts?: string[] | undefined;\n servers?: unknown[] | undefined;\n}): string {\n return sha256(\n JSON.stringify({\n host: input.host,\n port: input.port ?? 1883,\n protocol: input.protocol ?? \"mqtt\",\n hosts: input.hosts ?? [],\n servers: input.servers ?? [],\n }),\n );\n}\nexport function processGroupJournalContract(\n sourceIdentity: string,\n config: Pick<ProcessGroupJournalConfiguration, \"maxRecords\" | \"maxBytes\">,\n profiles: ProcessGroupJournalProfile[],\n): string {\n return JSON.stringify({\n version: 1,\n sourceIdentity,\n maxRecords: config.maxRecords,\n maxBytes: config.maxBytes,\n profiles: profiles\n .map(({ processName, mappingSha256, dataGroup }) => ({ processName, mappingSha256, dataGroup }))\n .sort((a, b) => a.processName.localeCompare(b.processName)),\n });\n}\n"]}
1
+ {"version":3,"file":"process-group-contract.js","sourceRoot":"","sources":["../../src/runtime/process-group-contract.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAA0B,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAC3F,OAAO,EAAE,0BAA0B,EAA6B,MAAM,4CAA4C,CAAC;AACnH;;GAEG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEhF,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAE,MAAM,4CAA4C,CAAC;AAEnH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CAAU,CAAC;AACtD,MAAM,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC;AAC5D,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC;KACrD,KAAK,CACJ,CAAC;KACE,MAAM,EAAE;KACR,KAAK,CAAC,+BAA+B,CAAC;KACtC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACzE;KACA,GAAG,CAAC,CAAC,CAAC;KACN,GAAG,CAAC,CAAC,CAAC,CAAC;AACV,MAAM,QAAQ,GAAG,uCAAuC,CAAC;AACzD,MA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":["import fs from \"node:fs\";\nimport path from \"node:path\";\nimport { z } from \"zod\";\n\nimport { type MqttChannelConfig, resolveMqttChannel } from \"../uns-config/mqtt-channel.js\";\nimport { legacyDescriptorForPackage, legacyEnergentiDescriptor } from \"./compatibility/energenti-descriptor-v1.js\";\n/** Versioned, data-only contract for same-host MQTT journal process groups.\n * Package declarations describe resources; only private operator policies grant authority.\n */\nimport { readProcessGroupResource, sha256 } from \"./process-group-resources.js\";\n\nexport { legacyDescriptorForPackage, legacyEnergentiDescriptor } from \"./compatibility/energenti-descriptor-v1.js\";\n\nexport const processGroupProtocolVersion = 1 as const;\nconst identity = z.string().regex(/^[a-z][a-z0-9-]{0,99}$/);\nexport const processGroupConfigurationSelectorSchema = z\n .array(\n z\n .string()\n .regex(/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/)\n .refine((v) => ![\"__proto__\", \"constructor\", \"prototype\"].includes(v)),\n )\n .min(1)\n .max(8);\nconst selector = processGroupConfigurationSelectorSchema;\nconst relative = z\n .string()\n .min(1)\n .max(512)\n .refine((v) => !path.isAbsolute(v) && path.normalize(v) === v && !v.split(/[\\\\/]/).some((x) => x === \"..\" || x === \".\") && !v.includes(\"\\0\"));\nexport const processGroupRuntimeDescriptorSchema = z\n .strictObject({\n protocolVersion: z.literal(1),\n namespace: identity,\n publisherPath: selector,\n journalPath: selector,\n runtimeRolePath: selector,\n receiverRole: identity,\n defaultDataGroup: identity.optional(),\n match: z.strictObject({ path: selector, value: z.string().min(1).max(100) }).optional(),\n manifests: z\n .array(z.strictObject({ id: identity, file: relative }))\n .min(1)\n .max(64),\n })\n .superRefine((d, c) => {\n if (new Set(d.manifests.map((v) => v.id)).size !== d.manifests.length || new Set(d.manifests.map((v) => v.file)).size !== d.manifests.length)\n c.addIssue({ code: \"custom\", message: \"Distinct group manifests required\" });\n const paths = [d.publisherPath, d.journalPath, d.runtimeRolePath].map((v) => v.join(\".\"));\n if (new Set(paths).size !== paths.length || paths.some((p, i) => paths.some((other, j) => i !== j && other.startsWith(p + \".\"))))\n c.addIssue({ code: \"custom\", message: \"Distinct configuration selectors required\" });\n });\nexport type ProcessGroupRuntimeDescriptor = z.infer<typeof processGroupRuntimeDescriptorSchema> & { legacy?: true };\nexport function readConfigurationSelector(raw: unknown, keys: readonly string[]): unknown {\n let value: unknown = raw;\n for (const key of keys) {\n if (!value || typeof value !== \"object\" || Array.isArray(value) || !Object.hasOwn(value, key)) return undefined;\n value = (value as Record<string, unknown>)[key];\n }\n return value;\n}\n/** Strictly bounded package metadata, no executable application adapter in the Controller. */\nexport function processGroupDescriptor(packageRoot: string): ProcessGroupRuntimeDescriptor | undefined {\n const file = path.join(packageRoot, \"package.json\");\n if (!fs.existsSync(file)) return undefined;\n // Discovery must not impose journal path rules on unrelated Node/Python packages.\n const fd = fs.openSync(file, fs.constants.O_RDONLY | fs.constants.O_NOFOLLOW);\n let bytes: Buffer;\n try {\n const stat = fs.fstatSync(fd);\n if (!stat.isFile() || stat.size > 1024 * 1024) throw Error(\"Invalid installed runtime metadata\");\n bytes = fs.readFileSync(fd);\n if (bytes.length > 1024 * 1024) throw Error(\"Installed runtime metadata is too large\");\n } finally {\n fs.closeSync(fd);\n }\n const pkg = JSON.parse(bytes.toString());\n const declared = pkg.unsDatahub?.processGroupRuntime;\n const descriptor =\n declared !== undefined\n ? processGroupRuntimeDescriptorSchema.parse(declared)\n : [1, 2, 3].includes(pkg.unsDatahub?.processGroupProductionAuthorization)\n ? legacyDescriptorForPackage(String(pkg.name))\n : undefined;\n // Opted-in groups still require canonical, unchanged, unlinked installed resources.\n if (descriptor && !readProcessGroupResource(file).equals(bytes)) throw Error(\"Installed runtime metadata changed during discovery\");\n return descriptor;\n}\nexport function normalizeProcessGroupConfiguration(raw: Record<string, unknown>, d: ProcessGroupRuntimeDescriptor) {\n const publisher = readConfigurationSelector(raw, d.publisherPath) as Record<string, unknown> | undefined;\n const role = readConfigurationSelector(raw, d.runtimeRolePath);\n return {\n ...raw,\n uns: raw[\"uns\"] as Record<string, unknown>,\n publisher: publisher ?? {},\n journal: readConfigurationSelector(raw, d.journalPath),\n runtimeRole: role === d.receiverRole ? \"admission\" : role,\n matches: !d.match || readConfigurationSelector(raw, d.match.path) === d.match.value,\n };\n}\nexport function projectProcessGroupConfiguration(\n raw: Record<string, unknown>,\n d: ProcessGroupRuntimeDescriptor,\n uns: Record<string, unknown>,\n authorizationSha256?: string,\n): Record<string, unknown> {\n const projection = structuredClone(raw);\n projection[\"uns\"] = uns;\n let value = projection;\n for (const key of d.publisherPath.slice(0, -1)) {\n const child = value[key];\n if (!child || typeof child !== \"object\" || Array.isArray(child)) throw Error(\"Invalid publisher projection\");\n value = child as Record<string, unknown>;\n }\n delete value[d.publisherPath.at(-1)!];\n if (authorizationSha256) projection[\"authorizationSha256\"] = authorizationSha256;\n return projection;\n}\nexport function resolvedProcessGroupChannels(raw: Record<string, unknown>, _d?: ProcessGroupRuntimeDescriptor) {\n const infra = (raw[\"infra\"] ?? {}) as MqttChannelConfig;\n return [\n resolveMqttChannel(infra),\n resolveMqttChannel(infra, (raw[\"input\"] ?? {}) as MqttChannelConfig),\n resolveMqttChannel(infra, (raw[\"output\"] ?? {}) as MqttChannelConfig),\n ];\n}\nexport function isLocalPilotPath(value: string, platform = process.platform): boolean {\n return path.resolve(value) === value && (value.startsWith(\"/private/tmp/\") || (platform === \"linux\" && value.startsWith(\"/tmp/\")));\n}\nexport function isProcessGroupJournalPath(root: string, directory: string, namespace: string): boolean {\n return (\n path.isAbsolute(root) &&\n path.resolve(root) === root &&\n new RegExp(`^${namespace}/admission/[a-z][a-z0-9-]{0,99}$`).test(path.relative(root, directory))\n );\n}\nexport const processGroupJournalSchema = z.strictObject({\n directory: z.string().startsWith(\"/\").max(512),\n journalId: z.string().uuid().optional(),\n minFreeBytes: z\n .number()\n .int()\n .min(1024 * 1024)\n .max(1024 * 1024 * 1024)\n .default(64 * 1024 * 1024),\n groupManifest: z.string().min(1).max(512),\n maxRecords: z.number().int().min(1).max(100000).default(20000),\n maxBytes: z\n .number()\n .int()\n .min(1024)\n .max(256 * 1024 * 1024)\n .default(32 * 1024 * 1024),\n});\nexport type ProcessGroupJournalConfiguration = z.infer<typeof processGroupJournalSchema>;\nexport interface ProcessGroupJournalProfile {\n processName: string;\n mappingSha256: string;\n dataGroup: string;\n}\nexport interface ProcessGroupJournalTask {\n profile: string;\n payload: string;\n}\n\nexport function resolvedProcessGroupInputChannel(raw: Record<string, unknown>) {\n return resolveMqttChannel((raw[\"infra\"] ?? {}) as MqttChannelConfig, (raw[\"input\"] ?? {}) as MqttChannelConfig);\n}\n\nexport function processGroupSourceIdentity(input: {\n host: string;\n port?: number | undefined;\n protocol?: string | undefined;\n hosts?: string[] | undefined;\n servers?: unknown[] | undefined;\n}): string {\n return sha256(\n JSON.stringify({\n host: input.host,\n port: input.port ?? 1883,\n protocol: input.protocol ?? \"mqtt\",\n hosts: input.hosts ?? [],\n servers: input.servers ?? [],\n }),\n );\n}\nexport function processGroupJournalContract(\n sourceIdentity: string,\n config: Pick<ProcessGroupJournalConfiguration, \"maxRecords\" | \"maxBytes\">,\n profiles: ProcessGroupJournalProfile[],\n): string {\n return JSON.stringify({\n version: 1,\n sourceIdentity,\n maxRecords: config.maxRecords,\n maxBytes: config.maxBytes,\n profiles: profiles\n .map(({ processName, mappingSha256, dataGroup }) => ({ processName, mappingSha256, dataGroup }))\n .sort((a, b) => a.processName.localeCompare(b.processName)),\n });\n}\n"]}