Raft Policy Management System
A comprehensive Open Policy Agent (OPA) management interface for creating, editing, testing, and managing authorization policies written in the Rego language.
Overview
This policy management system provides a complete solution for managing OPA policies with a modern, user-friendly interface. It enables policy authors to create, edit, test, and visualize authorization policies with real-time feedback, making policy development faster and more accessible.
Features
๐ง Policy Management
-
Create New Policies: Interactive policy creation with templates and guidance
-
Edit Existing Policies: Full-featured Monaco editor with Rego syntax highlighting
-
Policy Versioning: Track changes and maintain policy history
-
Real-time Sync: Automatic synchronization with OPA decision engine
-
Import/Export: Support for policy import and export functionality
๐งช Policy Testing
-
Interactive Testing: Test policies with custom JSON input
-
Real-time Evaluation: See policy results instantly
-
Input Generation: Auto-generate test inputs from policy structure
-
Error Handling: Comprehensive error reporting and validation
-
Performance Monitoring: Track policy evaluation performance
๐ Policy Visualization
-
Statement Cards: Visual representation of policy rules and statements
-
Diff View: Compare policy changes with side-by-side visualization
-
Syntax Highlighting: Color-coded Rego syntax for better readability
-
Line Indicators: Highlight specific lines when editing or debugging
-
Change Tracking: Visual indicators for added, modified, and removed policies
Technical Architecture
Frontend Stack
-
React 18 with TypeScript
-
Next.js for server-side rendering and API routes
-
Material-UI (MUI) for consistent UI components
-
Monaco Editor for advanced code editing
-
TanStack Query for efficient data fetching and caching
-
Highlight.js for syntax highlighting
File Structure
pages/policies/
โโโ index.tsx # Main policy management page
โโโ README.md # This documentation
components/Service/OPA/
โโโ policies.d.ts # TypeScript type definitions
โโโ PolicyList.tsx # Policy navigation and management
โโโ PolicyToolbar.tsx # Policy action buttons and controls
โโโ EditorPanel.tsx # Monaco editor integration
โโโ TestingPanel.tsx # Policy testing interface
โโโ StatementCard.tsx # Visual policy statement representation
โโโ StatementCards.tsx # Collection of statement cards
โโโ StatementPanel.tsx # Statement management panel
โโโ Welcome.tsx # Welcome screen and onboarding
โโโ Utils.ts # Policy parsing and utility functions
โโโ CreateNewPolicyDialog.tsx # New policy creation dialog
โโโ PolicyVersionControl.tsx # Version control interface
โโโ Editor/ # Advanced editor components
โโโ Utils.ts # Editor utilities
โโโ [other editor files]
Usage Guide
Getting Started
-
Navigate to Policies: Access the policy management interface at
/policies -
View Existing Policies: Browse the policy list in the left sidebar
-
Create New Policy: Click the "Create New" button to start a new policy
-
Edit Policy: Select a policy from the list and click the edit icon
Creating a New Policy
-
Click "Create New" button in the policy list
-
Enter your policy name and description
-
Write your Rego policy in the editor
-
Use the Testing Panel to validate your policy
-
Save your policy to make it active
Testing Policies
-
Select a policy from the list
-
Open the Testing Panel
-
Enter JSON input data or click "Generate Input from Policy"
-
Click "Evaluate Policy for Input" to see results
-
Review the output and any warnings or errors
Understanding Policy Statements
-
Statement Cards: Each policy is broken down into visual statement cards
-
Rule Types: Different colors indicate rules, variables, and functions
-
Change Indicators: Modified policies show visual change indicators
-
Line Highlighting: Click on statement cards to highlight corresponding editor lines
Policy Development Best Practices
Writing Effective Policies
-
Keep it Simple: Write clear, readable policies
-
Use Comments: Document complex logic with comments
-
Test Thoroughly: Always test policies with various inputs
-
Version Control: Save policies frequently and track changes
-
Follow Naming Conventions: Use descriptive policy and rule names
Common Patterns
# Allow access based on user role
allow {
input.user.role == "admin"
}
# Conditional access with multiple criteria
allow {
input.user.role == "user"
input.resource.type == "document"
input.action == "read"
}
# Time-based access control
allow {
input.user.role == "employee"
time.now_ns() < input.resource.expires_at
}
API Integration
Policy CRUD Operations
// Get all policies
GET /api/frontend/df-services/opa/get_policies
// Get active policies from OPA
GET /api/frontend/df-services/opa/get_policies_active
// Evaluate policy
POST /api/frontend/df-services/opa/evaluate/{policyPath}
// Save policy
PUT /api/frontend/df-services/opa/policies/{policyId}
// Delete policy
DELETE /api/frontend/df-services/opa/policies/{policyId}
// Chatbot integration
POST /api/v1/prediction/{chatflowId}
Troubleshooting
Common Issues
-
Policy Not Loading
-
Check for syntax errors in the Rego code
-
Verify policy format matches OPA requirements
-
Review server logs for loading errors
-
-
Testing Failures
-
Ensure input JSON is valid
-
Check policy rules for logic errors
-
Verify policy is loaded in OPA
-
-
Performance Issues
-
Review complex policies for optimization opportunities
-
Monitor evaluation times in testing panel
-
Consider breaking down complex policies
-