By NHI Mgmt Group Editorial TeamBased on Cerbos: “Query plan adapter for Drizzle ORM” (February 20, 2026)

TL;DR: Policy evaluation can be turned into native SQL filters with a query plan adapter for Drizzle ORM, using partial evaluation to return always-allowed, always-denied, or conditional plans that the database can execute directly, according to Cerbos. That matters because authorization logic stays centralized while query-time enforcement reduces unnecessary reads, memory use, and application-layer access checks.


At a glance

What this is: This is a Cerbos analysis of how PlanResources can translate policy decisions into executable SQL filters for Drizzle ORM, with three outcomes: always allowed, always denied, or conditional.

Why it matters: It matters because IAM teams need to keep authorization centralised while pushing enforcement closer to the query layer, especially when applications must filter large result sets without over-reading data.


Context

Externalized authorization moves permission logic out of application code and into a central policy engine, then applies the decision where the data is queried. In practice, that matters when teams need to answer not only whether a user may access one resource, but which rows they may see in the first place.

The governance gap is familiar to IAM teams: row-by-row checks in application code scale poorly, and fetching data first creates unnecessary exposure and waste. Query-layer enforcement changes the control point, but only if policy semantics can be translated cleanly into native database filters without weakening the policy model.


Key questions

Q: How should teams implement externalized authorization for row-level access control?

A: Use a central policy engine to decide access, then translate the resulting query plan into native filters at the data layer. That keeps authorization logic consistent while allowing the database to apply row-level constraints efficiently. The key is to avoid duplicating policy rules in application code, where drift and inconsistent enforcement usually begin.

Q: When should query-layer authorization be preferred over application-side checks?

A: Prefer query-layer enforcement when the access rule can be expressed as a stable predicate over resource attributes or relationships. It is most useful when the application would otherwise fetch many rows only to discard most of them later. If the policy is too dynamic or non-deterministic to translate cleanly, keep the decision at the application layer.

Q: What breaks when authorization is checked row by row in application code?

A: The application reads and processes data that the user will never be allowed to see, which wastes I/O and memory and increases the chance of inconsistent enforcement across services. In large result sets, that pattern becomes a scaling and governance problem, not just a performance issue.

Q: How do relation mappings affect policy enforcement in SQL?

A: Relation mappings let authorization rules follow linked entities such as ownership, tags, and many-to-many joins instead of only flat columns. That means the policy can still be enforced centrally while the database evaluates the necessary EXISTS or join conditions. Teams should use this approach when real access decisions depend on related records, not just the base row.


Technical breakdown

How PlanResources becomes a query plan

Cerbos PlanResources performs partial evaluation against policy rules and returns an abstract syntax tree that represents access conditions rather than a decision for one specific record. That tree can resolve to always allowed, always denied, or conditional. In the conditional case, the plan preserves the policy logic in a structured form that can be mapped to database columns and query operators. The important shift is that authorization is still policy-driven, but the decision output is now executable as a filter instead of an application-side check.

Practical implication: treat the policy engine as the source of truth and only translate its output into query syntax, never into duplicated business logic.

Why query-layer enforcement changes the access-control model

Traditional per-record authorization checks pull candidate rows into the application and then test them one at a time, which creates unnecessary I/O and memory pressure. Query-layer enforcement inverts that pattern by letting the database evaluate the conditional logic first. Because the filter is expressed in the database's native language, indexes and query planners can do work the application would otherwise repeat. This is a control-plane change more than a performance tweak: access control becomes part of data retrieval rather than an afterthought attached to it.

Practical implication: move row-level filtering into the query path when policy can be expressed as deterministic database predicates.

How relation mappings extend policy beyond flat columns

Real policies rarely map to one table column. A user may be allowed to see documents owned by a department, tagged in a certain way, or linked through many-to-many relationships. The adapter handles this by converting policy attributes into relation-aware expressions, including EXISTS subqueries and nested lookups. That matters because authorization logic often mirrors organisational data models, not just resource records. The technical challenge is to preserve policy intent while still emitting valid, composable SQL that matches the schema and join structure.

Practical implication: model relation mappings explicitly so authorization rules can follow ownership, tags, and linked entities without falling back to application-side scanning.


NHI Mgmt Group analysis

Externalized authorization does not just centralise policy, it relocates enforcement to the data plane. That matters because many IAM programmes still think of authorization as an application concern, even when the real control objective is to stop unauthorised rows from ever being fetched. Once policy output becomes a query filter, database design, schema mapping, and authorization semantics become one governance surface. Practitioners should treat query-layer enforcement as part of authorization architecture, not as an ORM convenience.

Query-time filtering is the right answer when access decisions are deterministic and resource-scoped. The conditional, always-allowed, and always-denied outcomes are a useful mental model because they separate policy evaluation from data retrieval cleanly. That distinction helps teams decide when to keep enforcement in the application and when to push it into SQL. The practical line is simple: if the rule can be expressed as a stable predicate, the database should be allowed to enforce it.

