@fractalcode/bridge 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.
- package/LICENSE +201 -0
- package/NOTICE +11 -0
- package/README.md +69 -0
- package/dist/src/cli.d.ts +16 -0
- package/dist/src/cli.js +241 -0
- package/dist/src/compiler/index.d.ts +26 -0
- package/dist/src/compiler/index.js +137 -0
- package/dist/src/compiler/mappings.d.ts +31 -0
- package/dist/src/compiler/mappings.js +316 -0
- package/dist/src/compiler/serialize.d.ts +23 -0
- package/dist/src/compiler/serialize.js +119 -0
- package/dist/src/compiler/types.d.ts +83 -0
- package/dist/src/compiler/types.js +9 -0
- package/dist/src/prover/index.d.ts +63 -0
- package/dist/src/prover/index.js +185 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025-2026 Angelo Regalbuto / Regal Health & Retirement LLC
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/NOTICE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
fractal-openshell-bridge
|
|
2
|
+
Copyright 2025-2026 Angelo Regalbuto / Regal Health & Retirement LLC
|
|
3
|
+
|
|
4
|
+
This product is original work that compiles Fractal Code channel sidecars
|
|
5
|
+
(a JSON data format) into OpenShell sandbox policy YAML (a data format),
|
|
6
|
+
and invokes openshell-prover as a subprocess. It contains no source code
|
|
7
|
+
from either Fractal Code or NVIDIA OpenShell. OpenShell is consumed
|
|
8
|
+
strictly as an Apache-2.0 binary via subprocess; Fractal is consumed
|
|
9
|
+
only via its on-disk .channels.json sidecar format.
|
|
10
|
+
|
|
11
|
+
Licensed under the Apache License, Version 2.0.
|
package/README.md
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# fractal-openshell-bridge
|
|
2
|
+
|
|
3
|
+
**Compiles Fractal Code channel sidecars into OpenShell sandbox policy YAML, and wires the OpenShell Z3 prover as a finalize-time gate.**
|
|
4
|
+
|
|
5
|
+
Fractal governs what an agent may *semantically* do (scoped channels, typed intents). OpenShell governs where bytes may *physically* travel (kernel filesystem/network/process containment). This bridge compiles between their domain models so an agent must pass both enforcement gates.
|
|
6
|
+
|
|
7
|
+
> ⚠️ **Alpha. AI-built, not human-reviewed.** This software was written by an AI agent and has NOT been reviewed by a human security engineer. It is an experimental alpha. Do NOT deploy it to protect real secrets or production systems without independent human review. Treat the semantic-gate claims as unverified until a qualified reviewer confirms them. See [SECURITY](#security-posture).
|
|
8
|
+
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
## What it does
|
|
12
|
+
|
|
13
|
+
- **`compile`** — reads a directory of Fractal `.channels.json` sidecars, emits OpenShell `policy.yaml`. A pure, deterministic function: identical input → byte-identical output → identical SHA-256 hash.
|
|
14
|
+
- **`prove`** — invokes `openshell-prover` as a subprocess against a compiled policy + credentials, returns structured findings. Fail-closed if the prover is flagged-on but absent or crashing.
|
|
15
|
+
- **`verify`** — compile + prove in one step. Intended as a finalize-time gate: a pipeline that would leak data through a misconfigured channel is rejected *before* it can execute.
|
|
16
|
+
|
|
17
|
+
## Channel scope (keepers only)
|
|
18
|
+
|
|
19
|
+
The bridge maps only the channels that earn their keep — app-semantic scopes the platform can't enforce natively:
|
|
20
|
+
|
|
21
|
+
| Fractal kind | Maps to |
|
|
22
|
+
|---|---|
|
|
23
|
+
| `file` | `filesystem_policy` (read_write / read_only) |
|
|
24
|
+
| `http` | `network_policies` (host + L7 method rules) |
|
|
25
|
+
| `anthropic` / `openai` / `google-genai` / `cohere` / `mistral` | `network_policies` (provider API host) |
|
|
26
|
+
| `github` | `network_policies` (api.github.com + L7 method/path rules from allowedOperations) |
|
|
27
|
+
|
|
28
|
+
**Deliberately NOT mapped** (documented in emitted YAML comments): `postgres`/`sqlite` (read-only via SQL inspection is unsound — use DB roles), `stripe` (duplicates Stripe's restricted-key model), `aws-s3`/`sqs` (duplicates IAM), `docker`/`kubernetes`/`terraform`/`vault`/`github-actions` (native RBAC), `browser` (overlaps OpenShell network policy), test runners (local execution), and unaudited SaaS channels. See [docs/mapping-reference.md](docs/mapping-reference.md).
|
|
29
|
+
|
|
30
|
+
## Install (from source — not yet on npm)
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
git clone <repo-url>
|
|
34
|
+
cd fractal-openshell-bridge
|
|
35
|
+
npm install
|
|
36
|
+
npm run build
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
# Compile a finalized scaffold's sidecars into OpenShell policy
|
|
43
|
+
fractal-openshell-bridge compile ./my-pipeline/cells -o policy.yaml
|
|
44
|
+
|
|
45
|
+
# Run the prover against the compiled policy
|
|
46
|
+
fractal-openshell-bridge prove --policy policy.yaml --credentials creds.yaml
|
|
47
|
+
|
|
48
|
+
# Compile + prove in one step (finalize-time gate)
|
|
49
|
+
fractal-openshell-bridge verify ./my-pipeline/cells --credentials creds.yaml
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Security posture
|
|
53
|
+
|
|
54
|
+
- **Pure-function compiler.** No temp files, no shared state, no side effects. Parallel invocations cannot cross-contaminate (nothing shared). Deterministic output (sorted keys, selective array sort) → identical input yields identical hash.
|
|
55
|
+
- **Prover gate fail-closed when flagged.** If `--openshell-prover` is set and the binary is absent or crashing, finalization blocks (exit 2). An attacker who deletes the binary or mutates `$PATH` cannot silently disable the gate. No-op only when the flag is entirely absent.
|
|
56
|
+
- **No shell injection surface.** Prover invoked via `spawn` with arg array, `shell: false`. Zero sidecar-derived data in any shell context.
|
|
57
|
+
- **Input hardening.** 1 MiB file-size cap + parse-depth limit before `JSON.parse`. Sidecar directory must never be agent-writable (TOCTOU defense).
|
|
58
|
+
- **Policy file protection.** `policy.yaml` is bind-mounted into the sandbox read-only (kernel-enforced), root-owned `0644`, never in any FileChannel's `allowedPaths`, reinforced by Landlock, with the policy hash sealed into Fractal's Merkle root at finalize (tamper detection).
|
|
59
|
+
- **Zero NVIDIA code.** No OpenShell source bundled or forked. OpenShell consumed as an Apache-2.0 binary via subprocess. No upstream PR required.
|
|
60
|
+
|
|
61
|
+
## What it is NOT
|
|
62
|
+
|
|
63
|
+
- Not a sandbox. It compiles a policy and invokes a prover. OpenShell does the enforcement.
|
|
64
|
+
- Not a substitute for human review. The compiler mapping and prover wiring are AI-authored and unreviewed. The generated `policy.yaml` is plain YAML — read it before applying it.
|
|
65
|
+
- Not a complete channel surface. Only the keeper channels are mapped. The dropped channels are documented, not silently ignored.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
Apache-2.0. See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* fractal-openshell-bridge — CLI.
|
|
4
|
+
*
|
|
5
|
+
* compile <scaffold-dir> [-o policy.yaml] Compile sidecars → OpenShell policy YAML.
|
|
6
|
+
* prove --policy <yaml> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>] [--compact]
|
|
7
|
+
* Run openshell-prover against a compiled policy. Exit 0 pass / 1 fail / 2 input-error.
|
|
8
|
+
* verify <scaffold-dir> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>]
|
|
9
|
+
* compile + prove in one step. Intended as a finalize-time gate.
|
|
10
|
+
*
|
|
11
|
+
* Input hardening (red-team #3): each sidecar file is capped at MAX_SIDECAR_BYTES
|
|
12
|
+
* and rejected if its JSON nesting exceeds MAX_PARSE_DEPTH (JSON-bomb defense).
|
|
13
|
+
*
|
|
14
|
+
* Exit codes: 0 success, 1 prover-fail / blocked, 2 input/usage error.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
package/dist/src/cli.js
ADDED
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
"use strict";
|
|
3
|
+
/**
|
|
4
|
+
* fractal-openshell-bridge — CLI.
|
|
5
|
+
*
|
|
6
|
+
* compile <scaffold-dir> [-o policy.yaml] Compile sidecars → OpenShell policy YAML.
|
|
7
|
+
* prove --policy <yaml> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>] [--compact]
|
|
8
|
+
* Run openshell-prover against a compiled policy. Exit 0 pass / 1 fail / 2 input-error.
|
|
9
|
+
* verify <scaffold-dir> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>]
|
|
10
|
+
* compile + prove in one step. Intended as a finalize-time gate.
|
|
11
|
+
*
|
|
12
|
+
* Input hardening (red-team #3): each sidecar file is capped at MAX_SIDECAR_BYTES
|
|
13
|
+
* and rejected if its JSON nesting exceeds MAX_PARSE_DEPTH (JSON-bomb defense).
|
|
14
|
+
*
|
|
15
|
+
* Exit codes: 0 success, 1 prover-fail / blocked, 2 input/usage error.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
const fs_1 = require("fs");
|
|
19
|
+
const path_1 = require("path");
|
|
20
|
+
const os_1 = require("os");
|
|
21
|
+
const compiler_1 = require("./compiler");
|
|
22
|
+
const prover_1 = require("./prover");
|
|
23
|
+
const MAX_SIDECAR_BYTES = 1_000_000; // 1 MiB
|
|
24
|
+
const MAX_PARSE_DEPTH = 64;
|
|
25
|
+
function usage() {
|
|
26
|
+
process.stderr.write(`fractal-openshell-bridge — compile Fractal sidecars to OpenShell policy + prover gate
|
|
27
|
+
|
|
28
|
+
usage:
|
|
29
|
+
fractal-openshell-bridge compile <scaffold-dir> [-o policy.yaml]
|
|
30
|
+
fractal-openshell-bridge prove --policy <yaml> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>] [--compact]
|
|
31
|
+
fractal-openshell-bridge verify <scaffold-dir> --credentials <yaml> [--registry <dir>] [--accepted-risks <yaml>] [-o policy.yaml]
|
|
32
|
+
|
|
33
|
+
The prover gate is opt-in. Set FRACTAL_OPENSHELL_PROVER=enabled or pass --openshell-prover
|
|
34
|
+
to enable fail-closed behavior in verify (binary-absent blocks rather than no-ops).
|
|
35
|
+
`);
|
|
36
|
+
process.exit(2);
|
|
37
|
+
}
|
|
38
|
+
function die(msg, code = 2) {
|
|
39
|
+
process.stderr.write(`error: ${msg}\n`);
|
|
40
|
+
process.exit(code);
|
|
41
|
+
}
|
|
42
|
+
/** Max nesting depth of a JSON value (JSON-bomb defense). */
|
|
43
|
+
function maxDepth(v, d) {
|
|
44
|
+
if (d > MAX_PARSE_DEPTH)
|
|
45
|
+
return d;
|
|
46
|
+
if (Array.isArray(v)) {
|
|
47
|
+
let m = d;
|
|
48
|
+
for (const x of v)
|
|
49
|
+
m = Math.max(m, maxDepth(x, d + 1));
|
|
50
|
+
return m;
|
|
51
|
+
}
|
|
52
|
+
if (v && typeof v === "object") {
|
|
53
|
+
let m = d;
|
|
54
|
+
for (const x of Object.values(v))
|
|
55
|
+
m = Math.max(m, maxDepth(x, d + 1));
|
|
56
|
+
return m;
|
|
57
|
+
}
|
|
58
|
+
return d;
|
|
59
|
+
}
|
|
60
|
+
/** Read and flatten all *.channels.json sidecars in a directory. */
|
|
61
|
+
function readSidecars(dir) {
|
|
62
|
+
if (!(0, fs_1.existsSync)(dir))
|
|
63
|
+
die(`scaffold directory not found: ${dir}`);
|
|
64
|
+
const entries = (0, fs_1.readdirSync)(dir).filter((f) => f.endsWith(".channels.json"));
|
|
65
|
+
if (entries.length === 0)
|
|
66
|
+
die(`no .channels.json sidecars found in ${dir}`);
|
|
67
|
+
const channels = [];
|
|
68
|
+
for (const f of entries) {
|
|
69
|
+
const path = (0, path_1.join)(dir, f);
|
|
70
|
+
const stat = statSafe(path);
|
|
71
|
+
if (stat.size > MAX_SIDECAR_BYTES) {
|
|
72
|
+
die(`sidecar exceeds ${MAX_SIDECAR_BYTES} byte cap: ${f} (${stat.size} bytes)`);
|
|
73
|
+
}
|
|
74
|
+
const raw = (0, fs_1.readFileSync)(path, "utf8");
|
|
75
|
+
let parsed;
|
|
76
|
+
try {
|
|
77
|
+
parsed = JSON.parse(raw);
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
die(`invalid JSON in ${f}: ${err.message}`);
|
|
81
|
+
}
|
|
82
|
+
if (maxDepth(parsed, 0) > MAX_PARSE_DEPTH) {
|
|
83
|
+
die(`sidecar nesting exceeds depth ${MAX_PARSE_DEPTH}: ${f} (possible JSON bomb)`);
|
|
84
|
+
}
|
|
85
|
+
const sidecar = parsed;
|
|
86
|
+
if (!sidecar || !Array.isArray(sidecar.channels)) {
|
|
87
|
+
die(`${f}: expected { channels: [...] }`);
|
|
88
|
+
}
|
|
89
|
+
for (const c of sidecar.channels) {
|
|
90
|
+
if (c && typeof c === "object" && "name" in c && "kind" in c && "scope" in c) {
|
|
91
|
+
channels.push(c);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return channels;
|
|
96
|
+
}
|
|
97
|
+
function statSafe(path) {
|
|
98
|
+
try {
|
|
99
|
+
return (0, fs_1.statSync)(path);
|
|
100
|
+
}
|
|
101
|
+
catch {
|
|
102
|
+
die(`cannot stat sidecar: ${path}`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
/** Parse -o value / --flag value / --flag=value argv into a map + positionals. */
|
|
106
|
+
function parseArgs(argv) {
|
|
107
|
+
const flags = {};
|
|
108
|
+
const positionals = [];
|
|
109
|
+
for (let i = 0; i < argv.length; i++) {
|
|
110
|
+
const a = argv[i];
|
|
111
|
+
if (a.startsWith("-")) {
|
|
112
|
+
const raw = a.replace(/^-+/, ""); // strip leading dashes (-o and --o both → "o")
|
|
113
|
+
const eq = raw.indexOf("=");
|
|
114
|
+
if (eq >= 0) {
|
|
115
|
+
flags[raw.slice(0, eq)] = raw.slice(eq + 1);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const next = argv[i + 1];
|
|
119
|
+
if (next !== undefined && !next.startsWith("-")) {
|
|
120
|
+
flags[raw] = next;
|
|
121
|
+
i++;
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
flags[raw] = true;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
positionals.push(a);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return { flags, positionals };
|
|
133
|
+
}
|
|
134
|
+
function flagString(v) {
|
|
135
|
+
return typeof v === "string" ? v : undefined;
|
|
136
|
+
}
|
|
137
|
+
// ── compile ──────────────────────────────────────────────────────────
|
|
138
|
+
function cmdCompile(argv) {
|
|
139
|
+
const { flags, positionals } = parseArgs(argv);
|
|
140
|
+
const dir = positionals[0];
|
|
141
|
+
if (!dir)
|
|
142
|
+
usage();
|
|
143
|
+
const out = flagString(flags.o);
|
|
144
|
+
const channels = readSidecars(dir);
|
|
145
|
+
const result = (0, compiler_1.compileSidecars)(channels, Date.now());
|
|
146
|
+
if (!result.success)
|
|
147
|
+
die(`${result.code}: ${result.error}`);
|
|
148
|
+
if (out) {
|
|
149
|
+
const dir2 = (0, path_1.dirname)(out);
|
|
150
|
+
if (!(0, fs_1.existsSync)(dir2))
|
|
151
|
+
(0, fs_1.mkdirSync)(dir2, { recursive: true });
|
|
152
|
+
(0, fs_1.writeFileSync)(out, result.policyYaml, "utf8");
|
|
153
|
+
process.stdout.write(`wrote ${out}\n`);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
process.stdout.write(result.policyYaml);
|
|
157
|
+
}
|
|
158
|
+
process.stderr.write(`policyHash: ${result.policyHash}\nchannels processed: ${result.auditLog.channelsProcessed}, skipped: ${result.auditLog.skippedChannels.length}\n`);
|
|
159
|
+
}
|
|
160
|
+
// ── prove ────────────────────────────────────────────────────────────
|
|
161
|
+
function cmdProve(argv) {
|
|
162
|
+
const { flags } = parseArgs(argv);
|
|
163
|
+
const policy = flagString(flags.policy);
|
|
164
|
+
const credentials = flagString(flags.credentials);
|
|
165
|
+
if (!policy || !credentials)
|
|
166
|
+
usage();
|
|
167
|
+
(0, prover_1.runProver)({
|
|
168
|
+
policyPath: policy,
|
|
169
|
+
credentialsPath: credentials,
|
|
170
|
+
registryPath: flagString(flags.registry),
|
|
171
|
+
acceptedRisksPath: flagString(flags["accepted-risks"]),
|
|
172
|
+
compact: flags.compact === true,
|
|
173
|
+
}, { flagEnabled: true }).then((r) => {
|
|
174
|
+
process.stdout.write(r.stdout);
|
|
175
|
+
process.stderr.write(r.stderr);
|
|
176
|
+
if (r.error)
|
|
177
|
+
process.stderr.write(`${r.error}\n`);
|
|
178
|
+
if (r.outcome === "pass")
|
|
179
|
+
process.exit(0);
|
|
180
|
+
if (r.outcome === "fail")
|
|
181
|
+
process.exit(1);
|
|
182
|
+
process.exit(2); // input-error, binary-absent-fail-closed, crash
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
// ── verify (compile + prove) ─────────────────────────────────────────
|
|
186
|
+
function cmdVerify(argv) {
|
|
187
|
+
const { flags, positionals } = parseArgs(argv);
|
|
188
|
+
const dir = positionals[0];
|
|
189
|
+
const credentials = flagString(flags.credentials);
|
|
190
|
+
if (!dir || !credentials)
|
|
191
|
+
usage();
|
|
192
|
+
const flagEnabled = flags["openshell-prover"] === true ||
|
|
193
|
+
process.env.FRACTAL_OPENSHELL_PROVER === "enabled";
|
|
194
|
+
const channels = readSidecars(dir);
|
|
195
|
+
const compiled = (0, compiler_1.compileSidecars)(channels, Date.now());
|
|
196
|
+
if (!compiled.success)
|
|
197
|
+
die(`${compiled.code}: ${compiled.error}`);
|
|
198
|
+
const keep = flagString(flags.o);
|
|
199
|
+
const tmpPath = keep ?? (0, path_1.join)((0, os_1.tmpdir)(), `fob-policy-${process.pid}-${Date.now()}.yaml`);
|
|
200
|
+
(0, fs_1.writeFileSync)(tmpPath, compiled.policyYaml, "utf8");
|
|
201
|
+
process.stderr.write(`policyHash: ${compiled.policyHash}\n`);
|
|
202
|
+
(0, prover_1.runProver)({
|
|
203
|
+
policyPath: tmpPath,
|
|
204
|
+
credentialsPath: credentials,
|
|
205
|
+
registryPath: flagString(flags.registry),
|
|
206
|
+
acceptedRisksPath: flagString(flags["accepted-risks"]),
|
|
207
|
+
compact: true,
|
|
208
|
+
}, { flagEnabled }).then((r) => {
|
|
209
|
+
try {
|
|
210
|
+
if (!keep)
|
|
211
|
+
(0, fs_1.rmSync)(tmpPath, { force: true });
|
|
212
|
+
}
|
|
213
|
+
catch {
|
|
214
|
+
/* best-effort cleanup */
|
|
215
|
+
}
|
|
216
|
+
process.stdout.write(r.stdout);
|
|
217
|
+
process.stderr.write(r.stderr);
|
|
218
|
+
if (!flagEnabled) {
|
|
219
|
+
process.stderr.write(`note: prover gate not enabled (set --openshell-prover or FRACTAL_OPENSHELL_PROVER=enabled to fail-closed). policy written to ${tmpPath}\n`);
|
|
220
|
+
}
|
|
221
|
+
if (r.error)
|
|
222
|
+
process.stderr.write(`${r.error}\n`);
|
|
223
|
+
if (r.outcome === "pass" || r.outcome === "not-enabled")
|
|
224
|
+
process.exit(0);
|
|
225
|
+
if (r.outcome === "fail")
|
|
226
|
+
process.exit(1);
|
|
227
|
+
process.exit(2);
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
// ── dispatch ─────────────────────────────────────────────────────────
|
|
231
|
+
const argv = process.argv.slice(2);
|
|
232
|
+
const cmd = argv[0];
|
|
233
|
+
const rest = argv.slice(1);
|
|
234
|
+
if (cmd === "compile")
|
|
235
|
+
cmdCompile(rest);
|
|
236
|
+
else if (cmd === "prove")
|
|
237
|
+
cmdProve(rest);
|
|
238
|
+
else if (cmd === "verify")
|
|
239
|
+
cmdVerify(rest);
|
|
240
|
+
else
|
|
241
|
+
usage();
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fractal-openshell-bridge — the pure compiler function.
|
|
3
|
+
*
|
|
4
|
+
* `compileSidecars(channels, timestamp)` is a pure function:
|
|
5
|
+
* - No filesystem, no network, no env, no clock reads (timestamp is a param).
|
|
6
|
+
* - Input is deep-frozen on entry (downstream mappers cannot mutate it).
|
|
7
|
+
* - Output is deterministic: identical channels → byte-identical policyYaml
|
|
8
|
+
* → identical policyHash. The timestamp is NOT an input to the hash.
|
|
9
|
+
* - Errors are returned as { success: false, code, error }, never thrown.
|
|
10
|
+
*
|
|
11
|
+
* Side effects (logging, persistence) are the caller's responsibility — the
|
|
12
|
+
* caller receives the auditLog in the result and persists it however it likes.
|
|
13
|
+
*/
|
|
14
|
+
import type { TypedChannelConfig, CompilationResult } from "./types";
|
|
15
|
+
/**
|
|
16
|
+
* Compile an array of typed channel declarations into OpenShell policy YAML.
|
|
17
|
+
*
|
|
18
|
+
* @param channels Flattened channel declarations from `.channels.json` sidecars.
|
|
19
|
+
* @param timestamp Epoch milliseconds for the audit log (caller-supplied; NOT hashed).
|
|
20
|
+
* @returns CompilationResult — { success, policyYaml, policyHash, auditLog }
|
|
21
|
+
* on success, or { success: false, code, error } on failure.
|
|
22
|
+
*/
|
|
23
|
+
export declare function compileSidecars(channels: TypedChannelConfig[], timestamp: number): CompilationResult;
|
|
24
|
+
export { serializePolicy } from "./serialize";
|
|
25
|
+
export { mapChannel, buildFilesystem } from "./mappings";
|
|
26
|
+
export type { TypedChannelConfig, PolicyFile, CompilationResult, AuditLog, FilesystemDef, NetworkPolicyRuleDef, NetworkEndpointDef, } from "./types";
|