.rego file to kosli evaluate trail or kosli evaluate trails via the --policy flag. Kosli has a built-in evaluator — no OPA installation required.
Policy contract
These rules are Kosli-specific conventions, not OPA built-ins. Kosli queriesdata.policy.* to find them.
Every policy must declare
package policy. Kosli queries data.policy.allow and data.policy.violations to read the result.Must evaluate to a boolean. Kosli exits with code
0 when true, code 1 when false. Typically defined as:Optional but recommended. A set of human-readable strings describing why the policy failed. Kosli displays these when
allow is false. Each message should identify the offending resource and the reason.Input data
The data structure passed to the policy asinput depends on which command you use.
kosli evaluate trail — single trail
The policy receives input.trail, a single trail object.
The trail being evaluated.
kosli evaluate trails — multiple trails
The policy receives input.trails, an array of trail objects with the same structure as input.trail above.
Array of trail objects. Each element has the same structure as
input.trail described above.Use
--show-input with --output json to print the full input structure for a given trail. Pipe through jq to explore specific fields:Exit codes
| Code | Meaning |
|---|---|
0 | Policy allowed (allow = true) |
1 | Policy denied (allow = false) or command error (network failure, invalid Rego, policy file not found) |
1 is used for both denial and failure. To distinguish between them in CI, use --output json and read the allow field directly from the output rather than relying on the exit code.
Examples
Check pull request approvals across multiple trails
Check Snyk scan results on a single trail
Further reading
- Rego Style Guide — naming, rule structure, and test conventions
- OPA Annotations — including
entrypoint: truefor use withopa build - OPA Best Practices
- Tutorial: Evaluate trails with OPA policies