跪拜 Guibai
← Back to the summary

KingbaseES Fences AI Queries with MCP Isolation and Row-Level Audit

Hello everyone, I'm Xiao Ye. I write these lessons just so you won't step on the same pitfalls I did.

'Data never leaves the database' sounds like the final answer to security problems. If data doesn't leave the database, leakage risks naturally disappear and compliance issues naturally resolve. But anyone who has done security auditing knows it's not that simple. Data being in the database doesn't mean permissions are in the right hands, doesn't mean every access can be traced by audit, and doesn't mean AI won't use ways it shouldn't to query things it shouldn't.

The access patterns of AI Agents differ fundamentally from traditional DBAs. A human DBA's SQL is hand-written, relatively fixed in structure, with long sessions and clear permission boundaries; an AI Agent's SQL is dynamically generated, with potentially complex nested queries, batch reads of large amounts of context, and it is hard to distinguish 'normal reasoning' from 'malicious instructions' from the SQL itself —— a full table scan might be data analysis, or it might be preparation for data exfiltration.

KingbaseES listed 'in-database security management' as one of the three core capabilities of its KES AI database at its launch event, alongside in-database semantic construction and in-database computation and reasoning. Its engineering logic is worth unpacking: security is not a slogan like 'data never leaves the database', but a combination of implementable mechanisms.

1. MCP Protocol Isolation Layer: AI Never Holds Database Credentials

The first engineering boundary of in-database security is not inside the database kernel, but at the protocol layer between AI and the database.

In traditional approaches, AI applications often directly hold database connection credentials (username/password or token) and then execute model-generated SQL. That means AI owns the full permissions of the database account. Once the model is hit by prompt injection or generates dangerous DDL/DML, there is no intermediate layer at the database level to intercept: permission adjudication happens after the SQL reaches the database, not before.

KingbaseES's path is to introduce MCP (Model Context Protocol) as an isolation layer. The MCP Server sits between the AI client and KingbaseES. The AI client does not hold database credentials; it only passes query intent. The MCP Server performs SQL validation and permission pre-judgment, and only forwards compliant requests to the database for execution.

The core value of this layer is not 'one more component', but moving the position of permission adjudication forward. Every request from AI must pass through the MCP Server's filter, rather than directly hitting the database. KingbaseES remains the final permission adjudicator, but the MCP Server has already done a round of SQL type whitelist validation and risk grading before the request reaches the database.

2. Row-Level Control and Semantic Audit: Making Every AI Access Traceable

After 'data never leaves the database', the granularity of audit must be finer than in traditional models.

Traditional audit records account + SQL + time. But in AI scenarios, the same MCP Server may serve multiple Agents, multiple users, and multiple tasks. Relying solely on accounts cannot distinguish 'who asked AI to query, why, and which rows were queried'.

KingbaseES's in-database security management binds row-level access control with audit: permissions determine not only 'can I query this table', but also 'which rows can I query'; audit records not only SQL but also semantic context — which business scenario this query belongs to, which Agent initiated it, and which sensitive data tags were hit.

In the scenario of an AI Agent's 'query storm', this granularity is necessary: an Agent might issue dozens of queries in a single reasoning pass, each query individually compliant, but combined they may constitute bulk extraction of sensitive data. The value of semantic audit lies in recognizing the pattern of query sequences, rather than just the compliance of a single SQL statement.

3. Full-Chain Output Validation: Blocking the 'Last Mile' Risk of AI

Even if permissions and audit are in place, the output generated by AI is still a risk point.

Large models may generate answers with misleading or out-of-bounds conclusions based on compliant query results. KingbaseES's KES AI database builds a full-chain LLM output validation mechanism: a 'generate-validate-grade-output' loop that grades model output for risk, and high-risk content is blocked or flagged before being delivered to users.

This mechanism addresses a problem that is easily underestimated in AI security: data hasn't leaked, but the model has reached a conclusion it shouldn't have based on the data. In financial risk control, medical diagnosis, and government decision-making, this risk may have a more insidious real-world impact than data leakage.

4. Boundaries: Three Questions That Still Need Answers After 'Data Never Leaves the Database'

In-database security management solves the layer of 'data doesn't leave the database', but it is not the whole of security.

First question: How do we ensure the security of the MCP Server itself? If the MCP Server is breached or misconfigured, the isolation layer is useless. Minimal privilege configuration, independent deployment, and access control for the MCP Server are prerequisites for this architecture.

Second question: Who defines the permission boundaries for AI? The in-database mechanism provides execution boundaries, but the business decision of 'which data AI can query and which operations it can perform' still needs to be made by humans. Turning off high-risk operations (DDL, large-scale DML) by default is a pragmatic starting point for engineering.

Third question: The integrity and tamper-resistance of audit logs themselves. If audit logs can be bypassed or tampered with, traceability is empty talk. This issue has been discussed repeatedly in traditional database security, and it holds equally true in AI scenarios.

5. Summary

'Data never leaves the database' is a necessary condition, not a sufficient one. The access patterns of AI Agents — dynamic SQL, batch context, difficulty in distinguishing reasoning from maliciousness — require security mechanisms to sink from 'boundary defense' to 'kernel control'. KingbaseES's in-database security management uses an MCP protocol isolation layer to move permission adjudication forward, uses row-level control and semantic audit to make every AI access traceable, and uses full-chain output validation to block the 'last mile' risk of model output. But the security of the MCP Server itself, the business definition of AI permissions, and the integrity of audit logs remain questions that must be continuously answered after 'data never leaves the database'. Security is not a switch; it is a set of continuously running mechanisms.

Xiao Ye has your back, SQL won't go off track

If there's anything else you'd like to know, feel free to leave a comment! Xiao Ye will tell you everything I know... see you next time~

Comments

Top 1 from juejin.cn, machine-translated. The original thread is authoritative.

shushenghong

The layer of "who asked AI to query, and why" is equally missing from coding agents. Our team runs all AI tasks on a dedicated machine within the team, credentials are stored only on that machine, permissions are assigned per project, and every access can be traced back to which task was dispatched by whom, so at least it's auditable when something goes wrong. The issue of individual compliance but combined overreach is very real. I'd like to ask: when semantic audit identifies sequences of queries, does it aggregate by session, or by the task that the Agent undertook?