Quick Path — Which API to Use at Each Layer
Layer | Purpose | Common Checks | Recommended Oso API |
---|---|---|---|
Service (request-level) | Coarse-grained access for incoming HTTP requests | Admin-only routes, tenant isolation | authorize |
Business logic (resource-level) | Fine-grained checks inside handlers | Ownership, action-specific perms | authorize |
Data access (query-level) | Return only authorized results from DB/search | Multi-tenant filters, search boundaries | list |
Presentation (client-side) | Conditional UI rendering | Show/hide buttons, enable/disable fields | actions |
Start Small: Initial Adoption
- Begin with one endpoint. Incremental rollout makes testing easier.
- Pick an authorization data strategy early:
- Local Authorization: Query your own database.
- Centralized facts: Store facts in Oso Cloud for complex relationship models.
- Context facts: Send facts inline with each request (useful during development).
- Deploy behind feature flags. Run Oso in parallel with your current system, monitor and reconcile differences before wider deployment.
- Audit coverage. Track unprotected endpoints with middleware:
Layer-by-Layer Enforcement
Secure your application at multiple layers using different authorization approaches. Each layer serves distinct security purposes.Service Layer: Request-Level Authorization
- Purpose: Coarse-grained access control for HTTP requests.
- Checks: Admin endpoints, tenant separation, route-level permissions.
- Implementation: Use middleware for scalability across routes.
Business Logic: Resource-Level Authorization
- Purpose: Fine-grained permissions on specific resources.
- Checks: “edit” permission, ownership, action-specific permissions.
- Implementation: Use reusable patterns like decorators or higher-order functions.
Data Access: Query-Level Authorization
- Purpose: Filter data queries to return only authorized results.
- **Checks: ** database queries return only accessible records, search results filtered by permissions, and list operations constrained by permission boundaries.
- Implementation: Modify queries with authorization constraints.
Presentation: Client-Side Authorization
- Purpose: Conditionally render UI elements based on user permissions.
- Checks: show/hide actions, disable inputs.
- Implementation: Create server endpoints for authorization data.
Never enforce in the frontend alone.
Key Principles
- Defense in depth. Use multiple layers per endpoint.
- Fail securely. Deny on missing/failed checks.
- Optimize performance. Batch checks, cache with TTL.
- Audit and monitor. Log decisions, review failed attempts.
Need help enforcing authorization in your application? Schedule a call with an Oso engineer.