DEVOURED
Securing Enterprise Data Agents with Policy as Code: A Preflight Gate for Multi-Domain NL2SQL
A new preflight security model secures NL2SQL agents by validating generated SQL dependencies against fine-grained policies before execution.
What: The approach parses generated SQL into an Abstract Syntax Tree (AST), maps it to specific table/column dependencies, and evaluates these against CEL policies. This prevents shared service accounts from accessing data that should be restricted at the user level.
Why it matters: As organizations deploy data agents, relying on the database's default permissions for a shared service account is a significant security flaw that this pattern attempts to mitigate.
Takeaway: If you are building an AI data agent, move away from shared service accounts and implement an AST-based static analysis step to validate query scope against user-level access policies before submitting SQL to your database.
Deep dive
- Parses raw SQL input into an Abstract Syntax Tree (AST) to extract granular access requirements.
- Evaluates security policies using Common Expression Language (CEL) to verify that the query only touches permitted tables and columns.
- Dynamically injects row-level filters into the SQL query before execution.
- Acts as an intermediate 'gate' between the LLM's output and the database engine.
- Maintains database-native roles as a secondary guardrail rather than relying on them as the primary security implementation.
Decoder
- NL2SQL (Natural Language to SQL): The process of using LLMs to convert natural language queries into executable SQL commands.
- AST (Abstract Syntax Tree): A tree representation of the abstract syntactic structure of source code, used by compilers and parsers to understand the logic of a query.
- CEL (Common Expression Language): A non-Turing complete, high-performance expression language used for embedding policy-based security checks.
Original article
Shared service accounts can bypass the user-level controls a data agent is meant to enforce. This prototype parses generated SQL into an AST, resolves every table and column dependency, evaluates CEL policies, then prepares approved row filters before execution. Database roles remain the final guardrail. The takeaway: authorize the query's actual dependencies, not just its visible output.
Explore all 60 articles in today's digest
Fresh dev news, AI-digested daily. Never miss a trend at devoured.fyi