How to Configure Dify MariaDB Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a dify mariadb audit log by turning on the native server plugin. Then you link your AI workflows to the database using a scoped role. Many teams start by giving their AI apps a single shared database user. When permissions are too broad, a bad prompt can read or change your whole database. How the dify mariadb audit log works in practice Dify lets your team build AI workflows that query external SQL databases. When a user asks a question, the app writes a SQL query and runs it. Mar

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up a dify mariadb audit log by turning on the native server plugin. Then you link your AI workflows to the database using a scoped role. Many teams start by giving their AI apps a single shared database user. When permissions are too broad, a bad prompt can read or change your whole database.

How the dify mariadb audit log works in practice

Dify lets your team build AI workflows that query external SQL databases. When a user asks a question, the app writes a SQL query and runs it. MariaDB receives this query over a standard network port using a stored database password. The native audit plugin watches these events inside the database engine and writes them down.

To set this up, your database admin loads the audit plugin on the MariaDB server. You then pick which events to track, such as logins, reads, or table writes. Next, you create a specific MariaDB user for your AI app with read-only table permissions. You paste those login details into your AI workflow settings so the tool can run queries.

Every time the AI agent queries a table, MariaDB writes a line to the log file. This log records the timestamp, the database username, the host address, and the raw SQL text. Security teams then ship these log files to a central log server for review.

What native database logging solves and what it misses

The native MariaDB plugin does a great job of recording past database events. It proves to auditors that your database tracks table reads and schema changes. If a query breaks a table, your team can read the file to see what ran. It also catches failed login attempts from unknown servers right away.

Still, native database logging has major blind spots when paired with AI tools. First, every query from the AI app uses the exact same MariaDB user account. The database log shows the shared app user, not the human or workflow that triggered it. You cannot tell which team member or AI agent ran a risky query.

Second, the native audit log only writes events down after the query finishes running. It decides who can log in, not what individual statements can do in flight. If an AI agent writes a huge query or drops a table, the log just records the damage. It cannot pause a dangerous command to ask a human for approval first.

Audit Log Integrity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Finally, native logging does not clean up sensitive data inside query results. When a query pulls customer emails, phone numbers, card numbers, or national IDs, raw data flows out. Those same raw values can also end up sitting in plain text inside your log files.

Managing AI database queries and sensitive data

Running AI agents against live databases requires more than a passive text log. Teams need a way to link every database query back to a real identity. You also need controls that check SQL statements before the database runs them.

Adding field-level data masking helps protect private records during AI workflows. Masking rewrites matched fields like card numbers or emails in query results on the fly. This keeps sensitive records out of AI prompts while still letting the workflow run.

Check MySQL queries and results on the wire

MySQL grants control who logs in. They do not check single queries or mask sensitive columns once a session starts. With hoop.dev, you run an open-source proxy, a sidecar for your MySQL. It runs next to MySQL, RDS, or Aurora and reads the MySQL wire protocol.

Multi-statement batches and prepared queries are split and checked one by one by hoop.dev guardrails. When a rule refuses a query, MySQL returns a native error packet with your message. On the response path, hoop.dev data masking rewrites string values in returned rows that match your rules. Every query and decision is logged per resource. See the MIT-licensed project on GitHub.

Frequently asked questions

Does the MariaDB audit log show which Dify user ran a query?

No, the native log only sees the shared database account used by the AI app. You need identity tracking in front of the database to log the specific user or agent.

Can the MariaDB audit plugin block a bad AI query from running?

No, the native audit plugin only records queries after the database runs them. It cannot stop a destructive statement or ask a human for approval before execution.

How do we protect emails and card numbers when Dify queries MariaDB?

Start by limiting the database role to specific tables and views. For live protection, use dynamic data masking to rewrite emails, phone numbers, and card numbers in results.

The query runs. The emails stay hidden.