@orygn/opa-mcp 0.4.0 → 0.6.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/CHANGELOG.md +583 -4
- package/README.md +144 -98
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +9 -3
- package/dist/cli.js.map +1 -1
- package/dist/config.d.ts +14 -4
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +91 -19
- package/dist/config.js.map +1 -1
- package/dist/constants.d.ts +1 -6
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +17 -3
- package/dist/constants.js.map +1 -1
- package/dist/lib/bundle-signatures.d.ts +23 -0
- package/dist/lib/bundle-signatures.d.ts.map +1 -0
- package/dist/lib/bundle-signatures.js +152 -0
- package/dist/lib/bundle-signatures.js.map +1 -0
- package/dist/lib/child-env.d.ts +9 -2
- package/dist/lib/child-env.d.ts.map +1 -1
- package/dist/lib/child-env.js +38 -6
- package/dist/lib/child-env.js.map +1 -1
- package/dist/lib/conftest-cli.d.ts +25 -10
- package/dist/lib/conftest-cli.d.ts.map +1 -1
- package/dist/lib/conftest-cli.js +233 -50
- package/dist/lib/conftest-cli.js.map +1 -1
- package/dist/lib/errors.d.ts +4 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +15 -3
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/inline-paths.d.ts +37 -0
- package/dist/lib/inline-paths.d.ts.map +1 -0
- package/dist/lib/inline-paths.js +162 -0
- package/dist/lib/inline-paths.js.map +1 -0
- package/dist/lib/install-id.d.ts.map +1 -1
- package/dist/lib/install-id.js +18 -3
- package/dist/lib/install-id.js.map +1 -1
- package/dist/lib/json-stream.d.ts +26 -0
- package/dist/lib/json-stream.d.ts.map +1 -0
- package/dist/lib/json-stream.js +69 -0
- package/dist/lib/json-stream.js.map +1 -0
- package/dist/lib/opa-cli.d.ts +74 -16
- package/dist/lib/opa-cli.d.ts.map +1 -1
- package/dist/lib/opa-cli.js +107 -30
- package/dist/lib/opa-cli.js.map +1 -1
- package/dist/lib/opa-client.d.ts +27 -1
- package/dist/lib/opa-client.d.ts.map +1 -1
- package/dist/lib/opa-client.js +98 -14
- package/dist/lib/opa-client.js.map +1 -1
- package/dist/lib/opa-paths.d.ts +34 -0
- package/dist/lib/opa-paths.d.ts.map +1 -0
- package/dist/lib/opa-paths.js +101 -0
- package/dist/lib/opa-paths.js.map +1 -0
- package/dist/lib/output.d.ts.map +1 -1
- package/dist/lib/output.js +83 -10
- package/dist/lib/output.js.map +1 -1
- package/dist/lib/regal-cli.d.ts +16 -1
- package/dist/lib/regal-cli.d.ts.map +1 -1
- package/dist/lib/regal-cli.js +40 -6
- package/dist/lib/regal-cli.js.map +1 -1
- package/dist/lib/rego-ast-walker.d.ts +0 -6
- package/dist/lib/rego-ast-walker.d.ts.map +1 -1
- package/dist/lib/rego-ast-walker.js +181 -55
- package/dist/lib/rego-ast-walker.js.map +1 -1
- package/dist/lib/rego-counterexample.d.ts +15 -2
- package/dist/lib/rego-counterexample.d.ts.map +1 -1
- package/dist/lib/rego-counterexample.js +63 -15
- package/dist/lib/rego-counterexample.js.map +1 -1
- package/dist/lib/rego-input-path.d.ts +20 -0
- package/dist/lib/rego-input-path.d.ts.map +1 -0
- package/dist/lib/rego-input-path.js +70 -0
- package/dist/lib/rego-input-path.js.map +1 -0
- package/dist/lib/rego-ir.d.ts +34 -3
- package/dist/lib/rego-ir.d.ts.map +1 -1
- package/dist/lib/rego-smt-encoder.d.ts +88 -5
- package/dist/lib/rego-smt-encoder.d.ts.map +1 -1
- package/dist/lib/rego-smt-encoder.js +270 -31
- package/dist/lib/rego-smt-encoder.js.map +1 -1
- package/dist/lib/rego-type-inferencer.d.ts +27 -2
- package/dist/lib/rego-type-inferencer.d.ts.map +1 -1
- package/dist/lib/rego-type-inferencer.js +71 -3
- package/dist/lib/rego-type-inferencer.js.map +1 -1
- package/dist/lib/rego-verify-engine.d.ts.map +1 -1
- package/dist/lib/rego-verify-engine.js +203 -90
- package/dist/lib/rego-verify-engine.js.map +1 -1
- package/dist/lib/rego-z3.d.ts +66 -0
- package/dist/lib/rego-z3.d.ts.map +1 -1
- package/dist/lib/rego-z3.js +312 -5
- package/dist/lib/rego-z3.js.map +1 -1
- package/dist/lib/security.d.ts +8 -0
- package/dist/lib/security.d.ts.map +1 -1
- package/dist/lib/security.js +130 -54
- package/dist/lib/security.js.map +1 -1
- package/dist/lib/subprocess.d.ts +13 -0
- package/dist/lib/subprocess.d.ts.map +1 -1
- package/dist/lib/subprocess.js +153 -18
- package/dist/lib/subprocess.js.map +1 -1
- package/dist/lib/tool-helpers.d.ts +12 -25
- package/dist/lib/tool-helpers.d.ts.map +1 -1
- package/dist/lib/tool-helpers.js +66 -40
- package/dist/lib/tool-helpers.js.map +1 -1
- package/dist/prompts/index.js +2 -2
- package/dist/resources/index.js +1 -1
- package/dist/resources/index.js.map +1 -1
- package/dist/resources/patterns.d.ts +1 -1
- package/dist/resources/patterns.d.ts.map +1 -1
- package/dist/resources/patterns.js +42 -15
- package/dist/resources/patterns.js.map +1 -1
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +50 -7
- package/dist/server.js.map +1 -1
- package/dist/tools/authoring/capabilities.d.ts +4 -0
- package/dist/tools/authoring/capabilities.d.ts.map +1 -1
- package/dist/tools/authoring/capabilities.js +41 -4
- package/dist/tools/authoring/capabilities.js.map +1 -1
- package/dist/tools/authoring/check-schema.d.ts +6 -0
- package/dist/tools/authoring/check-schema.d.ts.map +1 -1
- package/dist/tools/authoring/check-schema.js +56 -3
- package/dist/tools/authoring/check-schema.js.map +1 -1
- package/dist/tools/authoring/format.d.ts.map +1 -1
- package/dist/tools/authoring/format.js +2 -2
- package/dist/tools/authoring/format.js.map +1 -1
- package/dist/tools/authoring/lint.d.ts.map +1 -1
- package/dist/tools/authoring/lint.js +8 -6
- package/dist/tools/authoring/lint.js.map +1 -1
- package/dist/tools/authoring/migrate-v1.d.ts.map +1 -1
- package/dist/tools/authoring/migrate-v1.js +20 -4
- package/dist/tools/authoring/migrate-v1.js.map +1 -1
- package/dist/tools/authoring/parse.d.ts.map +1 -1
- package/dist/tools/authoring/parse.js +3 -3
- package/dist/tools/authoring/parse.js.map +1 -1
- package/dist/tools/bundles/build.d.ts.map +1 -1
- package/dist/tools/bundles/build.js +12 -4
- package/dist/tools/bundles/build.js.map +1 -1
- package/dist/tools/bundles/sign.d.ts +9 -2
- package/dist/tools/bundles/sign.d.ts.map +1 -1
- package/dist/tools/bundles/sign.js +125 -19
- package/dist/tools/bundles/sign.js.map +1 -1
- package/dist/tools/bundles/verify.d.ts +1 -1
- package/dist/tools/bundles/verify.d.ts.map +1 -1
- package/dist/tools/bundles/verify.js +58 -19
- package/dist/tools/bundles/verify.js.map +1 -1
- package/dist/tools/conftest/index.d.ts +5 -0
- package/dist/tools/conftest/index.d.ts.map +1 -1
- package/dist/tools/conftest/index.js.map +1 -1
- package/dist/tools/conftest/pull.d.ts.map +1 -1
- package/dist/tools/conftest/pull.js +24 -10
- package/dist/tools/conftest/pull.js.map +1 -1
- package/dist/tools/conftest/push.d.ts.map +1 -1
- package/dist/tools/conftest/push.js +17 -7
- package/dist/tools/conftest/push.js.map +1 -1
- package/dist/tools/conftest/test.d.ts +10 -6
- package/dist/tools/conftest/test.d.ts.map +1 -1
- package/dist/tools/conftest/test.js +61 -39
- package/dist/tools/conftest/test.js.map +1 -1
- package/dist/tools/conftest/verify.d.ts +10 -6
- package/dist/tools/conftest/verify.d.ts.map +1 -1
- package/dist/tools/conftest/verify.js +40 -32
- package/dist/tools/conftest/verify.js.map +1 -1
- package/dist/tools/evaluation/_shared.js +9 -12
- package/dist/tools/evaluation/_shared.js.map +1 -1
- package/dist/tools/evaluation/bench.d.ts +29 -2
- package/dist/tools/evaluation/bench.d.ts.map +1 -1
- package/dist/tools/evaluation/bench.js +53 -9
- package/dist/tools/evaluation/bench.js.map +1 -1
- package/dist/tools/evaluation/compile.js +4 -4
- package/dist/tools/evaluation/compile.js.map +1 -1
- package/dist/tools/evaluation/eval.d.ts.map +1 -1
- package/dist/tools/evaluation/eval.js +12 -16
- package/dist/tools/evaluation/eval.js.map +1 -1
- package/dist/tools/evaluation/exec.d.ts +16 -0
- package/dist/tools/evaluation/exec.d.ts.map +1 -1
- package/dist/tools/evaluation/exec.js +38 -6
- package/dist/tools/evaluation/exec.js.map +1 -1
- package/dist/tools/evaluation/test-multiroot.d.ts +6 -0
- package/dist/tools/evaluation/test-multiroot.d.ts.map +1 -1
- package/dist/tools/evaluation/test-multiroot.js +35 -8
- package/dist/tools/evaluation/test-multiroot.js.map +1 -1
- package/dist/tools/evaluation/test.d.ts +45 -0
- package/dist/tools/evaluation/test.d.ts.map +1 -1
- package/dist/tools/evaluation/test.js +153 -32
- package/dist/tools/evaluation/test.js.map +1 -1
- package/dist/tools/helpers/coverage-gaps.d.ts +11 -3
- package/dist/tools/helpers/coverage-gaps.d.ts.map +1 -1
- package/dist/tools/helpers/coverage-gaps.js +7 -7
- package/dist/tools/helpers/coverage-gaps.js.map +1 -1
- package/dist/tools/helpers/describe-policy.d.ts.map +1 -1
- package/dist/tools/helpers/describe-policy.js +2 -2
- package/dist/tools/helpers/describe-policy.js.map +1 -1
- package/dist/tools/helpers/explain-decision.d.ts.map +1 -1
- package/dist/tools/helpers/explain-decision.js +3 -4
- package/dist/tools/helpers/explain-decision.js.map +1 -1
- package/dist/tools/helpers/explain-undefined.d.ts +9 -3
- package/dist/tools/helpers/explain-undefined.d.ts.map +1 -1
- package/dist/tools/helpers/explain-undefined.js +214 -73
- package/dist/tools/helpers/explain-undefined.js.map +1 -1
- package/dist/tools/helpers/fix.d.ts +11 -5
- package/dist/tools/helpers/fix.d.ts.map +1 -1
- package/dist/tools/helpers/fix.js +88 -45
- package/dist/tools/helpers/fix.js.map +1 -1
- package/dist/tools/helpers/generate-test-skeleton.d.ts.map +1 -1
- package/dist/tools/helpers/generate-test-skeleton.js +105 -21
- package/dist/tools/helpers/generate-test-skeleton.js.map +1 -1
- package/dist/tools/helpers/playground-share.d.ts +4 -2
- package/dist/tools/helpers/playground-share.d.ts.map +1 -1
- package/dist/tools/helpers/playground-share.js +13 -3
- package/dist/tools/helpers/playground-share.js.map +1 -1
- package/dist/tools/helpers/policy-diff.d.ts.map +1 -1
- package/dist/tools/helpers/policy-diff.js +3 -4
- package/dist/tools/helpers/policy-diff.js.map +1 -1
- package/dist/tools/helpers/security-audit.d.ts.map +1 -1
- package/dist/tools/helpers/security-audit.js +19 -19
- package/dist/tools/helpers/security-audit.js.map +1 -1
- package/dist/tools/helpers/verify.d.ts.map +1 -1
- package/dist/tools/helpers/verify.js +5 -1
- package/dist/tools/helpers/verify.js.map +1 -1
- package/dist/tools/meta/index.d.ts +1 -1
- package/dist/tools/server-management/_shared.d.ts +15 -4
- package/dist/tools/server-management/_shared.d.ts.map +1 -1
- package/dist/tools/server-management/_shared.js +86 -13
- package/dist/tools/server-management/_shared.js.map +1 -1
- package/dist/tools/server-management/data.d.ts.map +1 -1
- package/dist/tools/server-management/data.js +88 -23
- package/dist/tools/server-management/data.js.map +1 -1
- package/dist/tools/server-management/decisions.d.ts.map +1 -1
- package/dist/tools/server-management/decisions.js +16 -3
- package/dist/tools/server-management/decisions.js.map +1 -1
- package/dist/tools/server-management/policies.d.ts.map +1 -1
- package/dist/tools/server-management/policies.js +44 -7
- package/dist/tools/server-management/policies.js.map +1 -1
- package/dist/tools/server-management/status.d.ts.map +1 -1
- package/dist/tools/server-management/status.js +80 -13
- package/dist/tools/server-management/status.js.map +1 -1
- package/dist/types.d.ts +10 -1
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-input-path.d.ts","sourceRoot":"","sources":["../../src/lib/rego-input-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,uDAAuD;AACvD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,SAAS,MAAM,EAAE,GAAG,MAAM,CAMnE;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAuCrD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rendering of an `input` path that is injective over its segments.
|
|
3
|
+
*
|
|
4
|
+
* Joining segments with dots made `input["a.b"]` and `input.a.b` the same
|
|
5
|
+
* string, so the two fields shared one Z3 constant and the witness for one
|
|
6
|
+
* was rebuilt as the other. A segment that is a plain identifier is written
|
|
7
|
+
* `.seg`; any other is written `["..."]` with JSON quoting, which is how Rego
|
|
8
|
+
* itself spells it, and the two forms cannot collide.
|
|
9
|
+
*/
|
|
10
|
+
const IDENT = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
11
|
+
/** Render `["user", "a.b"]` as `input.user["a.b"]`. */
|
|
12
|
+
export function renderInputPath(segments) {
|
|
13
|
+
let out = 'input';
|
|
14
|
+
for (const seg of segments) {
|
|
15
|
+
out += IDENT.test(seg) ? `.${seg}` : `[${JSON.stringify(seg)}]`;
|
|
16
|
+
}
|
|
17
|
+
return out;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Parse a rendered path back into its segments. The inverse of
|
|
21
|
+
* renderInputPath; anything it did not produce is read as best it can, one
|
|
22
|
+
* dot-separated segment at a time, so a plain `input.a.b` still works, and a
|
|
23
|
+
* bracket without a well-formed string inside is taken as literal text
|
|
24
|
+
* rather than thrown on.
|
|
25
|
+
*/
|
|
26
|
+
export function parseInputPath(path) {
|
|
27
|
+
let rest = /^input(?=[.[]|$)/.test(path) ? path.slice('input'.length) : path;
|
|
28
|
+
const segments = [];
|
|
29
|
+
while (rest.length > 0) {
|
|
30
|
+
if (rest.startsWith('.')) {
|
|
31
|
+
const m = /^\.([^.[]+)/.exec(rest);
|
|
32
|
+
if (!m) {
|
|
33
|
+
// A dot with no name after it is not a rendering of ours either.
|
|
34
|
+
segments.push(rest);
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
segments.push(m[1]);
|
|
38
|
+
rest = rest.slice(m[0].length);
|
|
39
|
+
}
|
|
40
|
+
else if (rest.startsWith('["')) {
|
|
41
|
+
// A JSON string literal: find its closing quote, honouring escapes.
|
|
42
|
+
let i = 2;
|
|
43
|
+
while (i < rest.length && rest[i] !== '"')
|
|
44
|
+
i += rest[i] === '\\' ? 2 : 1;
|
|
45
|
+
const closed = i < rest.length && rest[i + 1] === ']';
|
|
46
|
+
let literal;
|
|
47
|
+
if (closed) {
|
|
48
|
+
try {
|
|
49
|
+
literal = JSON.parse(rest.slice(1, i + 1));
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
literal = undefined;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if (typeof literal !== 'string') {
|
|
56
|
+
segments.push(rest);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
segments.push(literal);
|
|
60
|
+
rest = rest.slice(i + 2);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
// Not a rendering of ours; take the remainder as one segment.
|
|
64
|
+
segments.push(rest);
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return segments;
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=rego-input-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rego-input-path.js","sourceRoot":"","sources":["../../src/lib/rego-input-path.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,MAAM,KAAK,GAAG,0BAA0B,CAAC;AAEzC,uDAAuD;AACvD,MAAM,UAAU,eAAe,CAAC,QAA2B;IACzD,IAAI,GAAG,GAAG,OAAO,CAAC;IAClB,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;QAC3B,GAAG,IAAI,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,C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C,KAAK,GAAG,CAAC;YACtD,IAAI,OAAgB,CAAC;YACrB,IAAI,MAAM,EAAE,CAAC;gBACX,IAAI,CAAC;oBACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;gBAC7C,CAAC;gBAAC,MAAM,CAAC;oBACP,OAAO,GAAG,SAAS,CAAC;gBACtB,CAAC;YACH,CAAC;YACD,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;gBAChC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBACpB,MAAM;YACR,CAAC;YACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACvB,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,8DAA8D;YAC9D,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACpB,MAAM;QACR,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
package/dist/lib/rego-ir.d.ts
CHANGED
|
@@ -7,7 +7,8 @@
|
|
|
7
7
|
* A value that appears as an operand in a VerifyExpr.
|
|
8
8
|
*
|
|
9
9
|
* input_ref - a path like input.user.role (path = "input.user.role",
|
|
10
|
-
* segments = ["user","role"])
|
|
10
|
+
* segments = ["user","role"]); a segment that is not a plain
|
|
11
|
+
* identifier is rendered `["..."]`, so paths never collide
|
|
11
12
|
* local_var - a local variable bound by :=/= in the same clause
|
|
12
13
|
* literal_* - a constant from the policy source
|
|
13
14
|
*/
|
|
@@ -36,6 +37,11 @@ export type VerifyValue = {
|
|
|
36
37
|
* All supported operator semantics map cleanly to Z3. The 'unsupported'
|
|
37
38
|
* variant is included so the walker can pass through the reason; the
|
|
38
39
|
* engine treats any clause containing it as inconclusive.
|
|
40
|
+
*
|
|
41
|
+
* 'contradiction' is the encodable counterpart: a body term that makes the
|
|
42
|
+
* clause unsatisfiable no matter the input, such as a literal `false`. It is
|
|
43
|
+
* distinct from 'unsupported' because the engine CAN reason about it, and
|
|
44
|
+
* dropping it instead would make the clause look satisfiable when it is not.
|
|
39
45
|
*/
|
|
40
46
|
export type VerifyExpr = {
|
|
41
47
|
kind: 'eq';
|
|
@@ -84,15 +90,38 @@ export type VerifyExpr = {
|
|
|
84
90
|
kind: 'assign';
|
|
85
91
|
local: string;
|
|
86
92
|
value: VerifyValue;
|
|
93
|
+
} | {
|
|
94
|
+
kind: 'contradiction';
|
|
95
|
+
reason: string;
|
|
96
|
+
} | {
|
|
97
|
+
kind: 'negation';
|
|
98
|
+
inner: VerifyExpr[];
|
|
87
99
|
} | {
|
|
88
100
|
kind: 'unsupported';
|
|
89
101
|
constructType: string;
|
|
90
102
|
reason: string;
|
|
91
103
|
};
|
|
104
|
+
/**
|
|
105
|
+
* The shape of a rule head, which decides whether "is this rule true" is even
|
|
106
|
+
* a meaningful question.
|
|
107
|
+
*
|
|
108
|
+
* complete - `allow if { ... }` or `allow := <value> if { ... }`. Its
|
|
109
|
+
* value is a single term, so it can be compared to `true`.
|
|
110
|
+
* partial_set - `deny contains msg if { ... }`. Its value is a SET, so it
|
|
111
|
+
* is never equal to `true` and asking always_true/never_true
|
|
112
|
+
* about it answers a question the caller did not intend.
|
|
113
|
+
* partial_object - `perms[k] := v if { ... }`. Value is an object, same problem.
|
|
114
|
+
* function - `f(x) if { ... }`. Needs arguments the caller never supplies.
|
|
115
|
+
* else_chain - `... else := ...`. Ordered fallthrough the encoder does not model.
|
|
116
|
+
*/
|
|
117
|
+
export type RuleShape = 'complete' | 'partial_set' | 'partial_object' | 'function' | 'else_chain';
|
|
92
118
|
/**
|
|
93
119
|
* One clause of a rule -- corresponds to one `rule { body... }` block.
|
|
94
|
-
*
|
|
95
|
-
*
|
|
120
|
+
*
|
|
121
|
+
* A clause contributes to "the rule is true" only when its head value is
|
|
122
|
+
* literally `true`. It contributes to "the rule is defined" whenever its body
|
|
123
|
+
* is satisfied, whatever the head value is. Keeping those separate is what
|
|
124
|
+
* makes `default` and non-boolean heads encodable rather than silently wrong.
|
|
96
125
|
*/
|
|
97
126
|
export interface VerifyRuleClause {
|
|
98
127
|
clauseIndex: number;
|
|
@@ -111,6 +140,8 @@ export interface UnsupportedConstruct {
|
|
|
111
140
|
export interface VerifyWalkResult {
|
|
112
141
|
rules: Map<string, VerifyRuleClause[]>;
|
|
113
142
|
defaults: Map<string, boolean | number | string | null>;
|
|
143
|
+
/** Head shape per rule name. Absent means no clause was ever walked for it. */
|
|
144
|
+
shapes: Map<string, RuleShape>;
|
|
114
145
|
inputPaths: Map<string, string[]>;
|
|
115
146
|
unsupported: UnsupportedConstruct[];
|
|
116
147
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rego-ir.d.ts","sourceRoot":"","sources":["../../src/lib/rego-ir.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"rego-ir.d.ts","sourceRoot":"","sources":["../../src/lib/rego-ir.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,WAAW,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACzC;IAAE,IAAI,EAAE,cAAc,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GACxC;IAAE,IAAI,EAAE,cAAc,CAAA;CAAE,CAAC;AAE7B;;;;;;;;;;;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3 constant per input path, typed by the type inferencer.
|
|
9
9
|
* - One Z3 constant per local variable, scoped per clause.
|
|
10
|
-
* - Each clause body becomes an AND of its expression formulas
|
|
11
|
-
*
|
|
10
|
+
* - Each clause body becomes an AND of its expression formulas, plus a
|
|
11
|
+
* presence guard for every input path the clause reads.
|
|
12
|
+
* - "the rule is TRUE" is the OR of the bodies of clauses whose head value is
|
|
13
|
+
* literally true, OR'd with the default when no clause body holds. Encoding
|
|
14
|
+
* the OR of all clause bodies instead conflated "the rule is defined" with
|
|
15
|
+
* "the rule is true", which made `default allow := true` and non-boolean
|
|
16
|
+
* heads silently wrong.
|
|
12
17
|
* - Uninterpreted sorts get a dedicated Z3 uninterpreted sort and
|
|
13
18
|
* can only participate in equality/inequality constraints.
|
|
14
19
|
*/
|
|
15
20
|
import type { init as Z3Init } from 'z3-solver';
|
|
16
21
|
import type { Z3Sort } from './rego-type-inferencer.js';
|
|
17
22
|
import type { VerifyRuleClause } from './rego-ir.js';
|
|
23
|
+
/**
|
|
24
|
+
* A string literal for Z3. Its parser reads `\u{HH}` inside a literal as an
|
|
25
|
+
* escape, so a policy literal that happens to spell one, or that holds any
|
|
26
|
+
* backslash, would be stored as something else. Every backslash is written
|
|
27
|
+
* as `\u{5c}`, which Z3 stores as the character and renders back as an
|
|
28
|
+
* escape the counterexample decoder undoes.
|
|
29
|
+
*/
|
|
30
|
+
export declare function z3String(Z3: Z3Context, value: string): ReturnType<Z3Context['String']['val']>;
|
|
18
31
|
type Z3Context = ReturnType<Awaited<ReturnType<typeof Z3Init>>['Context']>;
|
|
19
32
|
type Z3Bool = ReturnType<Z3Context['Bool']['const']>;
|
|
20
33
|
type Z3AnyExpr = Z3Bool | ReturnType<Z3Context['Int']['const']> | ReturnType<Z3Context['String']['const']>;
|
|
21
34
|
export interface EncoderContext {
|
|
22
35
|
Z3: Z3Context;
|
|
23
36
|
inputVars: Map<string, Z3AnyExpr>;
|
|
37
|
+
/**
|
|
38
|
+
* One Bool per input path, true when that field is present in the input.
|
|
39
|
+
*
|
|
40
|
+
* Rego evaluates a body to undefined when it reads a missing field, and an
|
|
41
|
+
* undefined body does not make the rule true. Modelling every path as a
|
|
42
|
+
* total, always-present constant made vacuous predicates look like
|
|
43
|
+
* tautologies, so always_true could be PROVEN for a rule that is merely
|
|
44
|
+
* undefined when a field is absent.
|
|
45
|
+
*/
|
|
46
|
+
presenceVars: Map<string, Z3Bool>;
|
|
24
47
|
sorts: Map<string, Z3Sort>;
|
|
25
48
|
/** Per-call unique prefix for all Z3 constant names. Prevents sort conflicts
|
|
26
49
|
* when the same input path is inferred as different sorts across calls in the
|
|
@@ -31,19 +54,79 @@ export interface EncoderContext {
|
|
|
31
54
|
export interface EncodedRule {
|
|
32
55
|
formula: Z3Bool;
|
|
33
56
|
warnings: string[];
|
|
57
|
+
/**
|
|
58
|
+
* True when at least one clause could not be encoded.
|
|
59
|
+
*
|
|
60
|
+
* The caller MUST treat the formula as meaningless in that case. Skipping the
|
|
61
|
+
* clause and solving the rest is what turned an unencodable operand into a
|
|
62
|
+
* confident PROVEN: dropping a clause makes the rule strictly easier to
|
|
63
|
+
* satisfy in one direction and strictly harder in the other, and both
|
|
64
|
+
* directions produce a wrong verdict.
|
|
65
|
+
*/
|
|
66
|
+
unencodable: boolean;
|
|
34
67
|
}
|
|
35
68
|
/**
|
|
36
69
|
* Create Z3 constants for all input paths based on inferred sorts.
|
|
37
70
|
* Each constant name is prefixed with callId to ensure uniqueness across
|
|
38
71
|
* verification calls in the same Z3 singleton context.
|
|
39
72
|
*/
|
|
40
|
-
export declare function createInputVars(Z3: Z3Context, inputPaths: Map<string, string[]>, sorts: Map<string, Z3Sort>, callId: string):
|
|
73
|
+
export declare function createInputVars(Z3: Z3Context, inputPaths: Map<string, string[]>, sorts: Map<string, Z3Sort>, callId: string): {
|
|
74
|
+
vars: Map<string, Z3AnyExpr>;
|
|
75
|
+
presence: Map<string, Z3Bool>;
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* Facts about the shape of any input, added to the solver alongside the
|
|
79
|
+
* property. A path the rule compared equal to a scalar literal, or fed to a
|
|
80
|
+
* string built-in, is present only as a scalar wherever that read holds, so
|
|
81
|
+
* it cannot also be the object holding a path beneath it: the two are never
|
|
82
|
+
* present together. Without this, `input.a == "x"` and `input.a.b == "y"`
|
|
83
|
+
* got two independent constants and a rule no input can satisfy was proved
|
|
84
|
+
* satisfiable, with a witness OPA rejects.
|
|
85
|
+
*
|
|
86
|
+
* Only those reads qualify. `input.a != "x"`, `input.a > 1` and a bare
|
|
87
|
+
* `input.a` all hold for an object, and a path with no evidence at all is
|
|
88
|
+
* given the string sort by default; treating any of them as scalar proved
|
|
89
|
+
* satisfiable rules never true.
|
|
90
|
+
*/
|
|
91
|
+
export declare function structuralAxioms(Z3: Z3Context, inputPaths: Map<string, string[]>, scalarPaths: ReadonlySet<string>, presence: Map<string, Z3Bool>): Z3Bool[];
|
|
92
|
+
/**
|
|
93
|
+
* Every input path `clauses` reference, a negated body included.
|
|
94
|
+
*
|
|
95
|
+
* The presence guard below deliberately skips a negated body, since a
|
|
96
|
+
* missing field satisfies it; a witness must still be able to name that
|
|
97
|
+
* field. It must also never name a field the rule does not read: variables
|
|
98
|
+
* are created for every path in the module, so a path belonging to another
|
|
99
|
+
* rule is unconstrained here, and model completion would hand it an
|
|
100
|
+
* arbitrary value. Where that path is the parent of one this rule reads,
|
|
101
|
+
* the two collide and the witness stops satisfying the rule.
|
|
102
|
+
*/
|
|
103
|
+
export declare function clauseInputPaths(clauses: VerifyRuleClause[]): Set<string>;
|
|
41
104
|
/**
|
|
42
105
|
* Encode a complete rule as a Z3 Bool formula.
|
|
43
106
|
* rule_formula = clause_0 OR clause_1 OR ... OR clause_n
|
|
44
107
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
108
|
+
/**
|
|
109
|
+
* Encode "the rule evaluates to true".
|
|
110
|
+
*
|
|
111
|
+
* Rego semantics, and why the previous OR-of-all-clauses was wrong:
|
|
112
|
+
* - a clause whose body holds gives the rule that clause's HEAD value
|
|
113
|
+
* - the rule is DEFINED when any clause body holds
|
|
114
|
+
* - when no body holds the rule takes its `default`, or stays undefined
|
|
115
|
+
*
|
|
116
|
+
* So `rule == true` is the OR of the bodies of clauses whose head is literally
|
|
117
|
+
* true, plus the default case when nothing else fired. Treating every satisfied
|
|
118
|
+
* body as "true" made `allow := false if {...}` prove always-true, and ignoring
|
|
119
|
+
* the default made `default allow := true` prove never-true.
|
|
120
|
+
*/
|
|
121
|
+
export declare function encodeRule(clauses: VerifyRuleClause[], ctx: EncoderContext, defaultValue?: boolean | number | string | null): EncodedRule;
|
|
122
|
+
/**
|
|
123
|
+
* Convert an input path like "input.user.role" to a valid Z3 constant name.
|
|
124
|
+
*
|
|
125
|
+
* Must be INJECTIVE. Replacing "." with "__" was not: a quoted key holding a
|
|
126
|
+
* dot or an underscore pair, ordinary in Kubernetes and cloud policies such as
|
|
127
|
+
* `input.labels["app.kubernetes.io/name"]`, collided with a different path and
|
|
128
|
+
* two distinct fields became a single SMT variable.
|
|
129
|
+
*/
|
|
47
130
|
export declare function pathToVarName(path: string): string;
|
|
48
131
|
/** Reconstruct a nested JSON object from flat Z3 var name → value pairs. */
|
|
49
132
|
export declare function varNameToPath(varName: string): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rego-smt-encoder.d.ts","sourceRoot":"","sources":["../../src/lib/rego-smt-encoder.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"rego-smt-encoder.d.ts","sourceRoot":"","sources":["../../src/lib/rego-smt-encoder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,IAAI,IAAI,MAAM,EAAE,MAAM,WAAW,CAAC;AAEhD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,KAAK,EAAc,gBAAgB,EAAe,MAAM,cAAc,CAAC;AAE9E;;;;;;GAMG;AAC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