- Define specific requirements for each environment (e.g, dev, staging, prod)
- Enforce consistent compliance standards across your deployment pipeline
- Prevent non-compliant artifacts from being deployed (via admission controllers)
Create a Policy
You can create a policy via CLI or via the API. Here is a basic policy that requires provenance and specific attestations:prod-policy.yaml
Once you create a policy, you will be able to see it in the UI under
policies in the left navigation menu.Declarative Policy Syntax
A Policy is declaratively defined according to the following schema:Policy Rules
A policy consists ofrules which are applied to artifacts in an environment snapshot.
Provenance
Whenprovenance is set to required: true, the artifact must be part of a Kosli Flow (i.e., it must have
provenance information).
Trail Compliance
Whentrail-compliance is set to required: true, the artifact must be part of a compliant Trail in its Flow.
Specific Attestations
Policy Rules Exceptions
You can add exceptions to policy rules using expressions.Policy Expressions
Policy expressions allow you to create conditional rules using a simple and powerful syntax. Expressions are wrapped in${{ }} and can be used in policy rules to create dynamic conditions. An expression consists of operands
and operators:
Operators
Operators
Expressions support these operators:
- Comparison:
==, !=, <, >, <=, >= - Logical:
and, or, not - List membership:
in
Operands
Operands
Operands can be:
- Literal string
- List
- Context variable
- Function call
Available Contexts
Available Contexts
Contexts are built-in objects which are accessible from an expression. Expressions can access two main contexts:
flow- Information about the Kosli Flow:flow.name- Name of the flowflow.tags- Flow tags (accessed via flow.tags.tag_name)
artifact- Information about the artifact:artifact.name- Name of the artifactartifact.fingerprint- SHA256 fingerprint
Functions
Functions
Functions are helpers that can be used when constructing conditions. They may or may not accept arguments. Arguments
can be literals or context variables. Expressions can use following functions:
exists(arg): checks whether the value of arg is not None/Nullmatches(input, regex): checks if input matches regex
Example Expressions
Example Expressions
${{ exists(flow) }}${{ flow.name in ["runner", 'saver', differ] }}${{ matches(artifact.name, "^datadog:.*") }}${{ flow.name == "runner" and matches(artifact.name, "^runner:.*") }}${{ flow.tags.risk-level == "high" or matches(artifact.name, "^runner:.*") }}${{ not flow.tags.risk-level == "high"}}${{ flow.tags.risk-level != "high"}}${{ flow.tags.key.with.dots == "value"}}${{ flow.tags.risk-level >= 2 }}${{ flow.name == 'prod' and (flow.tags.key_name == "value" or artifact.name == 'critical-service') }}${{ flow.name == 'HIGH-RISK' and artifact.fingerprint == "37193ba1f3da2581e93ff1a9bba523241a7982a6c01dd311494b0aff6d349462" }}
Attaching/Detaching Policies to/from Environments
Once you define your policies, you can attach them to environments via CLI or API:If you detach all attached policies from an environment, the environment compliance state will become Unknown since there are no longer any defined requirements for artifacts running in it. The environment will continue to
track snapshots, but its compliance cannot be evaluated without policies.
Policy Enforcement Gates
Environment policies enable you to proactively block deploying a non-compliant artifact into an environment. This can be done as a deployment gate in your delivery pipeline or as an admission controller in your environment. Regardless of where you place your policy enforcement gate, it will be using theassert artifact Kosli CLI command
or its equivalent API call.