Files
git.stella-ops.org/docs/60_POLICY_TEMPLATES.md
2025-08-30 21:05:34 +00:00

2.3 KiB
Executable File
Raw Permalink Blame History

Policy Templates — YAML & Rego Examples

StellaOps lets you enforce pass / fail rules in two ways:

  1. YAML “quick policies” — simple equality / inequality checks.
  2. OPA Rego modules — fullpower logic for complex organisations.

Precedence: If the same image is subject to both a YAML rule and a Rego module, the Rego result wins. That is, deny in Rego overrides any allow in YAML.


1·YAML quick policy

# file: policies/root_user.yaml
version: 1
id: root-user
description: Disallow images that run as root
severity: high

rules:
  - field: ".config.user"
    operator: "equals"
    value: "root"
    deny_message: "Image runs as root — block."

Place the file under /opt/stella/plugins/policies/.


2·Rego example (deny on critical CVE)

# file: policies/deny_critical.rego
package stella.policy

default deny = []

deny[msg] {
  some f
  input.findings[f].severity == "critical"
  msg := sprintf("Critical CVE %s  build blocked", [input.findings[f].id])
}

Input schema — the Rego input document matches the public ScanResult POCO (see SDK). Use the bundled JSON schema in share/schemas/scanresult.schema.json for IDE autocompletion.


3·Passthrough warnings (Rego)

Return a warn array to surface nonblocking messages in the UI:

package stella.policy

warn[msg] {
  input.image.base == "ubuntu:16.04"
  msg := "Image uses EOL Ubuntu 16.04 — please upgrade."
}

Warnings decrement the quality score but do not affect the CLI exit code.


4·Testing policies locally

# run policy evaluation without pushing to DB
stella scan alpine:3.20 --policy-only \
  --policies ./policies/

The CLI prints PASS, WARN or DENY plus structured JSON.

Unittest your Rego modules with the OPA binary:

opa test policies/

5·Developer quickstart (plugins)

Need logic beyond Rego? Implement a plugin via C#/.NET {{ dotnet }} and the StellaOps.SDK NuGet:


Last updated {{ "now" | date: "%Y%m%d" }} — constants autoinjected.