惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - Franky
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志
宝玉的分享
宝玉的分享
量子位
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
GbyAI
GbyAI
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tailwind CSS Blog
Y
Y Combinator Blog
L
LangChain Blog
The Cloudflare Blog
T
The Blog of Author Tim Ferriss
U
Unit 42
Martin Fowler
Martin Fowler
aimingoo的专栏
aimingoo的专栏
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
月光博客
月光博客

Cerbos - All Posts

Authentik vs Keycloak: Self-hosted IdP comparison Mapping business requirements to authorization policy for automotive Fine-grained authorization for AI gateways EIC 2026: Stop counting agents, protect what they can touch Agent skill for writing authorization policies in Claude Desktop Identity security in 2026 EIC 2026 takeaways: the identity stack built for humans will not hold up for AI agents Already have authentication? Here's the authorization layer you still need. Tokens are authorization decisions: a guide to policy-driven token issuance What is a Runtime Authorization Platform It's a dimmer switch, not a kill switch. How CISOs are rethinking AI agent governance From maps to bitmaps (and from bitmaps to bitmaps) AuthZEN, Shared Signals, SCIM Events, IPSIE: Notes from the OpenID Enterprise Panel How do you update authorization policies without redeploying your application? IIW42 recap: Where agent authorization got real Cerbos PDP v0.52.0/v0.53.0: Engine performance, security hardening, and CEL path functions Authorization Management Platforms: what they do, how they work, and where they fit PocketOS AI coding agent deleted a production database in 9 seconds Non-Human Identity management still has a blind spot Supabase alternative in 2026: Best open source auth options Benefits of on-premise authorization: Why enterprises are moving toward self-hosted Authorization policies: How to write, test, and validate them (faster with AI) Agent skill for writing authorization policies How much does it cost to build authorization in-house? Why centralized authorization governance reduces incident response time OPA alternative Why AI agents make authorization a right now problem Modernizing legacy application authorization: why it’s your biggest security blind spot How to add authorization to legacy applications without code changes 5 authorization blind spots auditors find, and how to fix them
Mongoose adapter for Cerbos Query Plans v2.0
Alex Olivier · 2025-11-25 · via Cerbos - All Posts

Cerbos Query Plans solve a common challenge in decoupled authorization: how to efficiently determine which records a user is allowed to access without fetching everything from the database and checking permissions one by one. Instead of forcing your application to load and filter entire collections, a query plan gives you a structured set of conditions derived from your policies. You pass that plan into your data access layer, the adapter turns it into native filters, and MongoDB returns only the permitted documents.

With the original Mongoose adapter, we introduced a straightforward method for translating those conditions into MongoDB queries. Version 2.0 takes this further, covering a wider range of policy patterns, adding deeper schema awareness, and enhancing the overall developer experience.

What’s new in v2.0 Mongoose adapter

All policy logic enforced inside MongoDB

The adapter now maps the full set of Cerbos logical and comparison operators into native MongoDB filters. Everything stays inside the database engine. This includes string helpers, membership checks, scoped fields, and the collection-aware lambda operators.

Expressions that previously returned “unsupported”, such as hasIntersection involving projected fields or the all lambda over nested arrays, now translate cleanly to $elemMatch. This makes complex resource attributes and deeply nested schemas fully compatible with Cerbos Query Plans without any additional glue code.

A refreshed mapper contract

Mapping Cerbos fields to MongoDB paths is now clearer and more explicit. The adapter distinguishes between scalar fields, one-to-one relations, and arrays, and understands scoped fields such as tags.name or owner.id without guesswork.

You can also provide either a mapping object or a mapper function, useful when your models follow consistent naming conventions. The result is more reliable translations and fewer surprises when writing policies that reflect your data model.

Using the v2.0 Mongoose adapter

import { GRPC as Cerbos } from "@cerbos/grpc";
import mongoose from "mongoose";

import { queryPlanToMongoose, PlanKind } from "@cerbos/orm-mongoose";

// connect to mongo
await mongoose.connect("mongodb://127.0.0.1:27017/test");
// connect to Cerbos PDP
const cerbos = new Cerbos("localhost:3592", { tls: false });

// Mongoose models (schema excluded for brevity)
const MyModel = mongoose.model("MyModel", ....);

// Fetch the query plan from Cerbos passing in the principal
// resource type and action
const queryPlan = await cerbos.planResources({
  principal: {....},
  resource: { kind: "resourceKind" },
  action: "view"
});

// Generate the mongoose filter from the query plan
const result = queryPlanToMongoose({
  queryPlan,
  fieldNameMapper: {
    "request.resource.attr.owner.id": "ownerId",
    "request.resource.attr.tags.name": "tags.name"
  }
});

// The query plan says the user would always be denied
// return empty or throw an error depending on your app.
if(result.kind == PlanKind.ALWAYS_DENIED) {
  return console.log([]);
}

// Pass the filters in as where conditions
const rows = await MyModel.find({
  ...result.filters
});

console.log(rows);

Try it out

The updated adapter is available now on npm and in the query-plan-adapter repository, which also includes the Prisma and SQLAlchemy adapters.

Version 2.0 makes it easier to express richer authorization logic in your policies and have those constraints enforced efficiently inside MongoDB. If you rely on Mongoose and Cerbos Query Plans, this is a significant upgrade.

If you’re looking to enforce fine-grained, contextual, and continuous authorization across apps, APIs, AI agents, MCPs, services and workloads - give Cerbos a try. Curious how Cerbos could fit into your architecture or have specific requirements to discuss? Feel free to book a call with a Cerbos engineer for a free 1:1 session.