By NHI Mgmt Group Editorial TeamPublished 2026-06-04Domain: Best PracticesSource: Orca Security

TL;DR: OPA decouples policy from application code so the same authorization logic can govern Kubernetes, API gateways and Terraform pipelines with consistent Rego decisions, according to Orca Security. That helps reduce policy fragmentation, but it also makes logging, modular design and control mapping non-negotiable for identity governance.


At a glance

What this is: OPA is an open-source policy engine that centralises authorization decisions across cloud systems, with the key finding that policy fragmentation is the main risk it is designed to reduce.

Why it matters: For IAM practitioners, OPA matters because inconsistent policy enforcement across NHI, autonomous and human access paths creates audit gaps, misconfiguration risk and slower incident response.

👉 Read Orca Security's analysis of Open Policy Agent and policy-as-code


Context

Open Policy Agent, or OPA, is a policy engine that evaluates access and compliance decisions separately from application code. In identity terms, that means the control logic can be shared while the enforcement points differ across Kubernetes, API gateways and infrastructure pipelines.

The governance problem is not the absence of policy, but the multiplication of policy dialects. When the same rule is rewritten in several systems, drift appears in the gaps between intent, implementation and audit evidence, which is why policy-as-code programmes need a consistent decision layer.


Key questions

Q: How should security teams implement policy as code across Kubernetes and Terraform?

A: Start with one policy language, one decision engine and separate enforcement points. Use Rego for the shared logic, then apply it through Kubernetes admission controls, gateway checks and pipeline gates. Keep policy files versioned, tested and tied to named controls so the same rule produces the same decision everywhere.

Q: Why do fragmented policy engines create governance risk?

A: Fragmented policy engines create risk because the same identity or infrastructure rule can be enforced differently in each system. That produces drift between intent and enforcement, weakens audit evidence and makes incident response slower when teams cannot tell which rule applied where.

Q: How do you know if OPA is actually improving control consistency?

A: Look for fewer policy rewrites across systems, stable deny behaviour under testing and clear decision logs that can be matched to control requirements. If the policy exists in code but cannot be traced, tested or audited end to end, consistency is still incomplete.

Q: What should organisations do when policy evaluation becomes too slow?

A: Measure latency, simplify expensive rules and use partial evaluation where the same base data is checked repeatedly. If evaluations slow admission or time out, the control is no longer reliable enough to depend on in production, even if the policy logic is correct.


Technical breakdown

Policy as code across Kubernetes, gateways and Terraform

OPA evaluates structured input against Rego rules and returns a structured decision, usually allow or deny. Because the same engine can sit in an admission controller, API gateway or CI/CD gate, teams avoid reimplementing the same logic in multiple languages. The important distinction is that OPA does not replace enforcement points. It standardises the decision, while Gatekeeper, a webhook, or a pipeline step performs the enforcement in context.

Practical implication: Map each enforcement point to one policy source of truth and keep the decision logic versioned separately from application code.

Rego evaluation and structured decision logging

Rego is a declarative language built for evaluating structured data such as JSON and YAML. It is deterministic, which matters for access control because the same input should produce the same decision every time. OPA can also log the query, input, result, timestamp and bundle metadata, which turns the policy engine into an audit evidence source rather than a hidden control layer. That is especially valuable when compliance teams need proof of what was denied and why.

Practical implication: Enable decision logging from the start and forward the logs into your SIEM and audit reporting pipeline.

Performance, partial evaluation and control reliability

OPA is often described as flexible, but flexibility does not remove latency risk. In high-throughput environments, policy complexity can become a control issue if evaluations slow admission or cause timeouts. Partial evaluation precomputes stable parts of a policy so repeated checks are cheaper at runtime. That makes performance tuning part of governance, because an access control that cannot respond reliably is effectively inconsistent even if the policy itself is correct.

Practical implication: Benchmark policy latency under load and test timeout behaviour before relying on OPA in production enforcement paths.


Read our 52 NHI Breaches Analysis report for a comprehensive view of breaches impacting Non-Human Identities including AI Agents.


NHI Mgmt Group analysis

Policy fragmentation is an identity governance failure, not just an engineering inconvenience. When the same access rule lives separately in Kubernetes, Terraform and gateway code, enforcement diverges even if the written intent is identical. That produces different outcomes for the same actor depending on where the request lands, which is exactly how audit exceptions and misconfigurations accumulate. Practitioners should treat consistency of decision logic as a governance requirement, not a tooling preference.

OPA’s value is greatest where identity decisions must outlive individual applications. Rego turns policy into a reusable control object, which is useful when NHI and human access paths both need the same rule expressed once and enforced many times. That does not remove the need for lifecycle governance, it makes lifecycle governance more visible because policy versioning, review and rollback become traceable control events. The practitioner implication is to manage policy like a governed identity asset.

