Example 1: E-Commerce Store Authorization
Let’s build a complete authorization system for an e-commerce platform called “Raystack Store” with custom shopping cart permissions.Scenario
Raystack Store needs to:- Manage financial documents in a project called “Financials”
- Control access to sensitive files with custom permissions
- Allow the accountant (Jane) to read financial files
- Prevent unauthorized access
Step 1: Create Custom Permissions
First, create custom permissions for file storage:storage_file_getstorage_file_deletestorage_file_post
Step 2: Create Custom Roles
Create roles for different file access levels:Step 3: Create the Resource
John creates a sensitive financial file in the Financials project:Step 4: Grant Access with Policy
John grants Jane (accountant) read access to the file:Step 5: Verify Access
Check if Jane can read the file:Example 2: Shopping Cart Management
Build authorization for a shopping cart service with multiple user roles.Step 1: Define Cart Permissions
cart-permissions.yaml
Step 2: Create Cart Roles
Step 3: Assign Roles to Team
Grant different access levels to team members:Example 3: Multi-Project Access Control
Manage access across multiple projects with hierarchical permissions.Scenario Structure
Access Requirements
Alice: Platform Admin
Full access to entire organizationResult: Alice can access all projects and resources.
Bob: Backend Project Manager
Manage only Backend Services projectResult: Bob can manage Backend Services but not Data Analytics.
Permission Checks
Example 4: Compute Instance Deployment
Control who can deploy and manage compute instances.Step 1: Create Compute Permissions
compute-permissions.yaml
Step 2: Create Deployment Roles
Step 3: Create Instance and Assign Access
Create Instance
Grant Operator Access
Step 4: Verify Deployment Permission
{"status": true} - DevOps team members can deploy.
Example 5: Service Account Authorization
Grant API access to service accounts for automated systems.Scenario
A billing service needs to:- Read organization information
- View billing details
- Create billing entries
Step 1: Create Service User
Step 2: Create Custom Billing Role
Step 3: Grant Role to Service User
Step 4: Service Account Makes API Calls
{"status": true}
Common Authorization Patterns
Pattern 1: Role Hierarchy
Implement role inheritance with different permission levels:Pattern 2: Team-Based Access
Use groups for team access management:Create Team Group
Add Members to Group
Grant Role to Entire Group
Pattern 3: Temporary Access
Grant time-limited access by creating and later revoking policies:Grant Temporary Access
Pattern 4: Resource-Specific Access
Grant access to specific resources only:Project A Access Only
Troubleshooting Authorization
Check Why Access is Denied
Common Issues
Permission Denied Despite Having Role
Permission Denied Despite Having Role
Cause: Role is disabled or permission slug doesn’t matchSolution: Check role state and verify permission slugs match exactly
Group Members Can't Access Resource
Group Members Can't Access Resource
Cause: Policy principal is the group, but Check API uses user IDSolution: This is expected. The group relationship automatically cascades to members via SpiceDB’s
member sub-relation.Custom Permission Not Found
Custom Permission Not Found
Cause: Permission wasn’t created or slug format is wrongSolution: List permissions and verify the slug
Service Account Access Denied
Service Account Access Denied
Cause: Using wrong authentication method or client ID/secretSolution: Use Basic auth with service user credentials
Best Practices Summary
Start with Predefined Roles
Use built-in roles like
app_organization_owner before creating custom rolesUse Groups for Teams
Manage team access via groups instead of individual user policies
Grant Least Privilege
Assign minimal permissions needed; use viewer roles by default
Document Custom Roles
Add descriptive metadata explaining purpose and usage
Regular Access Reviews
Audit policies periodically to remove unnecessary access
Test Permission Checks
Always verify authorization works before production deployment
Next Steps
API Reference
Explore complete API documentation for all authorization endpoints