Policy Engine Guide
Replace OAuth scopes with fine-grained policy documents. Support RBAC, ABAC, time-based, IP-based, and MFA conditions in a single authorization model.
In this guide
1. Why Policies Instead of Scopes?
OAuth scopes are strings like read:projects write:users. They seem simple, but they break down quickly in real applications.
OAuth Scopes
- xScope explosion: hundreds of permission strings
- xNo time-based or IP-based conditions
- xToken size grows with permissions
- xNo inheritance or wildcard matching
- xChanges require re-issuing tokens
QAuth Policies
- +One policy reference per token
- +Time, IP, MFA, and custom conditions
- +Token size stays constant
- +Glob patterns for flexible matching
- +Update policies without re-issuing tokens
2. Policy Document Structure
A policy document is a JSON object with an ID, version, and a list of rules. Rules are evaluated in priority order (highest first).
3. Resource Patterns (Globs)
Resources use glob patterns. * matches a single path segment, ** matches any depth.
Action Matching
Actions are matched exactly or with * (all actions):
["read"]— only "read" action["read", "list"]— "read" or "list"["*"]— any action
4. Conditions
Rules can have conditions that must all be met for the rule to match. Four condition types are supported.
Time-Based Conditions
Restrict access to specific hours and days. Useful for business-hours-only operations.
IP-Based Conditions
Restrict access to specific CIDR ranges. Combine with allow and deny lists.
MFA Conditions
Require multi-factor authentication for sensitive operations.
Custom Conditions
Match against any attribute on the subject. Supports in (array membership) and eq (exact equality).
5. Evaluation Flow
The policy engine follows a simple, predictable evaluation flow.
Sort rules by priority
Higher priority numbers are evaluated first
Match resource pattern
Check if the resource path matches any rule's glob patterns
Match action
Check if the requested action is in the rule's actions list
Evaluate conditions
All conditions must pass (AND logic)
Return first match
The first matching rule determines allow or deny
Default deny
If no rule matches, access is denied
6. Real-World: RBAC
Classic role-based access control with viewer, editor, and admin roles.
7. Real-World: Multi-Tenant SaaS
Tenant isolation with per-tenant roles and platform admin override.
8. Real-World: Healthcare / HIPAA
HIPAA-compliant policy combining role, time, IP, and MFA conditions with emergency break-glass access.