Kumoss

Compliance policy

The contract of the Rego compliance policies: how and where they run, the general and provider policies, their input and decision, how their findings are reported, when they fail, and the shipped rules.

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

general/policies/compliance

kumoss.compliance

On every generate round. It must exist.

<provider>/policies/compliance

kumoss.providers.<provider>

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:

  1. 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 declaring random gets no random policy, and no error. Nothing is cached, so a label moved in Langfuse applies to the next round.

  2. 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 opa process (OPA 1.22.4, shipped in the core image) that queries data.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
  3. It reads each policy’s decision: blocking deny findings, non-blocking warn findings, and the list of rules checked.

  4. 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.

  5. If either part has an error or critical finding, 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

input.plan

The final plan’s terraform show -json or tofu show -json document, unchanged. Rules usually walk input.plan.resource_changes.

input.kumoss.schema

kumoss.compliance.input/v1. Changes if the shape of input ever does.

input.kumoss.providers

The provider type names of the root module’s required_providers (azurerm for hashicorp/azurerm): the providers whose policies are evaluated. The general policy can use it to scope a rule to the providers a module actually uses; see Root module manifest.

Three properties of the plan limit what a rule can check:

  • It is a -target plan: it holds the session’s targets only, so a rule cannot see resources outside them.

  • Values known only after apply are absent from after and listed in after_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

deny

set of {rule_id, message, resource?, severity?}

Blocking findings. severity is error (the default) or critical.

warn

set of {rule_id, message, resource?}

Non-blocking findings, reported with severity warning.

rules

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 no source, 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_revisions lists 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 single policy_revision string; they are read into the list.

  • passed is false when either source has an error or critical finding, and the session is then locked as for any failed compliance check. When the policies are what blocks, the summary starts with Blocked 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.compliance for the general policy, package kumoss.providers.<provider> for a provider’s), or the package is not an object.

  • deny, warn, or rules is not a set; a finding is not an object or lacks rule_id or message; or a deny severity is neither error nor critical.

  • A builtin error. The policies run with --strict-builtin-errors, so to_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.

  • opa could 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

critical_deletion

deny, critical

A managed resource whose plan actions are exactly ["delete"], even when the user requested the deletion. A replacement (["delete", "create"] or ["create", "delete"]), a forget (a removed block with destroy = false) and data sources are allowed.

customer_managed_key_removed

deny, error

A resource the plan updates or replaces that loses its customer-managed encryption key: an attribute named kms_key_id, kms_key_arn, kms_master_key_id, kms_key_name, kms_key_self_link, default_kms_key_name, customer_managed_key, disk_encryption_set_id or key_vault_key_id, at any nesting depth, is set before the change and empty or absent after it. Switching to another key is allowed, and a key whose new value is only known at apply time is not judged.

command_execution

deny, error

Terraform running commands: a null_resource, or a provisioner of any kind (local-exec, remote-exec, file) on a resource the plan creates or updates, child modules included; and any data "external" data source anywhere in the configuration, changed or not, since it runs its program on every plan. A resource with a provisioner that the round leaves untouched is not flagged.

unprotected_credential_output

warn

A root module output the plan creates or updates whose name contains, case-insensitively, password, passwd, secret, token, private_key, api_key, access_key, credential or connection_string, and that is not marked sensitive = true. The name is only a hint, hence a warning; the message carries the output’s name, never its value.

provider_version_pin

warn

A root module provider (an entry of the plan’s configuration.provider_config without module_address; the built-in terraform.io/builtin/* providers are skipped) with no version constraint, or one that is not of the form ~> X.Y: an exact pin such as = 4.63.0 (which the plan shows as 4.63.0), an open range such as >= 5.0, or ~> 6.1.0. The finding has no resource; the message carries the provider’s full name. A warning, since an existing pin is never changed as a side effect and a workspace may keep one on purpose; child modules pin for themselves.

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

aws

aws_public_ingress

Security group ingress (inline, aws_security_group_rule or aws_vpc_security_group_ingress_rule) from 0.0.0.0/0 or ::/0 on anything but TCP 80 or 443. ICMP is exempt.

aws_iam_wildcard_admin

An IAM policy statement allowing Action "" on Resource "", including the inline policies of a role.

aws_s3_public_access

A public-read or public-read-write bucket ACL, or any S3 Block Public Access flag set to false, at bucket or account level.

azurerm

azurerm_public_inbound

A network security group inbound Allow rule from *, Internet, 0.0.0.0/0 or ::/0 on anything but TCP 80 or 443. ICMP is exempt.

azurerm_subscription_owner

Owner or Contributor assigned at subscription, management group or root scope.

azurerm_host_command

The CustomScript extension on a virtual machine or scale set, or an azurerm_virtual_machine_run_command.

google

google_public_ingress

An ingress firewall rule or firewall policy rule from 0.0.0.0/0 or ::/0 on anything but TCP 80 or 443; a rule without ports opens every port. ICMP is exempt.

google_sa_key

A google_service_account_key.

google_basic_role_to_sa

roles/owner, roles/editor or roles/viewer granted to a serviceAccount: member through any google_*iam_member or google*_iam_binding.

kubernetes

k8s_privilege_escalation

allow_privilege_escalation = true in any security context.

k8s_runtime_socket

A hostPath volume on the container runtime socket or a directory exposing it: /, /run, /var/run, and the Docker, containerd and CRI-O sockets and directories.

k8s_cluster_admin_sa

cluster-admin bound to a ServiceAccount.

oci

oci_public_ingress

Ingress from 0.0.0.0/0 or ::/0 on anything but TCP 80 or 443, in a security list (oci_core_security_list), a VCN’s default security list (oci_core_default_security_list) or a network security group rule. ICMP is exempt.

oci_bastion_open

A bastion whose client_cidr_block_allow_list contains 0.0.0.0/0 or ::/0.

oci_any_user_no_condition

An Allow any-user policy statement without a request.principal condition.

vsphere

vsphere_host_management

Host-level resources: vsphere_host*, vsphere_vnic, vsphere_license.

vsphere_unverified_ssl

A vsphere provider block with allow_unverified_ssl = true written as a literal.

vsphere_snapshot

A vsphere_virtual_machine_snapshot.

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.