我如何使用 FalkorDB 建構 NexTrace:一個能實際處理雲端入侵的 AI 安全防護工具
How I Built NexTrace: An AI Security Guard That Actually Fixes Cloud Breaches Using FalkorDB
作者使用 FalkorDB 建構 NexTrace,讓 AI 智能體追蹤雲端攻擊路徑、隔離受影響服務並切斷危險連線。FalkorDB 可在不足 1 毫秒內搜尋數百萬條連線;NexTrace 完成處置後會再次檢查,確認公網至資料庫是否仍有攻擊路徑。透過連接 FalkorDB 的 MCP 工具,智能體可依據圖數據採取行動並驗證處置結果。
Have you ever wondered what happens when a hacker finds a tiny security flaw in a website or cloud service? Can they secretly jump from service to service and steal all your private customer data?
In this post, I want to share the story of NexTrace—a project I built for the FalkorDB Hackathon. I will explain the problem in simple words, how graph databases make the difference, and what I learned along the way.
The Big Problem: Cloud Systems Are Like Giant Mazes
Imagine your cloud system is a big city:
Public Gateways: The front gates where everyday visitors come in (like a website login page).
Microservices: Different small offices doing specific jobs (payments, shopping cart, user profiles).
Crown Jewels: The giant bank vault where your most confidential secrets live (credit cards, passwords, databases).
When all these services talk to each other, they create hundreds of invisible roads and permissions.
Here is the scary part: A hacker does not need to break into the bank vault directly.
If they find just one small bug in an unimportant service (like an image downloader or payment helper), they can use internal permissions to make secret jumps:
Traditional security tools only send a boring email saying: "Hey, there is a bug on service X." They don't show you the road to your secrets, and they don't fix it. By the time a human reads the alert hours later, the damage is already done.
Why Most AI Chatbots Can't Help
Most AI chatbots today are just "readers":
- You ask them: "Can you fix this security bug?"
- They say: "I am an AI, I cannot touch your database or run commands. Here is a 10-page text guide on how you can fix it manually."
That is not enough during a real emergency. We didn't need another chatbot that just talks. We needed an Autonomous Agent that takes real action.
Enter FalkorDB: Connecting the Dots
To stop an attacker from jumping through a maze, you must see the maze as a graph.
This is why I chose FalkorDB:
- In FalkorDB, every service, computer, and database is a Node (a dot).
- Every network call and permission is an Edge (a line connecting two dots).
Because FalkorDB is built on high-speed graph mathematics, it can search through millions of connections in less than one millisecond.
How NexTrace Works in 5 Simple Steps
When you upload any cloud setup into NexTrace (like Google Cloud or AWS) or simulate an attack, NexTrace acts like an automated digital firefighter:
Step 1: Find the Blast Radius
First, NexTrace asks FalkorDB: "If an attacker breaks this service, what else can they touch within 1 to 4 jumps?"
FalkorDB instantly returns every connected service, role, and database in danger.
Step 2: Trace the Shortest Attack Road
Next, NexTrace uses FalkorDB’s built-in shortestPath() tool.
It draws the exact road an attacker would take from the public internet all the way to your crown jewel database:
Internet Ingress -> CheckoutService -> PaymentService -> SpannerAdmin -> CreditCardVault
Step 3: Put the Service in Quarantine (Real Action!)
NexTrace doesn't just watch—it acts! It sends a live Cypher write command to FalkorDB:
MATCH (s {name: 'PaymentService'})
SET s.status = 'QUARANTINED'
This isolates the service so it cannot take in any untrusted commands.
Step 4: Cut the Dangerous Lines (Edge Severance)
Next, it severs the dangerous network lines and role-assumption permissions in the graph:
MATCH (s {name: 'PaymentService'})-[r:CALLS|CAN_ASSUME]->(target)
DELETE r
Now the bridge to the bank vault is completely destroyed!
Step 5: Prove It Is 100% Safe (Mathematical Proof)
Finally, NexTrace runs FalkorDB's path algorithm one more time.
It checks if any open roads still exist between the public internet and your private databases.
When the answer is 0, it gives the security team mathematical proof that the breach is completely contained.
What It Looks Like in Real Life
Here is a quick example of talking with NexTrace in the dashboard:
User asks:
"Check Payment service and fix it if any issues are found."
NexTrace Agent:
- Finds the target service (paymentservice).
- Discovers that a zero-day exploit can jump to CreditCardVault.
- Quarantines paymentservice.
- Severs the outgoing connection.
- Shows interactive Cyber Kill Chain cards and full execution logs!
User asks:
"Okay, now recheck and tell me what you fixed."
NexTrace Agent:
- Inspects the live FalkorDB graph.
- Confirms: Status is QUARANTINED.
- Confirms: 2 dangerous edges were removed.
- Confirms: 0 surviving attack paths remain.
What I Learned Building This
Graphs are a natural fit for security: Cloud security is not a flat list of items; it is a web of relationships. Trying to find attack paths with normal SQL tables is slow and painful. With FalkorDB's Cypher queries, it only takes one line of code.
Agents need to write, not just read: An AI agent becomes truly valuable when it has the tools to make changes, lock down threats, and verify its own work.
Model Context Protocol (MCP) makes AI smarter: By giving the LLM standard MCP tools connected directly to FalkorDB, the AI never has to guess. It uses real database facts.
Conclusion
Building NexTrace taught me how powerful graph-driven AI can be. Instead of waiting for humans to spot an attack in a confusing spreadsheet, an autonomous graph agent can spot the path, isolate the workload, and protect your most important data in seconds.
A huge thank you to the FalkorDB team for creating such a fast, developer-friendly graph database!
Check out the project on GitHub and try the live demo!
來源:DEV Community · dev.to
