tfui latest

Embed Rego for project risk policies

Use Open Policy Agent (OPA), embedded through its Go evaluation API, to evaluate project risk policies written in Rego. HCL selects a local policy source; it does not define a second tfui-specific rule language. A member’s selected policy replaces its parent’s complete policy; tfui does not implicitly combine ancestor rules. Ship explicit policy templates rather than runtime named presets. The repository owner accepted this language and runtime decision on 2026-11-14. Plan, Risk and tfui risk evaluate the selected policy with OPA embedded (#121).

The decision covers Risk analysis and tfui risk. It does not add a gate to tfui apply, change confirmation, or change auto-approval behavior. Evaluation uses structured data from the same Terraform plan being reviewed. Evaluation failures and invalid policy results must be reported as errors, not passing assessments.

The current classifier in internal/terraform/risk.go uses action and resource type. Its proposed replacement configuration would make tfui maintain a growing matching language, including operators, precedence, diagnostics and policy tests. Rego provides a policy language and test tooling; tfui remains responsible for the plan input and risk result contracts. CEL was the strongest alternative, but would leave the surrounding policy format, ordering and test conventions with tfui. OPA integration, policy testing.

Field report #106 supplies an attribute-aware example: changing a Lambda package path can overwrite code deployed by another pipeline. The current AWS provider’s needsFunctionCodeUpdate includes filename; its update path reads the file and calls UpdateFunctionCode. This supports a reason naming the code-source attribute, even with an unchanged hash. An unchanged or null hash does not by itself establish that the package is a placeholder or that its lifecycle ignores the hash. The report justifies attribute-aware input, not OPA uniquely. Provider implementation, inspected 2026-11-14; the report does not identify a provider version for reproduction.

The full analysis is in the risk policy architecture. The contract reference owns accepted definitions. ADR-0025 subsequently narrows evaluation to independent resource mutations with explicit results and no custom-policy fallback.

Consequences

  • Users write Rego; maintainers own the embedded OPA dependency and its upgrades. Evaluation requires no separate OPA command or daemon. Local evaluation is the initial runtime; remote policy distribution is not part of this decision.
  • Preserve structured plan values and unknown/sensitive metadata from the existing live or seeded acquisition path. PlanSummary’s display-string diffs are not a sufficient policy input. Do not run a second plan to acquire policy data.
  • Keep evaluator dependencies in app internals behind SDK-facing domain types. Plan and Risk use the same validated classifications and reasons; plugins do not import each other or OPA implementation details.
  • Source selection is whole-policy replacement. Switching member/workspace must resolve the applicable source and invalidate previous assessments; startup-only configuration is insufficient.
  • Rego’s declarative semantics do not inherit the earlier proposed first-match-wins behavior: a policy returns one complete result document, and conflicting results fail (contract).
  • Policy authors are trusted and local. Embedded OPA is not a sandbox for hostile code: tfui masks sensitive values before evaluation and exposes only an allowlist of builtins, and cancellation is cooperative, with no hard memory or time limit (runtime and trust boundary).
  • Use the Lambda case as an attribute-aware policy fixture and template candidate. Do not automatically lower non-code Lambda changes or assert external deployment ownership from hash equality alone.
  • Embedding OPA adds 15.0–16.2MiB to the release binary and about 13 seconds to a cold build, measured with a small policy on Linux/amd64 before #121 (D-03c). These costs are accepted as measured, not set as budgets; growth the maintainers find unacceptable reopens this decision.

Considered Options

Keep fixed classification and add a Lambda rule

The smallest fix for #106. Rejected as the project-policy solution because each new policy requires a tfui code release. It remains a possible independently scoped fix; this record does not require the issue to wait for the entire policy integration.

Define matching rules in HCL, YAML or JSON

Readable for a small lookup table. Rejected because changing serialization does not remove ownership of a custom policy language, diagnostics and tests.

Embed CEL expressions

A credible fit for per-change conditions with familiar expression syntax. Rejected in favor of Rego’s policy authoring and testing model; tfui would still own CEL’s surrounding rule document, ordering and testing conventions. CEL.

Invoke OPA or Conftest externally

Lets organizations manage their evaluator independently. Rejected for the initial integration because it adds runtime installation, version and process-management requirements. Conftest uses Rego; it is an execution/reporting alternative, not another language. Conftest.

Isolate untrusted policies in a separate process

A separate process could contain hostile policy code with hard memory and time limits, at installation and lifecycle cost. Rejected: authors are trusted locals, and embedded OPA’s cooperative cancellation is not such a boundary. Isolation needs its own design and evidence.

Leave policy evaluation entirely in external CI

Requires the least tfui integration and can already use Terraform plan JSON. Rejected for this feature because external-only results do not provide the requested integrated risk classifications and review reasons.

Merge parent policies or select named presets

Can reduce copied policy source, but adds effective-policy and upgrade semantics. The owner chose independently selected complete policies and explicit templates; composition or extends can be reconsidered separately.

Edit this page on GitHub