validation

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package validation checks Chainsaw YAML without executing assertions.

Index

Constants

View Source
const (
	TestAPIGroup = "chainsaw.kyverno.io"
	TestKind     = "Test"
)

TestAPIGroup and TestKind identify the Chainsaw Test type. Detection matches the API group and ignores the version, so a future chainsaw API version still dispatches to the allowlist-guarded path.

Variables

This section is empty.

Functions

func IsChainsawTest

func IsChainsawTest(raw string) bool

IsChainsawTest returns true if any document in the YAML stream is a Chainsaw Test (apiVersion group chainsaw.kyverno.io, kind Test). Exported so the deployment validator can partition Test-format asserts (which dispatch to the in-process executor with allowlist enforcement) from raw K8s resource YAML (which uses the Go assertion library directly). Originally added in PR #1231 to gate the binary-shipping path; retained in #1236 because the dispatch split is still useful — Test-format content runs through the read-only allowlist guard before evaluation; raw K8s YAML bypasses that guard (it has no operations to gate).

Detection parses each document's apiVersion/kind rather than scanning for substrings (#2040). The substring form failed in both directions: a quoted `kind: "Test"` was not recognized, and raw K8s YAML that merely mentioned both strings — in a comment, an annotation, or ConfigMap data — was dispatched as a Test, unmarshaling to zero steps and passing without evaluating anything.

Any document matching is enough: a stream that carries a Test must reach the allowlist guard regardless of which document it sits in. Undecodable content reports false and surfaces its parse error on the raw path, which reports document context.

func ValidateTestReadOnly

func ValidateTestReadOnly(component, yamlContent string) error

ValidateTestReadOnly parses chainsaw Test YAML content (possibly multi-document) and rejects any operation other than `assert` or `error`. Used at runtime to bound the blast radius of registry-declared health checks: the deployment validator Job runs under a ServiceAccount bound to cluster-admin (pkg/validator/job/rbac.go:41-67), so registry content must not be able to invoke state-changing chainsaw operations (apply, create, delete, patch, update) or side-effecting collectors (script, command, wait, sleep, podLogs, events, describe, get, proxy).

Multi-document support: a single `---`-separated stream may carry more than one Test; each is unmarshaled and validated independently. Empty documents and non-Test documents (different apiVersion/kind) are skipped. Per PR #1235 review.

Both per-step (`spec.steps[].try/catch/finally/cleanup`) and top-level (`spec.catch`) operation lists are validated.

Caller contract: invoke only on content that IsChainsawTest reports as Test format. Raw K8s YAML asserts have no operations and are unaffected.

Returns ErrCodeInvalidRequest naming the offending document index + step + operation so the operator can pinpoint the registry entry that violated the allowlist. PR #1223 will surface the same rule at lint time so violations are caught before they ever reach the validator.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL