kosli create policy to create or update a policy. For concepts, workflow, and enforcement, see Environment Policies.
Specification
Version identifier and JSON Schema URL for the policy format. The final path segment must match
/v{n} where n is a supported major version. Currently only v1 is supported.Rules applied to artifacts in an environment snapshot. Omitted keys use server defaults.
Attestation types
| Value | Description |
|---|---|
generic | Generic attestation |
junit | JUnit test results |
snyk | Snyk security scan |
pull_request | Pull request evidence |
jira | Jira ticket reference |
sonar | SonarQube analysis |
* | Matches any built-in or custom type |
custom:<name> | A custom attestation type (e.g., custom:coverage-metrics) |
Policy expressions
Expressions are boolean conditions evaluated against flow and artifact context. They are wrapped in${{ }} and can appear in if and exceptions[].if fields.
Operators
| Operator | Category | Example |
|---|---|---|
== | Comparison | flow.name == "runner" |
!= | Comparison | flow.tags.risk-level != "high" |
< | Comparison | flow.tags.priority < 3 |
> | Comparison | flow.tags.priority > 1 |
<= | Comparison | flow.tags.risk-level <= 2 |
>= | Comparison | flow.tags.risk-level >= 2 |
and | Logical | flow.name == "a" and artifact.name == "b" |
or | Logical | flow.name == "a" or flow.name == "b" |
not | Logical | not flow.tags.risk-level == "high" |
in | Membership | flow.name in ["runner", "saver"] |
${{ flow.name == 'prod' and (flow.tags.team == "a" or artifact.name == 'svc') }}.
Contexts
Information about the Kosli flow the artifact belongs to.
Information about the artifact being evaluated.
Functions
| Function | Description | Example |
|---|---|---|
exists(arg) | Returns true if arg is not null. | ${{ exists(flow) }} |
matches(input, regex) | Returns true if input matches the regular expression. | ${{ matches(artifact.name, "^datadog:.*") }} |
Constraints
_schemais the only required field. All other fields are optional and use server defaults when omitted.- An attestation rule must not have both
nameandtypeset to*. - Expressions must evaluate to a boolean. An invalid expression causes a policy evaluation error.
Example
Editor validation
The_schema URL resolves to a JSON Schema for the environment policy format. To enable inline validation and autocomplete in VS Code (requires the YAML extension) and other schema-aware editors, add a yaml-language-server directive:
See also
- Environment Policies — concepts, workflow, and enforcement
kosli create policy— create or update a policykosli attach-policy— attach a policy to an environmentkosli assert artifact— enforce policies on an artifact- Terraform: kosli_policy — manage policies via Terraform