Authorization API
The authorization API provides deny-by-default security through theauthorize() method. Every action must be explicitly authorized before execution.
Core Method
authorize()
crates/oneclaw-core/src/security/traits.rs:77
Authorize an action with deny-by-default semantics. Returns a Permit indicating whether the action is granted and the reason for the decision.
Parameters:
action: &Action- The action to authorize
Result<Permit>- Authorization decision with reason
Action Types
Actions are represented by theAction struct:
crates/oneclaw-core/src/security/traits.rs:7
Fields
- kind: Type of action being requested (see
ActionKind) - resource: Target resource (e.g., file path, command name)
- actor: Device or user requesting the action
ActionKind Enum
crates/oneclaw-core/src/security/traits.rs:18
- Read: Read access to a resource (e.g., read file)
- Write: Write access to a resource (e.g., modify file)
- Execute: Execute a command or tool
- Network: Network access (e.g., HTTP request)
- PairDevice: Device pairing operation
Authorization Permit
ThePermit struct represents the authorization decision:
crates/oneclaw-core/src/security/traits.rs:33
- granted:
trueif action is authorized,falseif denied - reason: Human-readable explanation of the decision
Authorization Logic (DefaultSecurity)
TheDefaultSecurity implementation enforces the following rules:
Source: crates/oneclaw-core/src/security/default.rs:147
1. Device Pairing Check
For all actions exceptPairDevice:
- Device must be in the paired devices list
- Special exception:
actor == "system"bypasses pairing check - Denied if: Device not paired and not “system”
2. Per-Action Authorization
PairDevice
crates/oneclaw-core/src/security/default.rs:162
Read / Write
PathGuard.
Source: crates/oneclaw-core/src/security/default.rs:166
Execute
crates/oneclaw-core/src/security/default.rs:174
Network
crates/oneclaw-core/src/security/default.rs:177
Usage Examples
Basic Authorization
Handling Unpaired Devices
System Actor Bypass
Resource-Based Authorization
Command Execution
Network Access
Development vs Production
Development Mode
- Pairing not required
- Path validation still enforced
- Useful for local development and testing
Production Mode
- Pairing required for all actions
- Deny-by-default for unpaired devices
- Full security enforcement
Best Practices
- Always check permits: Never assume authorization will succeed
- Log denials: Track denied actions for security auditing
- Use specific resources: Provide exact file paths or command names
- Handle actor identity: Ensure
actormatches the paired device ID - Production mode for deployment: Use
DefaultSecurity::production()in production
See Also
- SecurityCore Trait - Trait definition and implementations
- Device Pairing API - Pairing devices for authorization