A written policy such as "no critical vulnerabilities in production" depends on people to apply it consistently. Policy as code turns it into something a program evaluates: a rule, stored in version control, that takes facts as input (the findings of a scan, a Kubernetes manifest, a cloud resource, a request) and returns a decision such as allow, warn or deny. Some systems use a general-purpose policy language, such as Rego for Open Policy Agent or CEL in Kubernetes; others use declarative rule structures with a fixed set of conditions. Either way, the policy can be reviewed in a pull request, tested against examples, rolled out gradually and rolled back.
How it is used in practice
Policy as code shows up wherever a decision should be automatic and explainable. CI pipelines ask whether a build's scan results satisfy policy before publishing an artifact. Admission controllers evaluate a workload before a cluster runs it. IaC scanners apply rule catalogs to Terraform and manifests. Access systems evaluate requests against authorization policies. In each case, the useful output is not just the decision but the reasoning: which rule matched which fact. Teams usually introduce a new rule in a non-blocking mode first, observe what it would have refused, and only then enforce it.
Common pitfalls
- Policy the pipeline can rewrite. If the credential that asks for a decision can also change the rules, the build grades its own homework.
- Opaque decisions. A bare "fail" with no record of which rule and which finding caused it gets bypassed, not fixed.
- Non-reproducible results. If evaluating the same inputs twice can give different answers, an audit cannot reconstruct why something shipped.
- Arbitrary code in policies. A policy language that can make network calls or run customer-supplied code is itself an attack surface.
- Enforcing on day one. A new rule that blocks immediately breaks pipelines before its authors have read its results.
How TrustIvan relates to it
TrustIvan's AppSec policies are declarative and versioned. A rule is a set of conditions on severity, finding kind, lifecycle status, fixability, advisory identifier, age and match count, with exactly one effect: fail, warn or ignore. A separate signed_by rule refuses a container image not signed by one of the public keys it lists. There is no expression language and no customer code to evaluate. Evaluating a policy against a scan produces a recorded, immutable verdict with its reasoning, and a repeated request replays it rather than recomputing. Policies are written by people in the dashboard or API; policies:manage cannot be granted to an API key, so a pipeline can request verdicts but cannot change the rules it is judged by. A new policy starts disabled. See Policies and verdicts.
Related terms
- Admission control (Kubernetes) Admission control is the stage of the Kubernetes API server that intercepts a request to create or change an object, after authentication and authorization, and can accept, modify or reject it before it is stored.
- Shift left Shift left is the practice of moving security checks earlier in the software delivery process, into design, coding, pull requests and CI, so that problems are found when they are cheapest and quickest to fix.
- IaC scanning (infrastructure-as-code scanning) Infrastructure-as-code (IaC) scanning analyzes the files that define infrastructure, such as Terraform, CloudFormation, Kubernetes manifests, Helm charts and Dockerfiles, for insecure configuration before it is deployed.
- Remediation SLA A remediation SLA (service-level agreement, or target) is the maximum time an organization allows between discovering a vulnerability and fixing it, usually set per severity level and measured per finding.
- Vulnerability management lifecycle The vulnerability management lifecycle is the repeating process of discovering vulnerabilities, assessing and prioritizing them, remediating or accepting them, and verifying the result, with each decision recorded.
Guides on Policy as code
- Container Vulnerability Management: From Scan to Verdict How container vulnerability management works end to end: a finding identity that survives rescans, a lifecycle, and a policy verdict a pipeline can act on.
- Policy as Code for Release Gates: Fail Builds on What Matters A release gate that fails on every critical gets switched off. Write a policy that blocks exploited, fixable risk, warns on the rest and explains itself.
On the platform: Policy engine. All glossary terms