Authorization controls what an authenticated key can do. While verification answers "is this key valid?", authorization answers "can this key perform this action?"
Unkey provides Role-Based Access Control (RBAC) that lets you:
- Define permissions (like
documents.read,billing.write) - Group permissions into roles (like
admin,editor,viewer) - Attach roles or permissions directly to keys
- Check permissions during verification
When to use this#
Different customers get different feature access. Enterprise keys can do more than free-tier keys.
Admin keys can delete resources, editor keys can modify, viewer keys can only read.
Only keys with beta.access permission can use new features.
Keys can only access specific resources: project.123.read,
project.456.write.
How it works#
Define permissions
Create permissions that map to actions in your app: documents.read,
documents.write, users.delete.
Create roles (optional)
Group permissions into roles for easier management. An editor role might
include documents.read and documents.write.
Attach to keys
When creating or updating keys, assign roles or direct permissions.
Check during verification
Pass a permission query when verifying. Unkey checks if the key has the required permissions.
Quick example#
Permissions vs Roles#
| Concept | What it is | Example |
|---|---|---|
| Permission | A specific action | documents.read, billing.manage |
| Role | A group of permissions | admin = all permissions, viewer = read-only permissions |
You can attach either (or both) directly to keys:
- Attach roles when you want predefined access levels
- Attach permissions directly for fine-grained control