Postgres RLS enforces rules at the database row level, while application-level authorization evaluates broader context such as user roles, resource attributes, and workflow state. RLS is best for protecting records inside one table. Application authorization is better for expressing reusable policies across services and for maintaining a single source of truth for access decisions.
Why This Matters for Security Teams
Postgres row-level security and application-level authorization solve different parts of the same access-control problem. RLS is strong when the question is “which rows can this database session see?” Application authorization is stronger when the question is “should this actor be allowed to perform this business action at all?” Security teams get into trouble when they assume one layer can replace the other, especially in systems where API keys, service accounts, and autonomous jobs touch sensitive data outside a single table boundary.
That distinction matters because database-only rules cannot express workflow context, cross-service policy, or identity provenance. As NHI Management Group notes in the Ultimate Guide to NHIs, organisations often struggle with visibility into service accounts and excessive privilege, which makes hidden database access a real governance issue. For broader access-control design, OWASP Non-Human Identity Top 10 and NIST SP 800-53 Rev 5 Security and Privacy Controls both reinforce that authorization has to be tied to identity, privilege, and least-privilege enforcement across the full stack. In practice, many security teams discover the gap only after a service account has already bypassed business controls through direct database access.
How It Works in Practice
RLS is enforced inside PostgreSQL at query time. It filters rows based on predicates attached to a table, so it is ideal when the database should prevent one tenant, user, or workload from reading another tenant’s records. Application-level authorization happens earlier in the request flow. It evaluates who the caller is, what action is being requested, what object is involved, and what the current workflow state allows.
In a mature design, both layers are used together. The application decides whether the action is valid, and the database ensures the data access stays constrained even if the application logic is bypassed or misused. That layering is especially important for NHIs, because machine identities often have broad reach and are hard to inspect after the fact. The NHI Mgmt Group research on Ultimate Guide to NHIs — Key Challenges and Risks shows why privilege sprawl and visibility gaps make single-layer controls brittle. For implementation, teams typically map app roles or policy decisions to business actions, then use RLS as a backstop for tenant isolation or record-level scoping.
- Use application authorization for business rules such as “can approve,” “can transfer,” or “can export.”
- Use RLS for record isolation such as tenant IDs, ownership, or per-user document visibility.
- Keep database roles narrow so direct connections do not become a shortcut around policy.
- Log both decision points so investigations can tell whether denial came from the app or the database.
CIS Controls v8 aligns with this layered approach by pushing least privilege and controlled access pathways, while database controls alone cannot express every workflow nuance. These controls tend to break down when teams allow shared service credentials to connect directly to production databases, because the database can only enforce row predicates, not business intent or approval context.
Common Variations and Edge Cases
Tighter database enforcement often increases implementation overhead, requiring organisations to balance stronger data isolation against policy complexity and developer friction. The tradeoff becomes visible in multi-tenant platforms, analytics pipelines, and microservices where one application might legitimately need different access paths depending on task, environment, or tenant.
Current guidance suggests treating RLS as a data-protection control, not a complete authorization model. It works best when the access question is narrowly about rows in one database. It breaks down when a policy must account for cross-table relationships, external systems, approval workflows, or time-bound exceptions. Application-level authorization is usually the better source of truth for those cases because it can incorporate richer context and central policy logic.
There is no universal standard for how much policy should live in the app versus the database, but the practical rule is simple: keep the business decision in the application and the data boundary in the database. That split is especially important for non-human identities that execute repeated, high-volume actions. The 52 NHI Breaches Analysis shows how quickly machine access becomes dangerous when privilege is broader than the task requires. Teams should also remember that RLS does not replace authentication, secrets hygiene, or service-account governance.
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 and CSA MAESTRO address the attack and risk surface, while NIST CSF 2.0, NIST AI RMF and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Non-Human Identity Top 10 | NHI-01 | Directly addresses service-account privilege and hidden machine access. |
| NIST CSF 2.0 | PR.AC-4 | Access enforcement maps to least-privilege authorization decisions. |
| NIST AI RMF | GOVERN | Policy ownership and accountability matter for layered authorization design. |
| NIST Zero Trust (SP 800-207) | AC-6 | Zero trust emphasizes continuous, least-privilege access enforcement. |
| CSA MAESTRO | IAM | Agentic and workload identities need context-aware access boundaries. |
Inventory NHI identities, scope their database access, and remove broad credentials.
Related resources from NHI Mgmt Group
- What is the difference between role-based access control and attribute-based access control in AI agent authorization?
- What is the difference between centralized authorization and application-level access logic?
- What is the difference between application-level access checks and shared authorization layers?
- What is the difference between policy-based authorization for NHIs and application-level access checks?
Deepen Your Knowledge
Reviewed and updated by the NHIMG editorial team on September 1, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org