@orygn/opa-mcp 0.2.0 → 0.3.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 +73 -0
- package/README.md +12 -5
- package/dist/constants.d.ts +1 -1
- package/dist/constants.js +1 -1
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/errors.js +3 -1
- package/dist/lib/errors.js.map +1 -1
- package/dist/lib/json-coerce.d.ts +19 -0
- package/dist/lib/json-coerce.d.ts.map +1 -0
- package/dist/lib/json-coerce.js +29 -0
- package/dist/lib/json-coerce.js.map +1 -0
- package/dist/lib/opa-cli.d.ts.map +1 -1
- package/dist/lib/opa-cli.js +7 -2
- package/dist/lib/opa-cli.js.map +1 -1
- package/dist/lib/rego-smt-encoder.d.ts.map +1 -1
- package/dist/lib/rego-smt-encoder.js.map +1 -1
- package/dist/lib/rego-verify-engine.d.ts.map +1 -1
- package/dist/lib/rego-verify-engine.js +107 -81
- package/dist/lib/rego-verify-engine.js.map +1 -1
- package/dist/lib/tool-helpers.d.ts +9 -0
- package/dist/lib/tool-helpers.d.ts.map +1 -1
- package/dist/lib/tool-helpers.js +40 -6
- package/dist/lib/tool-helpers.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 +11 -5
- package/dist/resources/patterns.js.map +1 -1
- package/dist/tools/authoring/capabilities.js +2 -2
- package/dist/tools/evaluation/_shared.d.ts.map +1 -1
- package/dist/tools/evaluation/_shared.js +13 -1
- package/dist/tools/evaluation/_shared.js.map +1 -1
- package/dist/tools/evaluation/test-multiroot.d.ts.map +1 -1
- package/dist/tools/evaluation/test-multiroot.js +5 -3
- package/dist/tools/evaluation/test-multiroot.js.map +1 -1
- package/dist/tools/evaluation/test.js +13 -3
- package/dist/tools/evaluation/test.js.map +1 -1
- package/dist/tools/helpers/describe-policy.d.ts +4 -0
- package/dist/tools/helpers/describe-policy.d.ts.map +1 -1
- package/dist/tools/helpers/describe-policy.js +14 -5
- package/dist/tools/helpers/describe-policy.js.map +1 -1
- package/dist/tools/helpers/explain-undefined.d.ts.map +1 -1
- package/dist/tools/helpers/explain-undefined.js +11 -1
- package/dist/tools/helpers/explain-undefined.js.map +1 -1
- package/dist/tools/helpers/generate-test-skeleton.d.ts.map +1 -1
- package/dist/tools/helpers/generate-test-skeleton.js +4 -2
- package/dist/tools/helpers/generate-test-skeleton.js.map +1 -1
- package/dist/tools/server-management/_shared.d.ts.map +1 -1
- package/dist/tools/server-management/_shared.js +7 -3
- 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 +4 -3
- 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 +3 -2
- package/dist/tools/server-management/decisions.js.map +1 -1
- package/package.json +10 -10
|
@@ -46,104 +46,130 @@ export async function runVerify(ast, property, signal) {
|
|
|
46
46
|
if (hasUnsupportedInClauses) {
|
|
47
47
|
return inconclusive(property, `Rule "${property.ruleName}" contains constructs that cannot be encoded in Z3 (e.g. negation-as-failure, comprehensions, built-ins beyond string/comparison ops). Verification is inconclusive.`, unsupportedInRule, warnings);
|
|
48
48
|
}
|
|
49
|
-
// Type inference
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
49
|
+
// Type inference, encoding, and solving. A Z3 "Sorts X and Y are
|
|
50
|
+
// incompatible" error -- raised when a single input field is constrained to
|
|
51
|
+
// conflicting sorts within a clause (e.g. compared to both a number and a
|
|
52
|
+
// string) -- or any other encoder/solver failure is reported as inconclusive
|
|
53
|
+
// rather than thrown. A verification tool must never crash on a valid policy,
|
|
54
|
+
// and a raw stack trace (which leaks absolute filesystem paths) must never
|
|
55
|
+
// reach the caller.
|
|
56
|
+
try {
|
|
57
|
+
const typeResult = inferTypes([...walked.rules.values()], walked.inputPaths);
|
|
58
|
+
for (const conflict of typeResult.conflicts) {
|
|
59
|
+
warnings.push(conflict.reason);
|
|
60
|
+
}
|
|
61
|
+
signal?.throwIfAborted();
|
|
62
|
+
const Z3 = await getZ3();
|
|
63
|
+
signal?.throwIfAborted();
|
|
64
|
+
const callId = `v${_verifyCallCounter++}`;
|
|
65
|
+
const inputVars = createInputVars(Z3, walked.inputPaths, typeResult.sorts, callId);
|
|
66
|
+
const ctx = { Z3, inputVars, sorts: typeResult.sorts, callId };
|
|
67
|
+
const encoded = encodeRule(targetClauses, ctx);
|
|
68
|
+
warnings.push(...encoded.warnings);
|
|
69
|
+
// Z3's high-level Solver and Model objects use FinalizationRegistry internally
|
|
70
|
+
// (solver_dec_ref / model_dec_ref) so they are cleaned up when GC'd.
|
|
71
|
+
// We avoid holding a reference to the Model beyond extractCounterexample so
|
|
72
|
+
// it becomes eligible for GC as soon as the call returns, reducing WASM heap
|
|
73
|
+
// pressure under high call volume.
|
|
74
|
+
const solver = new Z3.Solver();
|
|
75
|
+
// Set timeout to prevent hanging on complex policies
|
|
76
|
+
solver.set('timeout', SOLVER_TIMEOUT_MS);
|
|
77
|
+
switch (property.kind) {
|
|
78
|
+
case 'always_true':
|
|
79
|
+
// Prove rule is always true: check if NOT(rule) is satisfiable.
|
|
80
|
+
// SAT → counterexample (input where rule is false)
|
|
81
|
+
// UNSAT → proven always true
|
|
82
|
+
solver.add(Z3.Not(encoded.formula));
|
|
83
|
+
break;
|
|
84
|
+
case 'never_true':
|
|
85
|
+
// Prove rule is never true: check if rule IS satisfiable.
|
|
86
|
+
// SAT → counterexample (input where rule fires, violating "never")
|
|
87
|
+
// UNSAT → proven never true
|
|
88
|
+
solver.add(encoded.formula);
|
|
89
|
+
break;
|
|
90
|
+
case 'satisfiable':
|
|
91
|
+
// Check if any input satisfies the rule.
|
|
92
|
+
// SAT → witness found (not a bug, just a satisfying input)
|
|
93
|
+
// UNSAT → rule is vacuously false / dead code
|
|
94
|
+
solver.add(encoded.formula);
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
signal?.throwIfAborted();
|
|
98
|
+
const solverResult = await solver.check();
|
|
99
|
+
if (solverResult === 'unknown') {
|
|
100
|
+
return inconclusive(property, `Z3 solver returned "unknown" (timeout or resource limit reached after ${SOLVER_TIMEOUT_MS}ms). The policy may be too complex for automated verification.`, unsupportedInRule, warnings);
|
|
101
|
+
}
|
|
102
|
+
if (solverResult === 'unsat') {
|
|
103
|
+
if (property.kind === 'satisfiable') {
|
|
104
|
+
// No satisfying input exists -- rule is dead code or has contradictory conditions.
|
|
105
|
+
return {
|
|
106
|
+
verdict: 'unsatisfiable',
|
|
107
|
+
property: describeProperty(property),
|
|
108
|
+
rule: property.ruleName,
|
|
109
|
+
unsupportedConstructs: unsupportedInRule,
|
|
110
|
+
warnings,
|
|
111
|
+
message: `UNSATISFIABLE: No input can make "${property.ruleName}" true. The rule may be dead code or have contradictory conditions.`,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
// For always_true / never_true: UNSAT on the negation = property proven
|
|
115
|
+
return {
|
|
116
|
+
verdict: 'proven',
|
|
117
|
+
property: describeProperty(property),
|
|
118
|
+
rule: property.ruleName,
|
|
119
|
+
unsupportedConstructs: unsupportedInRule,
|
|
120
|
+
warnings,
|
|
121
|
+
message: `PROVEN: ${describeProperty(property)}.`,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
// SAT: pass solver.model() inline so the Model object is not kept alive
|
|
125
|
+
// beyond extractCounterexample -- it becomes GC-eligible immediately after.
|
|
126
|
+
const ce = extractCounterexample(solver.model(), inputVars, typeResult.sorts);
|
|
127
|
+
const ceFormatted = formatCounterexample(ce);
|
|
96
128
|
if (property.kind === 'satisfiable') {
|
|
97
|
-
// No satisfying input exists -- rule is dead code or has contradictory conditions.
|
|
98
129
|
return {
|
|
99
|
-
verdict: '
|
|
130
|
+
verdict: 'proven',
|
|
100
131
|
property: describeProperty(property),
|
|
101
132
|
rule: property.ruleName,
|
|
133
|
+
counterexample: ce,
|
|
134
|
+
counterexampleFormatted: ceFormatted,
|
|
102
135
|
unsupportedConstructs: unsupportedInRule,
|
|
103
136
|
warnings,
|
|
104
|
-
message: `
|
|
137
|
+
message: `SATISFIABLE: Found an input that makes "${property.ruleName}" true.\n\nWitness input:\n${ceFormatted}`,
|
|
105
138
|
};
|
|
106
139
|
}
|
|
107
|
-
//
|
|
140
|
+
// always_true / never_true: SAT means we found a violation
|
|
141
|
+
const ceLabel = property.kind === 'always_true'
|
|
142
|
+
? 'input where rule is FALSE'
|
|
143
|
+
: 'input where rule is TRUE (violates "never")';
|
|
108
144
|
return {
|
|
109
|
-
verdict: '
|
|
110
|
-
property: describeProperty(property),
|
|
111
|
-
rule: property.ruleName,
|
|
112
|
-
unsupportedConstructs: unsupportedInRule,
|
|
113
|
-
warnings,
|
|
114
|
-
message: `PROVEN: ${describeProperty(property)}.`,
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
// SAT: pass solver.model() inline so the Model object is not kept alive
|
|
118
|
-
// beyond extractCounterexample -- it becomes GC-eligible immediately after.
|
|
119
|
-
const ce = extractCounterexample(solver.model(), inputVars, typeResult.sorts);
|
|
120
|
-
const ceFormatted = formatCounterexample(ce);
|
|
121
|
-
if (property.kind === 'satisfiable') {
|
|
122
|
-
return {
|
|
123
|
-
verdict: 'proven',
|
|
145
|
+
verdict: 'counterexample',
|
|
124
146
|
property: describeProperty(property),
|
|
125
147
|
rule: property.ruleName,
|
|
126
148
|
counterexample: ce,
|
|
127
149
|
counterexampleFormatted: ceFormatted,
|
|
128
150
|
unsupportedConstructs: unsupportedInRule,
|
|
129
151
|
warnings,
|
|
130
|
-
message: `
|
|
152
|
+
message: `COUNTEREXAMPLE: Property does NOT hold. Found ${ceLabel}:\n\n${ceFormatted}`,
|
|
131
153
|
};
|
|
132
154
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
155
|
+
catch (e) {
|
|
156
|
+
// A cancellation must propagate as a cancellation, not be masked as a
|
|
157
|
+
// verdict; everything else (most notably a Z3 sort conflict) becomes a
|
|
158
|
+
// sound "inconclusive" instead of crashing the tool.
|
|
159
|
+
if (signal?.aborted)
|
|
160
|
+
throw e;
|
|
161
|
+
const detail = e instanceof Error ? e.message : String(e);
|
|
162
|
+
const isSortConflict = /sort/i.test(detail) && /incompat/i.test(detail);
|
|
163
|
+
return inconclusive(property, isSortConflict
|
|
164
|
+
? 'The rule constrains an input field to conflicting types (for example, compared against both a number and a string), which cannot be encoded for SMT solving.'
|
|
165
|
+
: 'Verification could not be completed due to an internal encoding or solver error.', [
|
|
166
|
+
...unsupportedInRule,
|
|
167
|
+
{
|
|
168
|
+
constructType: isSortConflict ? 'type_conflict' : 'encoding_error',
|
|
169
|
+
description: detail,
|
|
170
|
+
},
|
|
171
|
+
], warnings);
|
|
172
|
+
}
|
|
147
173
|
}
|
|
148
174
|
function inconclusive(property, reason, unsupportedConstructs, warnings) {
|
|
149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;oBACjB,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,IAAI;oBACV,qBAAqB;oBACrB,QAAQ;oBACR,OAAO,EAAE,WAAW,IAAI,WAAW,IAAI,2DAA2D;iBACnG,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,gBAAgB;gBACzB,QAAQ,EAAE,IAAI;gBACd,IAAI,EAAE,IAAI;gBACV,cAAc,EAAE,YAAY;gBAC5B,uBAAuB,EAAE,cAAc;gBACvC,qBAAqB;gBACrB,QAAQ;gBACR,OAAO,EAAE,yBAAyB,IAAI,0GAA0G;aACjJ,CAAC;QAEJ,KAAK,aAAa;YAChB,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO;oBACL,OAAO,EAAE,QAAQ;oBACjB,QAAQ,EAAE,IAAI;oBACd,IAAI,EAAE,IAAI;oBACV,cAAc,EAAE,YAAY;oBAC5B,uBAAuB,EAAE,cAAc;oBACvC,qBAAqB;oBACrB,QAAQ;oBACR,OAAO,EAAE,sBAAsB,IAAI,kEAAkE;iBACtG,CAAC;YACJ,CAAC;YACD,OAAO;gBACL,OAAO,EAAE,eAAe;gBACxB,QAAQ,EAAE,IAAI;gBACd,IAAI,EAAE,IAAI;gBACV,qBAAqB;gBACrB,QAAQ;gBACR,OAAO,EAAE,wBAAwB,IAAI,sEAAsE;aAC5G,CAAC;IACN,CAAC;AACH,CAAC"}
|
|
@@ -20,6 +20,15 @@ export declare const INLINE_TEMP_PATH_PATTERN: RegExp;
|
|
|
20
20
|
* to all location.file values regardless of whether inline source was used.
|
|
21
21
|
*/
|
|
22
22
|
export declare function sanitizeInlinePath(file: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Recursively rewrite every temp-file path -- in both string values and object
|
|
25
|
+
* keys -- to the `<inline>` sentinel. OPA writes inline source to a temp file,
|
|
26
|
+
* so trace (`explanation`), coverage, and profile output reference that path;
|
|
27
|
+
* this normalizes the whole structure so callers never see an absolute temp
|
|
28
|
+
* path. Only our own temp paths match the pattern, so real user file paths pass
|
|
29
|
+
* through untouched.
|
|
30
|
+
*/
|
|
31
|
+
export declare function sanitizeInlinePathsDeep(value: unknown): unknown;
|
|
23
32
|
import type { Config } from '../config.js';
|
|
24
33
|
import { type McpToolResult } from './output.js';
|
|
25
34
|
import type { SpawnResult } from './subprocess.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,QAAsD,CAAC;AAE5F;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AACD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"tool-helpers.d.ts","sourceRoot":"","sources":["../../src/lib/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,eAAO,MAAM,wBAAwB,QAAsD,CAAC;AAE5F;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEvD;AAED;;;;;;;GAOG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAW/D;AACD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAG3C,OAAO,EAAkB,KAAK,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,KAAK,EAAE,YAAY,EAAiB,MAAM,aAAa,CAAC;AAE/D;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,KAAK,GAAG,OAAO,GAAG,UAAU,GACnC,YAAY,CAAC,KAAK,CAAC,GAAG,SAAS,CAmCjC;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,CAAC,GAAG,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS,CAOrE;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EACd,OAAO,GAAE;IAAE,SAAS,CAAC,EAAE,OAAO,CAAA;CAAO,GACpC;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAA;CAAE,CAU9E;AAED;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GACnC,OAAO,CAAC,aAAa,CAAC,CAgBxB"}
|
package/dist/lib/tool-helpers.js
CHANGED
|
@@ -22,7 +22,30 @@ export const INLINE_TEMP_PATH_PATTERN = /orygn-(?:opa|regal)-mcp-[^/\\]+[/\\]inp
|
|
|
22
22
|
export function sanitizeInlinePath(file) {
|
|
23
23
|
return INLINE_TEMP_PATH_PATTERN.test(file) ? '<inline>' : file;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Recursively rewrite every temp-file path -- in both string values and object
|
|
27
|
+
* keys -- to the `<inline>` sentinel. OPA writes inline source to a temp file,
|
|
28
|
+
* so trace (`explanation`), coverage, and profile output reference that path;
|
|
29
|
+
* this normalizes the whole structure so callers never see an absolute temp
|
|
30
|
+
* path. Only our own temp paths match the pattern, so real user file paths pass
|
|
31
|
+
* through untouched.
|
|
32
|
+
*/
|
|
33
|
+
export function sanitizeInlinePathsDeep(value) {
|
|
34
|
+
if (typeof value === 'string')
|
|
35
|
+
return sanitizeInlinePath(value);
|
|
36
|
+
if (Array.isArray(value))
|
|
37
|
+
return value.map(sanitizeInlinePathsDeep);
|
|
38
|
+
if (value !== null && typeof value === 'object') {
|
|
39
|
+
const out = {};
|
|
40
|
+
for (const [key, val] of Object.entries(value)) {
|
|
41
|
+
out[sanitizeInlinePath(key)] = sanitizeInlinePathsDeep(val);
|
|
42
|
+
}
|
|
43
|
+
return out;
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
25
47
|
import { err } from './errors.js';
|
|
48
|
+
import { logger } from './logger.js';
|
|
26
49
|
import { formatEnvelope } from './output.js';
|
|
27
50
|
import { validatePath } from './security.js';
|
|
28
51
|
/**
|
|
@@ -38,6 +61,15 @@ export function mapSubprocessFailure(result, binary) {
|
|
|
38
61
|
details: { durationMs: result.durationMs },
|
|
39
62
|
});
|
|
40
63
|
}
|
|
64
|
+
// A timed-out process is killed, so it also reports a null exit code. Check
|
|
65
|
+
// the timeout first, otherwise a slow command (e.g. `opa bench` on a large
|
|
66
|
+
// policy) is misreported as a missing binary and sends the user hunting for
|
|
67
|
+
// an install problem that does not exist.
|
|
68
|
+
if (result.timedOut) {
|
|
69
|
+
return err('TIMEOUT', `${binary} subprocess exceeded the configured timeout (OPA_MCP_TIMEOUT_MS).`, {
|
|
70
|
+
details: { durationMs: result.durationMs },
|
|
71
|
+
});
|
|
72
|
+
}
|
|
41
73
|
if (result.exitCode === null) {
|
|
42
74
|
const code = binary === 'opa'
|
|
43
75
|
? 'OPA_BINARY_NOT_FOUND'
|
|
@@ -51,11 +83,6 @@ export function mapSubprocessFailure(result, binary) {
|
|
|
51
83
|
: 'Install Conftest (https://www.conftest.dev/) or set CONFTEST_BINARY to the absolute path of the binary.';
|
|
52
84
|
return err(code, `${binary} binary unreachable: ${result.stderr || 'spawn failed'}`, { hint });
|
|
53
85
|
}
|
|
54
|
-
if (result.timedOut) {
|
|
55
|
-
return err('TIMEOUT', `${binary} subprocess exceeded the configured timeout (OPA_MCP_TIMEOUT_MS).`, {
|
|
56
|
-
details: { durationMs: result.durationMs },
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
86
|
return undefined;
|
|
60
87
|
}
|
|
61
88
|
/**
|
|
@@ -101,7 +128,14 @@ export async function withToolEnvelope(config, body) {
|
|
|
101
128
|
}
|
|
102
129
|
catch (e) {
|
|
103
130
|
const message = e instanceof Error ? e.message : 'An unknown error occurred';
|
|
104
|
-
|
|
131
|
+
// Log the full error (with stack) server-side, but never return a raw stack
|
|
132
|
+
// trace to the client: it leaks absolute filesystem paths and is not
|
|
133
|
+
// actionable. Non-Error throws keep their thrown value in details.
|
|
134
|
+
logger.error('Unhandled tool error', {
|
|
135
|
+
message,
|
|
136
|
+
stack: e instanceof Error ? e.stack : undefined,
|
|
137
|
+
});
|
|
138
|
+
const details = e instanceof Error ? undefined : { value: e };
|
|
105
139
|
return formatEnvelope(err('UNKNOWN_ERROR', message, { details }), config.maxResponseBytes);
|
|
106
140
|
}
|
|
107
141
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool-helpers.js","sourceRoot":"","sources":["../../src/lib/tool-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,mDAAmD,CAAC;AAE5F;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,IAAY;IAC7C,OAAO,wBAAwB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC;AACjE,CAAC;AAED,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,cAAc,EAAsB,MAAM,aAAa,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAI7C;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAAmB,EACnB,MAAoC;IAEpC,IAAI,MAAM,CAAC,OAAO,EAAE,CAAC;QACnB,OAAO,GAAG,CAAC,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,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAc,EACd,IAAoC;IAEpC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,IAAI,EAAE,CAAC;QAC9B,OAAO,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,CAAC,EAAE,CAAC;QACX,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CAAC;QAC7E,4EAA4E;QAC5E,qEAAqE;QACrE,mEAAmE;QACnE,MAAM,CAAC,KAAK,CAAC,sBAAsB,EAAE;YACnC,OAAO;YACP,KAAK,EAAE,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS;SAChD,CAAC,CAAC;QACH,MAAM,OAAO,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;QAC9D,OAAO,cAAc,CAAC,GAAG,CAAC,eAAe,EAAE,OAAO,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAC7F,CAAC;AACH,CAAC"}
|
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* - A test
|
|
6
6
|
* - Common pitfalls
|
|
7
7
|
*/
|
|
8
|
-
export declare const PATTERNS = "# Rego pattern library\n\nCommon Rego patterns with working examples, tests, and pitfalls. Each\npattern is self-contained -- copy, adapt, and ship.\n\n---\n\n## 1. Role-based access control (RBAC)\n\n**When to use:** the simplest authorization model. Every user has one\nor more roles; each role grants a set of actions on a set of\nresources. Sufficient for ~80% of internal applications.\n\n```rego\npackage rbac\n\nimport rego.v1\n\ndefault allow := false\n\n# Permissions table -- extend as roles evolve.\npermissions := {\n \"admin\": {\"read\", \"write\", \"delete\", \"manage_users\"},\n \"editor\": {\"read\", \"write\"},\n \"viewer\": {\"read\"},\n}\n\nallow if {\n some role in input.user.roles\n input.action in permissions[role]\n}\n\n# Why was it denied? -- useful for audit logs.\ndeny_reasons contains reason if {\n not allow\n input.user\n reason := sprintf(\n \"user %q has roles %v, none grant %q\",\n [input.user.id, input.user.roles, input.action],\n )\n}\n\ndeny_reasons contains \"anonymous request\" if {\n not allow\n not input.user\n}\n```\n\n**Test:**\n\n```rego\npackage rbac_test\n\nimport rego.v1\nimport data.rbac\n\ntest_admin_can_delete if {\n rbac.allow with input as {\n \"user\": {\"id\": \"alice\", \"roles\": [\"admin\"]},\n \"action\": \"delete\",\n }\n}\n\ntest_viewer_cannot_delete if {\n not rbac.allow with input as {\n \"user\": {\"id\": \"bob\", \"roles\": [\"viewer\"]},\n \"action\": \"delete\",\n }\n}\n\ntest_anonymous_denied if {\n not rbac.allow with input as {\"action\": \"read\"}\n \"anonymous request\" in (rbac.deny_reasons with input as {\"action\": \"read\"})\n}\n```\n\n**Pitfalls:**\n- The `permissions` table grows unbounded. Move to data files\n (`data.permissions`) once you have more than ~20 roles.\n- Roles overlap with groups in real auth systems; map at the boundary\n rather than carrying both.\n\n---\n\n## 2. Attribute-based access control (ABAC)\n\n**When to use:** when \"who\" alone isn't enough -- decisions also depend\non resource attributes (ownership, tenant, sensitivity) and context\n(time of day, source IP).\n\n```rego\npackage abac\n\nimport rego.v1\n\ndefault allow := false\n\n# A user can read any resource they own.\nallow if {\n input.action == \"read\"\n input.resource.owner_id == input.user.id\n}\n\n# A user can read shared resources at their organization.\nallow if {\n input.action == \"read\"\n input.resource.shared\n input.resource.org_id == input.user.org_id\n}\n\n# Admins can do anything within their organization.\nallow if {\n \"admin\" in input.user.roles\n input.resource.org_id == input.user.org_id\n}\n\n# Don't show \"secret\" resources to anyone outside the owner's\n# organization, even admins.\nallow := false if {\n input.resource.classification == \"secret\"\n input.resource.org_id != input.user.org_id\n}\n```\n\n**Test:**\n\n```rego\npackage abac_test\n\nimport rego.v1\nimport data.abac\n\ntest_owner_reads_own if {\n abac.allow with input as {\n \"action\": \"read\",\n \"user\": {\"id\": \"u1\", \"org_id\": \"o1\"},\n \"resource\": {\"owner_id\": \"u1\", \"org_id\": \"o1\"},\n }\n}\n\ntest_admin_blocked_from_secret_in_other_org if {\n not abac.allow with input as {\n \"action\": \"read\",\n \"user\": {\"id\": \"u1\", \"org_id\": \"o1\", \"roles\": [\"admin\"]},\n \"resource\": {\n \"owner_id\": \"u2\",\n \"org_id\": \"o2\",\n \"classification\": \"secret\",\n },\n }\n}\n```\n\n**Pitfalls:**\n- Multiple `allow` rules combine with logical OR. Use explicit\n `allow := false if ...` to *override* an allow.\n- Don't compute attributes inside the policy; compute them at the\n boundary and pass via `input`.\n\n---\n\n## 3. Kubernetes admission control\n\n**When to use:** validate or mutate Kubernetes resources at admission\ntime. Run as a Gatekeeper, OPA-as-a-webhook, or Kyverno-equivalent\npolicy layer.\n\n```rego\npackage k8s.admission\n\nimport rego.v1\n\n# Reject pods without resource limits.\ndeny contains msg if {\n input.request.kind.kind == \"Pod\"\n container := input.request.object.spec.containers[_]\n not container.resources.limits.memory\n msg := sprintf(\n \"Pod %q container %q is missing resources.limits.memory\",\n [input.request.object.metadata.name, container.name],\n )\n}\n\n# Reject privileged containers in production.\ndeny contains msg if {\n input.request.kind.kind == \"Pod\"\n input.request.namespace != \"kube-system\"\n container := input.request.object.spec.containers[_]\n container.securityContext.privileged == true\n msg := sprintf(\n \"privileged containers are not allowed: %q in %q\",\n [container.name, input.request.object.metadata.name],\n )\n}\n```\n\n**Pitfalls:**\n- Use `input.request.object` for the resource being admitted; the\n envelope shape comes from Kubernetes, not your control.\n- For mutations, return a JSON Patch via the `patch` field. Test\n patches with the actual admission webhook in dry-run mode before\n enforcing.\n- Iteration order is undefined; never rely on `containers[0]` to mean\n anything specific.\n\n---\n\n## 4. Infrastructure-as-Code gates (Terraform)\n\n**When to use:** validate Terraform plans before apply. Catch overly\npermissive IAM, public S3 buckets, missing encryption.\n\n```rego\npackage terraform\n\nimport rego.v1\n\n# Reject S3 buckets without server-side encryption.\ndeny contains msg if {\n resource := input.resource_changes[_]\n resource.type == \"aws_s3_bucket\"\n after := resource.change.after\n not after.server_side_encryption_configuration\n msg := sprintf(\n \"S3 bucket %q has no server-side encryption configured\",\n [resource.address],\n )\n}\n\n# Reject IAM policies with action \"*\" on resource \"*\".\ndeny contains msg if {\n resource := input.resource_changes[_]\n resource.type == \"aws_iam_policy\"\n policy := json.unmarshal(resource.change.after.policy)\n statement := policy.Statement[_]\n statement.Effect == \"Allow\"\n \"*\" in statement.Action\n statement.Resource == \"*\"\n msg := sprintf(\"IAM policy %q grants Allow * on *\", [resource.address])\n}\n```\n\n**Pitfalls:**\n- Terraform plan JSON is verbose and version-specific. Pin the\n `terraform plan -json` schema you target.\n- `resource_changes[_].change.after` may be `null` for destroys --\n guard against it.\n- For wide-radius changes, use `opa exec --decision` against a plan\n file in CI, not the live API.\n\n---\n\n## 5. API authorization (HTTP request gating)\n\n**When to use:** at the API gateway / reverse proxy layer, validate\neach request against the caller's identity and the requested\nendpoint.\n\n```rego\npackage api.authz\n\nimport rego.v1\n\ndefault allow := false\n\n# Public endpoints -- no auth required.\npublic_endpoints := {\n {\"method\": \"GET\", \"path\": [\"health\"]},\n {\"method\": \"GET\", \"path\": [\"version\"]},\n}\n\nallow if some _ in public_endpoints; matches_endpoint(_)\n\n# Authenticated reads on resources the user has access to.\nallow if {\n input.method == \"GET\"\n input.user\n user_can_read(input.user, input.path)\n}\n\n# Authenticated writes only with specific scopes.\nallow if {\n input.method in {\"POST\", \"PUT\", \"PATCH\", \"DELETE\"}\n input.user\n \"write\" in input.user.scopes\n user_can_write(input.user, input.path)\n}\n\nmatches_endpoint(spec) if {\n spec.method == input.method\n spec.path == input.path\n}\n\nuser_can_read(user, path) if {\n path[0] == \"users\"\n user.id == path[1]\n}\n\nuser_can_write(user, path) if {\n path[0] == \"users\"\n user.id == path[1]\n}\n```\n\n**Pitfalls:**\n- `input.path` is typically an array (`[\"users\", \"alice\"]`), not a\n string. Build it consistently at the gateway.\n- Path-prefix matching is easy; full pattern matching is not. For\n parameterized routes, decode at the gateway and pass structured\n fields.\n\n---\n\n## 6. Rate limiting (with sliding window data)\n\n**When to use:** allow N requests per principal per window. Lightweight\nlimit enforcement; for high throughput, push to a dedicated rate\nlimiter.\n\n```rego\npackage rate\n\nimport rego.v1\n\n# Configuration: 100 requests per principal per 60-second window.\nlimit := 100\nwindow_seconds := 60\n\n# input.now is a unix timestamp in nanoseconds.\n# data.requests[principal] is an array of nanosecond timestamps.\n\ncurrent_window := requests if {\n requests := [t | some t in data.requests[input.principal]; t > input.now - window_seconds * 1000000000]\n}\n\ncount := count(current_window)\n\nallow if count < limit\n\ndeny_reason := sprintf(\n \"rate limit exceeded: %d requests in last %d seconds (limit %d)\",\n [count, window_seconds, limit],\n) if not allow\n```\n\n**Pitfalls:**\n- `data.requests` grows unbounded unless the writer prunes outside the\n window. Schedule prune on every write.\n- This pattern is *advisory* -- under load, two concurrent decisions\n can both see `count == limit - 1` and both allow. For strict\n limits, use a Lua/Redis token bucket at the gateway and have OPA\n validate the token, not count requests.\n\n---\n\n## Where these patterns came from\n\nEach is distilled from production policy code. The full Rego files,\ntests, and policy data fixtures live in this server's GitHub\nrepository under `tests/fixtures/policies/`.\n\nFor more patterns, see:\n\n- OPA Playground: https://play.openpolicyagent.org/\n- Awesome OPA: https://github.com/anderseknert/awesome-opa\n- Styra DAS pattern library: https://docs.styra.com/das/policies\n";
|
|
8
|
+
export declare const PATTERNS = "# Rego pattern library\n\nCommon Rego patterns with working examples, tests, and pitfalls. Each\npattern is self-contained -- copy, adapt, and ship.\n\n---\n\n## 1. Role-based access control (RBAC)\n\n**When to use:** the simplest authorization model. Every user has one\nor more roles; each role grants a set of actions on a set of\nresources. Sufficient for ~80% of internal applications.\n\n```rego\npackage rbac\n\nimport rego.v1\n\ndefault allow := false\n\n# Permissions table -- extend as roles evolve.\npermissions := {\n \"admin\": {\"read\", \"write\", \"delete\", \"manage_users\"},\n \"editor\": {\"read\", \"write\"},\n \"viewer\": {\"read\"},\n}\n\nallow if {\n some role in input.user.roles\n input.action in permissions[role]\n}\n\n# Why was it denied? -- useful for audit logs.\ndeny_reasons contains reason if {\n not allow\n input.user\n reason := sprintf(\n \"user %q has roles %v, none grant %q\",\n [input.user.id, input.user.roles, input.action],\n )\n}\n\ndeny_reasons contains \"anonymous request\" if {\n not allow\n not input.user\n}\n```\n\n**Test:**\n\n```rego\npackage rbac_test\n\nimport rego.v1\nimport data.rbac\n\ntest_admin_can_delete if {\n rbac.allow with input as {\n \"user\": {\"id\": \"alice\", \"roles\": [\"admin\"]},\n \"action\": \"delete\",\n }\n}\n\ntest_viewer_cannot_delete if {\n not rbac.allow with input as {\n \"user\": {\"id\": \"bob\", \"roles\": [\"viewer\"]},\n \"action\": \"delete\",\n }\n}\n\ntest_anonymous_denied if {\n not rbac.allow with input as {\"action\": \"read\"}\n reasons := rbac.deny_reasons with input as {\"action\": \"read\"}\n \"anonymous request\" in reasons\n}\n```\n\n**Pitfalls:**\n- The `permissions` table grows unbounded. Move to data files\n (`data.permissions`) once you have more than ~20 roles.\n- Roles overlap with groups in real auth systems; map at the boundary\n rather than carrying both.\n\n---\n\n## 2. Attribute-based access control (ABAC)\n\n**When to use:** when \"who\" alone isn't enough -- decisions also depend\non resource attributes (ownership, tenant, sensitivity) and context\n(time of day, source IP).\n\n```rego\npackage abac\n\nimport rego.v1\n\ndefault allow := false\n\n# A user can read any resource they own.\nallow if {\n input.action == \"read\"\n input.resource.owner_id == input.user.id\n}\n\n# A user can read shared resources at their organization.\nallow if {\n input.action == \"read\"\n input.resource.shared\n input.resource.org_id == input.user.org_id\n}\n\n# Admins can do anything within their organization.\nallow if {\n \"admin\" in input.user.roles\n input.resource.org_id == input.user.org_id\n}\n\n# Don't show \"secret\" resources to anyone outside the owner's\n# organization, even admins.\nallow := false if {\n input.resource.classification == \"secret\"\n input.resource.org_id != input.user.org_id\n}\n```\n\n**Test:**\n\n```rego\npackage abac_test\n\nimport rego.v1\nimport data.abac\n\ntest_owner_reads_own if {\n abac.allow with input as {\n \"action\": \"read\",\n \"user\": {\"id\": \"u1\", \"org_id\": \"o1\"},\n \"resource\": {\"owner_id\": \"u1\", \"org_id\": \"o1\"},\n }\n}\n\ntest_admin_blocked_from_secret_in_other_org if {\n not abac.allow with input as {\n \"action\": \"read\",\n \"user\": {\"id\": \"u1\", \"org_id\": \"o1\", \"roles\": [\"admin\"]},\n \"resource\": {\n \"owner_id\": \"u2\",\n \"org_id\": \"o2\",\n \"classification\": \"secret\",\n },\n }\n}\n```\n\n**Pitfalls:**\n- Multiple `allow` rules combine with logical OR. Use explicit\n `allow := false if ...` to *override* an allow.\n- Don't compute attributes inside the policy; compute them at the\n boundary and pass via `input`.\n\n---\n\n## 3. Kubernetes admission control\n\n**When to use:** validate or mutate Kubernetes resources at admission\ntime. Run as a Gatekeeper, OPA-as-a-webhook, or Kyverno-equivalent\npolicy layer.\n\n```rego\npackage k8s.admission\n\nimport rego.v1\n\n# Reject pods without resource limits.\ndeny contains msg if {\n input.request.kind.kind == \"Pod\"\n container := input.request.object.spec.containers[_]\n not container.resources.limits.memory\n msg := sprintf(\n \"Pod %q container %q is missing resources.limits.memory\",\n [input.request.object.metadata.name, container.name],\n )\n}\n\n# Reject privileged containers in production.\ndeny contains msg if {\n input.request.kind.kind == \"Pod\"\n input.request.namespace != \"kube-system\"\n container := input.request.object.spec.containers[_]\n container.securityContext.privileged == true\n msg := sprintf(\n \"privileged containers are not allowed: %q in %q\",\n [container.name, input.request.object.metadata.name],\n )\n}\n```\n\n**Pitfalls:**\n- Use `input.request.object` for the resource being admitted; the\n envelope shape comes from Kubernetes, not your control.\n- For mutations, return a JSON Patch via the `patch` field. Test\n patches with the actual admission webhook in dry-run mode before\n enforcing.\n- Iteration order is undefined; never rely on `containers[0]` to mean\n anything specific.\n\n---\n\n## 4. Infrastructure-as-Code gates (Terraform)\n\n**When to use:** validate Terraform plans before apply. Catch overly\npermissive IAM, public S3 buckets, missing encryption.\n\n```rego\npackage terraform\n\nimport rego.v1\n\n# Reject S3 buckets without server-side encryption.\ndeny contains msg if {\n resource := input.resource_changes[_]\n resource.type == \"aws_s3_bucket\"\n after := resource.change.after\n not after.server_side_encryption_configuration\n msg := sprintf(\n \"S3 bucket %q has no server-side encryption configured\",\n [resource.address],\n )\n}\n\n# Reject IAM policies with action \"*\" on resource \"*\".\ndeny contains msg if {\n resource := input.resource_changes[_]\n resource.type == \"aws_iam_policy\"\n policy := json.unmarshal(resource.change.after.policy)\n statement := policy.Statement[_]\n statement.Effect == \"Allow\"\n \"*\" in statement.Action\n statement.Resource == \"*\"\n msg := sprintf(\"IAM policy %q grants Allow * on *\", [resource.address])\n}\n```\n\n**Pitfalls:**\n- Terraform plan JSON is verbose and version-specific. Pin the\n `terraform plan -json` schema you target.\n- `resource_changes[_].change.after` may be `null` for destroys --\n guard against it.\n- For wide-radius changes, use `opa exec --decision` against a plan\n file in CI, not the live API.\n\n---\n\n## 5. API authorization (HTTP request gating)\n\n**When to use:** at the API gateway / reverse proxy layer, validate\neach request against the caller's identity and the requested\nendpoint.\n\n```rego\npackage api.authz\n\nimport rego.v1\n\ndefault allow := false\n\n# Public endpoints -- no auth required.\npublic_endpoints := {\n {\"method\": \"GET\", \"path\": [\"health\"]},\n {\"method\": \"GET\", \"path\": [\"version\"]},\n}\n\nallow if {\n some endpoint in public_endpoints\n matches_endpoint(endpoint)\n}\n\n# Authenticated reads on resources the user has access to.\nallow if {\n input.method == \"GET\"\n input.user\n user_can_read(input.user, input.path)\n}\n\n# Authenticated writes only with specific scopes.\nallow if {\n input.method in {\"POST\", \"PUT\", \"PATCH\", \"DELETE\"}\n input.user\n \"write\" in input.user.scopes\n user_can_write(input.user, input.path)\n}\n\nmatches_endpoint(spec) if {\n spec.method == input.method\n spec.path == input.path\n}\n\nuser_can_read(user, path) if {\n path[0] == \"users\"\n user.id == path[1]\n}\n\nuser_can_write(user, path) if {\n path[0] == \"users\"\n user.id == path[1]\n}\n```\n\n**Pitfalls:**\n- `input.path` is typically an array (`[\"users\", \"alice\"]`), not a\n string. Build it consistently at the gateway.\n- Path-prefix matching is easy; full pattern matching is not. For\n parameterized routes, decode at the gateway and pass structured\n fields.\n\n---\n\n## 6. Rate limiting (with sliding window data)\n\n**When to use:** allow N requests per principal per window. Lightweight\nlimit enforcement; for high throughput, push to a dedicated rate\nlimiter.\n\n```rego\npackage rate\n\nimport rego.v1\n\n# Configuration: 100 requests per principal per 60-second window.\nlimit := 100\nwindow_seconds := 60\n\n# input.now is a unix timestamp in nanoseconds.\n# data.requests[principal] is an array of nanosecond timestamps.\n\ncurrent_window := requests if {\n requests := [t | some t in data.requests[input.principal]; t > input.now - window_seconds * 1000000000]\n}\n\n# Do not name this rule `count`: it would shadow the built-in of the same\n# name, and the call below would resolve to the rule instead.\nrequest_count := count(current_window)\n\nallow if request_count < limit\n\ndeny_reason := sprintf(\n \"rate limit exceeded: %d requests in last %d seconds (limit %d)\",\n [request_count, window_seconds, limit],\n) if not allow\n```\n\n**Pitfalls:**\n- `data.requests` grows unbounded unless the writer prunes outside the\n window. Schedule prune on every write.\n- This pattern is *advisory* -- under load, two concurrent decisions\n can both see `count == limit - 1` and both allow. For strict\n limits, use a Lua/Redis token bucket at the gateway and have OPA\n validate the token, not count requests.\n\n---\n\n## Where these patterns came from\n\nEach is distilled from production policy code. The full Rego files,\ntests, and policy data fixtures live in this server's GitHub\nrepository under `tests/fixtures/policies/`.\n\nFor more patterns, see:\n\n- OPA Playground: https://play.openpolicyagent.org/\n- Awesome OPA: https://github.com/anderseknert/awesome-opa\n- Styra DAS pattern library: https://docs.styra.com/das/policies\n";
|
|
9
9
|
//# sourceMappingURL=patterns.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/resources/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,
|
|
1
|
+
{"version":3,"file":"patterns.d.ts","sourceRoot":"","sources":["../../src/resources/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ,wwTAoXpB,CAAC"}
|
|
@@ -77,7 +77,8 @@ test_viewer_cannot_delete if {
|
|
|
77
77
|
|
|
78
78
|
test_anonymous_denied if {
|
|
79
79
|
not rbac.allow with input as {"action": "read"}
|
|
80
|
-
|
|
80
|
+
reasons := rbac.deny_reasons with input as {"action": "read"}
|
|
81
|
+
"anonymous request" in reasons
|
|
81
82
|
}
|
|
82
83
|
\`\`\`
|
|
83
84
|
|
|
@@ -276,7 +277,10 @@ public_endpoints := {
|
|
|
276
277
|
{"method": "GET", "path": ["version"]},
|
|
277
278
|
}
|
|
278
279
|
|
|
279
|
-
allow if
|
|
280
|
+
allow if {
|
|
281
|
+
some endpoint in public_endpoints
|
|
282
|
+
matches_endpoint(endpoint)
|
|
283
|
+
}
|
|
280
284
|
|
|
281
285
|
# Authenticated reads on resources the user has access to.
|
|
282
286
|
allow if {
|
|
@@ -340,13 +344,15 @@ current_window := requests if {
|
|
|
340
344
|
requests := [t | some t in data.requests[input.principal]; t > input.now - window_seconds * 1000000000]
|
|
341
345
|
}
|
|
342
346
|
|
|
343
|
-
count
|
|
347
|
+
# Do not name this rule \`count\`: it would shadow the built-in of the same
|
|
348
|
+
# name, and the call below would resolve to the rule instead.
|
|
349
|
+
request_count := count(current_window)
|
|
344
350
|
|
|
345
|
-
allow if
|
|
351
|
+
allow if request_count < limit
|
|
346
352
|
|
|
347
353
|
deny_reason := sprintf(
|
|
348
354
|
"rate limit exceeded: %d requests in last %d seconds (limit %d)",
|
|
349
|
-
[
|
|
355
|
+
[request_count, window_seconds, limit],
|
|
350
356
|
) if not allow
|
|
351
357
|
\`\`\`
|
|
352
358
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/resources/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG
|
|
1
|
+
{"version":3,"file":"patterns.js","sourceRoot":"","sources":["../../src/resources/patterns.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoXvB,CAAC"}
|
|
@@ -17,7 +17,7 @@ const RegoCapabilitiesInput = {
|
|
|
17
17
|
version: z
|
|
18
18
|
.string()
|
|
19
19
|
.optional()
|
|
20
|
-
.describe('A specific OPA capabilities version (e.g. "
|
|
20
|
+
.describe('A specific OPA capabilities version (e.g. "v1.19.0"). When neither flag is set, lists available versions.'),
|
|
21
21
|
names_only: z
|
|
22
22
|
.boolean()
|
|
23
23
|
.optional()
|
|
@@ -28,7 +28,7 @@ export function registerRegoCapabilities(server, config) {
|
|
|
28
28
|
const opa = new OpaCli(config);
|
|
29
29
|
server.registerTool('rego_capabilities', {
|
|
30
30
|
title: 'OPA capabilities',
|
|
31
|
-
description: 'Return OPA capabilities -- the available builtins, future keywords, features, and WASM ABI versions. With `current: true`, returns the running OPA\'s capabilities. With `version: "
|
|
31
|
+
description: 'Return OPA capabilities -- the available builtins, future keywords, features, and WASM ABI versions. With `current: true`, returns the running OPA\'s capabilities. With `version: "v1.19.0"`, returns those of a specific version. With neither, lists available named versions. By default (`names_only: true`), returns only builtin names and count to stay within response size limits; pass `names_only: false` for full type signatures and documentation.',
|
|
32
32
|
inputSchema: RegoCapabilitiesInput,
|
|
33
33
|
annotations: {
|
|
34
34
|
readOnlyHint: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../../src/tools/evaluation/_shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../../src/tools/evaluation/_shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,sBAAsB,CAAC;AAO9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD,oEAAoE;AACpE,eAAO,MAAM,eAAe;;;;;;;;;CAwB3B,CAAC;AAEF,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,WAAW,CAAC,EAAE,OAAO,EAAE,CAAC;IACxB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,UAAU,QAAQ;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,mBAAmB,CAAC,EAAE,OAAO,CAAC;CAC/B;AAED,UAAU,SAAS;IACjB,OAAO,CAAC,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC;IAC/C,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAsB,OAAO,CAC3B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,QAAQ,EACd,KAAK,EAAE,SAAS,EAChB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,YAAY,CAAC,cAAc,CAAC,CAAC,CAiFvC"}
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import { z } from 'zod';
|
|
11
11
|
import { err, ok } from '../../lib/errors.js';
|
|
12
|
-
import { mapSubprocessFailure, tryParseJson, validatePaths } from '../../lib/tool-helpers.js';
|
|
12
|
+
import { mapSubprocessFailure, sanitizeInlinePathsDeep, tryParseJson, validatePaths, } from '../../lib/tool-helpers.js';
|
|
13
13
|
/** Common input fields shared across rego_eval and its variants. */
|
|
14
14
|
export const SharedEvalInput = {
|
|
15
15
|
query: z.string().min(1).describe('Rego query to evaluate, e.g. "data.example.allow".'),
|
|
@@ -106,6 +106,18 @@ export async function runEval(opa, config, args, flags, signal) {
|
|
|
106
106
|
details: { stdout: result.stdout.trim() },
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
+
// OPA references the temp file it wrote inline source to in trace, coverage,
|
|
110
|
+
// and profile output. Normalize those paths to <inline> for consistency with
|
|
111
|
+
// rego_check and to avoid exposing the temp directory layout.
|
|
112
|
+
if (parsed.explanation) {
|
|
113
|
+
parsed.explanation = sanitizeInlinePathsDeep(parsed.explanation);
|
|
114
|
+
}
|
|
115
|
+
if (parsed.coverage !== undefined) {
|
|
116
|
+
parsed.coverage = sanitizeInlinePathsDeep(parsed.coverage);
|
|
117
|
+
}
|
|
118
|
+
if (parsed.profile) {
|
|
119
|
+
parsed.profile = sanitizeInlinePathsDeep(parsed.profile);
|
|
120
|
+
}
|
|
109
121
|
return ok(parsed);
|
|
110
122
|
}
|
|
111
123
|
//# sourceMappingURL=_shared.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../src/tools/evaluation/_shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,
|
|
1
|
+
{"version":3,"file":"_shared.js","sourceRoot":"","sources":["../../../src/tools/evaluation/_shared.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,YAAY,EACZ,aAAa,GACd,MAAM,2BAA2B,CAAC;AAGnC,oEAAoE;AACpE,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,oDAAoD,CAAC;IACvF,MA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AU,EAAE,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,aAAa,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CACjE;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,UAAU,GAAG,MAAM,CAAC;IAC1B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;CAC5B;AAqVD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAiOjF"}
|
|
@@ -398,14 +398,16 @@ export function registerRegoTestMultiroot(server, config) {
|
|
|
398
398
|
break;
|
|
399
399
|
}
|
|
400
400
|
// Systemic failures (binary missing, timeout) abort the entire run.
|
|
401
|
+
// Check the timeout first: a killed process also reports a null exit
|
|
402
|
+
// code, so the other order reports a slow run as a missing binary.
|
|
403
|
+
if (result.timedOut) {
|
|
404
|
+
return err('TIMEOUT', 'opa subprocess exceeded the configured timeout (OPA_MCP_TIMEOUT_MS).', { details: { durationMs: result.durationMs } });
|
|
405
|
+
}
|
|
401
406
|
if (result.exitCode === null) {
|
|
402
407
|
return err('OPA_BINARY_NOT_FOUND', `opa binary unreachable: ${result.stderr || 'spawn failed'}`, {
|
|
403
408
|
hint: 'Install OPA (https://www.openpolicyagent.org/docs/latest/) or set OPA_BINARY to the absolute path of the binary.',
|
|
404
409
|
});
|
|
405
410
|
}
|
|
406
|
-
if (result.timedOut) {
|
|
407
|
-
return err('TIMEOUT', 'opa subprocess exceeded the configured timeout (OPA_MCP_TIMEOUT_MS).', { details: { durationMs: result.durationMs } });
|
|
408
|
-
}
|
|
409
411
|
const outcome = processRootOutput(result, coverageMode, threshold);
|
|
410
412
|
const rootResult = {
|
|
411
413
|
path: root.path,
|