Policy Engine Best Practices
This guide provides security best practices for configuring and using the Radium Policy Engine effectively.
Principle of Least Privilegeβ
Always start restrictive and relax as needed.
- Default to Ask mode - Use
approval_mode = "ask"for maximum safety - Explicit allow rules - Only allow operations you explicitly trust
- Deny by default - Use deny rules for operations you never want
# Good: Explicit allow, deny by default
approval_mode = "ask"
[[rules]]
name = "Allow only specific safe operations"
priority = "user"
action = "allow"
tool_pattern = "read_file"
arg_pattern = "*.md"
Defense in Depthβ
Use multiple layers of protection.
- Combine priority levels - Use Admin rules for critical security, User rules for convenience
- Multiple rule types - Combine tool patterns with argument patterns
- Session constitutions - Add temporary restrictions for specific tasks
# Layer 1: Admin rules (highest priority)
[[rules]]
name = "Block dangerous operations"
priority = "admin"
action = "deny"
tool_pattern = "run_terminal_cmd"
arg_pattern = "rm -rf *"
# Layer 2: User rules (medium priority)
[[rules]]
name = "Require approval for writes"
priority = "user"
action = "ask_user"
tool_pattern = "write_*"
# Layer 3: Default approval mode
approval_mode = "ask"
Priority System Usageβ
Admin Priorityβ
Use for:
- Security-critical rules that must never be overridden
- Enterprise policies that apply to all users
- Rules that block dangerous operations
Examples:
- Blocking external network access
- Preventing file operations outside workspace
- Denying sudo/root access
[[rules]]
name = "Enterprise security policy"
priority = "admin"
action = "deny"
tool_pattern = "http_*"
reason = "Enterprise policy: no external network access"
User Priorityβ
Use for:
- Workspace-specific policies
- Developer preferences
- Convenience rules
Examples:
- Allowing safe read operations
- Requiring approval for writes
- Custom tool access patterns
[[rules]]
name = "Workspace-specific rule"
priority = "user"
action = "allow"
tool_pattern = "read_*"
Default Priorityβ
Use for:
- Fallback rules
- System defaults
- Low-priority policies
Note: Default priority rules are rarely needed since approval mode provides the fallback.
Pattern Matching Best Practicesβ
Be Specificβ
Bad:
tool_pattern = "*" # Too broad
Good:
tool_pattern = "read_*" # Specific pattern
Use Argument Patternsβ
Combine tool and argument patterns for fine-grained control:
[[rules]]
name = "Allow reading only markdown files"
priority = "user"
action = "allow"
tool_pattern = "read_file"
arg_pattern = "*.md"
Test Patternsβ
Always test patterns before deploying:
# Test if a pattern matches
rad policy check read_file config.toml
# Validate policy file
rad policy validate
Session Constitution Guidelinesβ
When to Useβ
- Temporary restrictions - Add constraints for a specific task
- Per-session security - Different security levels for different sessions
- Dynamic policies - Adjust policies based on runtime conditions
Best Practicesβ
- Clear expiration - Constitutions auto-expire after 1 hour
- Limit rules - Maximum 50 rules per session (enforced)
- Combine with static rules - Use constitutions to supplement, not replace, static rules
Audit Loggingβ
Enable Loggingβ
Policy decisions should be logged for audit trails:
- Log all decisions - Record allow/deny/ask decisions
- Include context - Log tool name, arguments, matched rule
- Track changes - Log when policies are modified
Log Formatβ
{
"timestamp": "2025-01-15T10:30:00Z",
"tool": "write_file",
"args": ["config.toml"],
"decision": "ask_user",
"matched_rule": "Require approval for file writes",
"session_id": "session-123"
}
Common Security Pitfallsβ
1. Overly Permissive Patternsβ
Problem:
tool_pattern = "*" # Allows everything
Solution:
tool_pattern = "read_*" # Specific pattern
2. Missing Admin Rulesβ
Problem: Critical security rules at User priority can be overridden.
Solution: Use Admin priority for security-critical rules.
3. Ignoring Argument Patternsβ
Problem: Only matching tool names, not arguments.
Solution: Use argument patterns for fine-grained control:
[[rules]]
name = "Block dangerous arguments"
priority = "admin"
action = "deny"
tool_pattern = "run_terminal_cmd"
arg_pattern = "rm -rf *"
4. Not Testing Policiesβ
Problem: Deploying untested policies.
Solution: Always test with rad policy check before deploying.
5. Forgetting Approval Modeβ
Problem: Relying only on rules, ignoring approval mode fallback.
Solution: Set appropriate approval mode as safety net:
approval_mode = "ask" # Safe default
Enterprise Deploymentβ
Policy Distributionβ
- Version control - Commit policy.toml to version control
- Team sharing - Share policies via git
- Centralized management - Use admin rules for org-wide policies
Policy Reviewβ
- Regular audits - Review policies quarterly
- Change management - Require approval for policy changes
- Documentation - Document all rules with reasons
Complianceβ
- Regulatory requirements - Ensure policies meet compliance needs
- Audit trails - Maintain logs of all policy decisions
- Access control - Restrict who can modify policies
Performance Considerationsβ
Rule Countβ
- Optimal: 10-50 rules
- Acceptable: 50-100 rules
- Problematic: 100+ rules (consider consolidation)
Pattern Complexityβ
- Simple patterns - Fast evaluation
- Complex patterns - May slow evaluation
- Argument patterns - Additional overhead
Optimization Tipsβ
- Order rules by frequency - Most common rules first (within priority)
- Consolidate similar rules - Combine rules with same action
- Use specific patterns - More specific = faster evaluation
Migration Guideβ
From No Policy to Policy Engineβ
- Start with Ask mode -
approval_mode = "ask" - Add allow rules gradually - Start with most common safe operations
- Add deny rules for dangerous ops - Block known dangerous operations
- Test thoroughly - Use
rad policy checkextensively - Monitor and adjust - Review logs and adjust as needed
From Other Policy Systemsβ
- Map approval modes - Match your current mode to Radium modes
- Convert rules - Translate rules to Radium format
- Test equivalence - Verify same behavior
- Gradual migration - Migrate one workspace at a time