Authorization drift appears when policy logic is duplicated across services instead of projected once into the query layer. The article shows a cleaner pattern in which policies remain central and adapters translate them into executable filters. That reduces the chance that one service interprets access differently from another, especially in row-level access scenarios. IAM teams should see this as a consistency problem as much as a performance one.

Relational authorization is where externalized policy becomes operationally useful at scale. Many real access models depend on ownership, tags, or linked entities, and flat checks cannot represent that faithfully without custom code. Query-plan adapters make those relationships explicit and executable, which is why this pattern is more than a transport mechanism for policy. Practitioners should map their real data relationships before they try to push authorization into the query path.

Externalized authorization is becoming a design pattern for modern application stacks, not a niche integration. As frameworks and ORMs become the place where most data access is expressed, policy enforcement has to meet them there or risk being bypassed by convenience code. The likely direction of travel is tighter coupling between identity policy and data access primitives. Teams should expect authorization architecture to be judged increasingly by how well it scales inside the query engine.

What this signals

Externalized authorization is converging with data-access architecture. Once policy evaluation produces executable filters, IAM teams have to think about authorization in the same design meeting as schema design, indexing, and ORM patterns. That is a useful discipline shift because it reduces the temptation to treat access control as a post-query cleanup step.

Query-layer enforcement raises the bar for policy modelling. Teams need policies that are stable enough to translate into deterministic predicates, and that requirement is often where informal role logic breaks down. The more an access model depends on ownership, relationships, and resource attributes, the more valuable explicit policy translation becomes.


For practitioners

  • Define row-level policy outcomes centrally Keep access rules in a policy engine and use query plans to express only the final filter condition, never duplicated application logic.
  • Map policy attributes to schema columns Create an explicit mapper between policy attribute paths and database fields so the translated filter remains deterministic and maintainable.
  • Handle always-allowed and always-denied branches explicitly Treat unconditional results as first-class outcomes in application code so you avoid unnecessary queries or accidental partial filtering.
  • Model relation-aware access paths Use relation mappings for ownership, tags, and many-to-many joins so authorization follows the actual data model instead of flat-row assumptions.

Key takeaways

  • Externalized authorization works best when policy decisions can be translated into database-native filters rather than repeated in application code.
  • The main benefit is not only performance. It is a cleaner enforcement point that reduces unnecessary reads and aligns authorization with query execution.
  • Teams should centralise policy logic, map it carefully to schema fields, and use relation-aware filters when access depends on linked data.

Standards & Framework Alignment

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

OWASP API Security Top 10 addresses the attack and risk surface, while NIST CSF 2.0, OWASP ASVS and CIS Controls v8 set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0PR.AA-05 — Access Permissions, Entitlements and AuthorizationsExternalized authorization is directly about governing entitlements at the point of data access.
Recommendation — Apply PR.AA-05 to keep authorization decisions centralized and consistently enforced at query time.
OWASP API Security Top 10API5 — Broken Function Level AuthorizationThe article addresses centralised policy enforcement that prevents application-layer authorization drift.
Recommendation — Use API5 patterns to ensure access control is enforced before sensitive data retrieval paths execute.
OWASP ASVSV8 — AuthorizationThe topic concerns how authorization rules are expressed and enforced in application and query layers.
Recommendation — Use V8 to verify that authorization is not duplicated inconsistently across services and queries.
CIS Controls v8CIS-5 — Account ManagementQuery-layer enforcement depends on consistent account and entitlement governance.
Recommendation — Use CIS-5 to keep entitlements aligned with the centralized policies that drive query filtering.

Key terms

  • Externalized Authorization: A design pattern where access decisions are removed from application code and handled by a separate policy layer. This makes authorization easier to govern, test, audit, and reuse across services, especially when roles, attributes, and request context change frequently.
  • 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.
  • Query Plan Adapter: Software that converts a policy expression tree into the native query syntax of a specific database or search engine. It bridges authorization policy and data retrieval so the enforcement point stays close to the data path. The security value depends on accurate schema mapping and operator translation.
  • Relationship Mapping: Relationship mapping is the process of identifying and linking connected individuals or entities around a primary subject. In compliance workflows, it helps reveal indirect risk through family ties, close associates, or ownership structures that a single-record match would miss.

Deepen your knowledge

NHI governance, agentic AI identity, and machine identity lifecycle are core topics in our NHI Foundation Level course, the industry's only accredited NHI security programme. If you are responsible for identity security strategy or NHI governance in your organisation, it is worth exploring.
NHIMG Editorial Note
Published by the NHIMG editorial team on June 10, 2026.
Updated on October 6, 2026.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org