Decision logging changes policy from an assumption into evidence. A policy that exists only in code may be defensible in architecture review, but it is not yet audit-ready. OPA’s logs provide the record of what was evaluated, what was denied and which bundle produced the outcome. That matters for compliance teams because enforcement history becomes reviewable instead of anecdotal. Practitioners should require logs that are sufficient to reconstruct a decision path.

Modular policy design is the difference between scalable governance and reusable confusion. A single Rego file that tries to govern admission control, RBAC and pipeline checks will eventually obscure accountability and create brittle dependencies. The better model is shared helpers with scoped policy packages aligned to the control surface. That approach keeps the policy layer understandable as the environment grows. Practitioners should split policy by enforcement domain, not by team convenience.

OPA exposes the hidden cost of policy-as-code maturity. Centralisation does not automatically produce control maturity unless teams maintain tests, review cycles and benchmark mapping. A policy written against an outdated standard will still work technically while failing governance intent. The practitioner implication is that policy change management must be as disciplined as application change management.

From our research:

  • 1 in 4 organisations are already investing in dedicated NHI security capabilities, with an additional 60% planning to do so within the next twelve months, according to The State of Non-Human Identity Security.
  • 85% of organisations lack full visibility into third-party vendors connected via OAuth apps, which shows how quickly policy enforcement can outgrow access visibility.
  • NHI Lifecycle Management Guide helps teams connect policy decisions to provisioning, rotation and offboarding rather than treating access rules as static.

What this signals

Policy-as-code only works when the policy layer is governed like an identity control plane. The next maturity step for most teams is not more rules, but better traceability between policy, identity source and enforcement point. That is where OPA fits cleanly alongside broader NHI governance and lifecycle discipline.

Decision logging will become a default expectation in regulated environments. Once policy decisions start replacing embedded logic, auditors will want to see the evaluation history, not just the repository contents. Teams that cannot produce decision evidence will struggle to defend policy outcomes during access reviews or compliance testing.


For practitioners

  • Map each policy to a named control Tie Rego rules to a specific compliance benchmark or internal standard so every deny decision is auditable and explainable. Avoid generic policy language that cannot be traced to a control objective.
  • Separate policy packages by enforcement domain Use modular Rego packages for admission control, gateway authorization and pipeline checks, with shared helper functions only where the logic truly overlaps. Keep the packages small enough to test independently.
  • Turn on decision logging from day one Forward OPA decision logs into your SIEM so you can prove what was evaluated, what was denied and which policy bundle was active at the time.
  • Benchmark policy latency before production use Measure evaluation time under realistic load, including partial evaluation and webhook timeout behaviour, so a correct policy does not become an unreliable control.

Key takeaways

  • OPA reduces policy fragmentation, but it does not remove the governance burden of keeping access logic consistent across systems.
  • Decision logging and modular policy design are the two controls that turn policy-as-code into evidence, not just enforcement.
  • Performance, version control and named control mapping determine whether OPA is a reliable identity control or merely a reusable rule engine.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.AC-4OPA centralises authorization decisions across cloud systems.
NIST Zero Trust (SP 800-207)AC-3OPA supports continuous, context-aware authorization decisions.
OWASP Non-Human Identity Top 10NHI-03Policy consistency is essential for service accounts and other non-human identities.

Use OPA as the decision layer for zero trust enforcement where access must be evaluated at runtime.


Key terms

  • Policy as code: Policy as code means writing access and compliance rules in a version-controlled language that systems can evaluate automatically. It separates the decision from the application, which makes enforcement more consistent, reviewable and testable across cloud-native environments.
  • Rego: Rego is OPA’s declarative policy language for expressing what conditions permit or deny a request. It works well with structured data such as JSON and YAML, and its deterministic evaluation model makes it suitable for real-time authorization and compliance decisions.
  • Decision logging: Decision logging is the record of how a policy engine evaluated a request, including the input, result, timestamp and policy version. In governed environments, it turns access control into evidence by showing what was checked, what was denied and why the outcome occurred.
  • Partial evaluation: Partial evaluation precomputes stable parts of a policy so repeated decisions are faster at runtime. For autonomous or high-throughput enforcement points, it helps reduce latency without changing the policy logic, but it still requires careful testing to avoid hidden complexity.

Deepen your knowledge

Policy as code and identity governance are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are standardising controls across cloud platforms and service identities, it is worth exploring.

This post draws on content published by Orca Security: Open Policy Agent explained and its policy-as-code implications. Read the original.

NHIMG Editorial Note
Published by the NHIMG editorial team on 2026-06-04.
NHI Mgmt Group — the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org