The compliance policies are the deterministic part of Kumoss’s
compliance check: Rego
modules that Open Policy Agent (OPA)
evaluates against the plan of every generate round. No language model is
involved, so the same plan always gets the same verdict. A deny
finding locks the session.
Two kinds of policy run together:
| Prompt | Package | Evaluated |
|---|---|---|
|
|
On every generate round. It must exist. |
|
|
On the rounds whose root module declares that provider. A provider without one is skipped. |
<provider> is the Terraform provider type name, as in the other
provider prompts: aws, azurerm, google, kubernetes, oci,
vsphere. A type name containing - is not a valid Rego identifier,
so its package uses the bracket form, for example package
kumoss.providers["google-beta"]. Every policy gets the same
input and returns the same decision.
This page is the contract a policy follows. To add a rule step by step, see Write a policy rule. For how the policies relate to the other checks that can lock a session, see How compliance works.
How the policies run
At the end of every generate round, when
orchestration.enable_compliance_checker is true:
-
The core fetches the general policy and the policy of every provider the root module declares in
required_providers(the session’s providers), each from the version that carries your environment’s label in Langfuse. A provider whose policy prompt does not exist, or has no version with that label, is left out: a module declaringrandomgets norandompolicy, and no error. Nothing is cached, so a label moved in Langfuse applies to the next round. -
It builds the input document from the round’s final plan and the root module’s providers, and runs all the fetched policies in one
opaprocess (OPA 1.22.4, shipped in the core image) that queriesdata.kumoss, so the general package and every provider package are read from a single result:opa eval --stdin-input --strict-builtin-errors --format json \ --data general.rego --data aws.rego ... data.kumoss -
It reads each policy’s decision: blocking
denyfindings, non-blockingwarnfindings, and the list of rules checked. -
The intent check, the language-model half, runs next, and both results are merged into one compliance report for the round; see How findings appear in the report.
-
If either part has an
errororcriticalfinding, the session is locked and the compliance failure notification is sent.
Errors name the prompt and the line they come from, for example
aws/policies/compliance:12: ….
Every policy sees the whole plan, not only its provider’s resources: a module may use several providers. A provider policy’s rules therefore match on their own resource `type`s.
Drift and import rounds are never checked.
Where the policies live
Each policy is a Langfuse text prompt, seeded from
core/prompts/seed/<scope>/policies/compliance.rego: the general
policy from general/, and one policy each for aws, azurerm,
google, kubernetes, oci, and vsphere. To give another provider
a policy, create its <provider>/policies/compliance prompt in
Langfuse. The core uses the raw text of the version: Langfuse’s
{{variable}} templating is not applied, so the braces of Rego are
safe. A version you customized is never overwritten by a Kumoss
upgrade. How versions, labels, and seeding work is in
How seeding
works.
Input
The document every policy receives as input:
{
"plan": { ... },
"kumoss": {
"schema": "kumoss.compliance.input/v1",
"providers": ["azurerm", "kubernetes"]
}
}
| Field | Content |
|---|---|
|
The final plan’s |
|
|
|
The provider type names of the root module’s |
Three properties of the plan limit what a rule can check:
-
It is a
-targetplan: it holds the session’s targets only, so a rule cannot see resources outside them. -
Values known only after apply are absent from
afterand listed inafter_unknown. -
It carries sensitive values unmasked. Never put a value that can hold a secret (passwords, keys, tokens, connection strings, user data, policy or script bodies) in a finding’s
message, which ends up in the compliance report, the session’s artifacts, and the notification; name the resource address and the attribute instead. Addresses, CIDR blocks, ports, protocols, and paths, which the shipped rules quote, are fine.
Decision
Each policy’s package, data.kumoss.compliance or
data.kumoss.providers.<provider>, is read with the same contract, so
the general module must declare package kumoss.compliance and a
provider’s package kumoss.providers.<provider>. All keys are
optional; a missing one counts as empty, and keys outside these three
are ignored.
| Key | Type | Meaning |
|---|---|---|
|
set of |
Blocking findings. |
|
set of |
Non-blocking findings, reported with severity |
|
set of strings |
Every rule id the policy evaluates, so the report lists the rules that passed too. Rule ids of findings are added to it anyway. |
rule_id and message are non-empty strings; resource, when
present, is a string, usually the resource address.
How findings appear in the report
The policies' decisions and the intent check’s findings are merged into one compliance report per round; only this merge produces the verdict:
-
Each policy violation carries
source: "opa"; findings of the intent check carry"intent". Reports stored with the former value"llm", or before the policy existed with nosource, load as intent findings. The web application marks policy findings with a policy badge and intent check findings with an intent badge, in the Compliance Check artifact and in the Why list of the Deployment Blocked screen. -
The policies' findings come first.
-
policy_revisionslists the versions that ran, each as"<prompt name>@<version>", the general policy first, for example["general/policies/compliance@3", "aws/policies/compliance@1"], or is empty when no policy ran. Reports stored when there was only the general policy carry a singlepolicy_revisionstring; they are read into the list. -
passedisfalsewhen either source has anerrororcriticalfinding, and the session is then locked as for any failed compliance check. When the policies are what blocks, the summary starts withBlocked by the compliance policy: N finding(s) (<rule ids>).
When a policy cannot be evaluated
The policies fail closed. If one cannot be evaluated, the round gets a
blocking policy_unavailable finding (severity error) whose message
gives the reason, so the session is locked and the compliance failure
notification is sent. The intent check still runs, and its findings
are in the same report.
Since all the policies run in one evaluation, one broken provider policy blocks every round of a module that declares that provider, and a broken general policy blocks every round.
Problems in a policy
Fix these in a new version of the policy:
-
A syntax or compile error in any of the policies.
-
A fetched policy does not define its package (
package kumoss.compliancefor the general policy,package kumoss.providers.<provider>for a provider’s), or the package is not an object. -
deny,warn, orrulesis not a set; a finding is not an object or lacksrule_idormessage; or adenyseverity is neithererrornorcritical. -
A builtin error. The policies run with
--strict-builtin-errors, soto_number("x")fails rather than being undefined. -
The evaluation did not finish within 30 seconds.
Problems around the policy
These need your operator:
-
A policy could not be fetched from Langfuse: Langfuse is unreachable, the version carrying the environment label is not a single text prompt, or, for the general policy only, the prompt or such a version does not exist.
-
The plan JSON could not be read.
-
opacould not be run.
Startup check
When enable_compliance_checker is true, the core, after seeding the
prompts, evaluates the general policy and the policy of every provider
that ships a seed (aws, azurerm, google, kubernetes, oci,
vsphere) against an empty plan, and refuses to start if that fails: a
missing opa binary, a broken policy, or Langfuse unreachable. A
provider policy missing from Langfuse is skipped there too. A broken
version that gets the environment label while the core is running is
caught only when it is evaluated, and then blocks every round it
applies to.
The shipped rules
General policy
The general seed defines five rules that apply whatever the provider.
critical_deletion looks at every managed resource and
provider_version_pin at the root module’s provider configuration; the
other three look only at what the plan creates or updates (a
replacement included), so a resource the round leaves alone is not
judged.
| Rule id | Decision | Finds |
|---|---|---|
|
|
A managed resource whose plan actions are exactly |
|
|
A resource the plan updates or replaces that loses its
customer-managed encryption key: an attribute named |
|
|
Terraform running commands: a |
|
|
A root module output the plan creates or updates whose name contains,
case-insensitively, |
|
|
A root module provider (an entry of the plan’s
|
critical_deletion, the rule a custom policy most often starts from:
package kumoss.compliance
rules contains "critical_deletion"
deny contains finding if {
some change in input.plan.resource_changes
change.mode == "managed"
change.change.actions == ["delete"]
finding := {
"rule_id": "critical_deletion",
"severity": "critical",
"resource": change.address,
"message": sprintf(
"%s is destroyed without being recreated; standalone deletions are never allowed, even when requested.",
[change.address],
),
}
}
The seed declares its five ids in one rules contains rule if some rule
in {…} statement; the excerpt above declares only its own. The code
is explained line by line in
How a rule
works.
data "external" runs its program while the plan is made, so by the
time command_execution locks the round the program has already run
in the IaC sidecar; the rule keeps the code from being applied and
merged. Provisioners and null_resource commands run at apply and are
stopped before they run.
Some safeguards of the former prompts are not in the general policy.
Removing lifecycle.prevent_destroy cannot be detected: the plan JSON
does not contain lifecycle blocks. Turning off deletion protection
and replacing a stateful resource are visible in the plan, but the
prompts allowed them on an explicit request, so they were not
translated (see below).
Provider policies
No prompt lists forbidden actions any more. The provider seeds
translate the most critical rules of the removed forbidden_actions
prompts that can be decided from the plan alone. Each has three rules,
all deny with the default severity error, with ids prefixed by the
provider (k8s_ for Kubernetes). They check only resources the plan
creates or updates, and only values known at plan time;
vsphere_unverified_ssl reads the plan’s provider configuration
instead.
| Provider | Rule id | Denies |
|---|---|---|
|
|
Security group ingress (inline, |
|
An IAM policy statement allowing |
|
|
A |
|
|
|
A network security group inbound |
|
Owner or Contributor assigned at subscription, management group or root scope. |
|
|
The CustomScript extension on a virtual machine or scale set, or an
|
|
|
|
An ingress firewall rule or firewall policy rule from |
|
A |
|
|
|
|
|
|
|
|
A |
|
|
|
|
|
|
Ingress from |
|
A bastion whose |
|
|
An |
|
|
|
Host-level resources: |
|
A |
|
|
A |
Rules of the removed prompts that allowed an exception on an explicit
user request were not translated: a policy sees the plan, not the
request. Write such rules as warn rules, so a reviewer sees them
without the session being locked, or leave them to review.
Write your own rules
Further prohibitions (no public storage, no owner role assignments,
allowed regions, mandatory tags…) are written as rules in the policy
of the provider they concern, or in the general policy when they span
providers, each adding its id to rules. To give a provider without a
seed a policy, create its <provider>/policies/compliance prompt in
Langfuse with package kumoss.providers.<provider>. See Write a policy rule.
Testing commands
All commands use the OPA image at the version the core ships. With OPA
1.22.4 installed locally, run opa with the same arguments instead.
Run the shipped rules' tests, from the core directory (the shell
expands the glob, so run it there):
docker run --rm -v "$PWD:/core:ro" -w /core \
openpolicyagent/opa:1.22.4-static \
test prompts/seed/*/policies tests/policies
The tests are in core/tests/policies, one <scope>_test.rego per
policy. The general policy’s fixtures are real Terraform 1.16 and
OpenTofu 1.13 plans, fixtures/<engine>/data.json, and a Terraform
plan exercising its command and output rules,
fixtures/general/data.json; the AWS, Google, and Kubernetes rules are
tested against real terraform plan output,
fixtures/<provider>/data.json. opa test loads each as
data.fixtures.<directory>.
Check that policies compile, from the folder that holds them, passing the general policy together with the provider policies a round would run:
docker run --rm -v "$PWD:/w:ro" -w /w \
openpolicyagent/opa:1.22.4-static check general.rego aws.rego
Evaluate the policies against an input document, as the core does:
docker run --rm -i -v "$PWD:/w:ro" -w /w openpolicyagent/opa:1.22.4-static \
eval --stdin-input --strict-builtin-errors --format pretty \
-d general.rego -d aws.rego data.kumoss < input.json
How to build input.json from a plan is shown in
Write a policy rule.
Related pages
-
Write a policy rule to add a rule, test it, and publish it.
-
Prompt registry for how the policies are seeded, versioned, and labeled in Langfuse.
-
Resolve a locked session for what users see when a policy denies a plan.
-
Configuration for
orchestration.enable_compliance_checker.