An AI-powered Role-Based Access Control (RBAC) Policy Engine with natural language interface for defining, validating, and managing access policies.
A Role-Based Access Control (RBAC) policy engine with a natural language chat interface. Build access control policies by simply describing them in plain English.
- Natural Language Interface: Create policies using conversational AI (powered by Claude)
- Real-time Policy Preview: See your policy update as you build it
- Smart Validation: Automatic validation against available roles, resources, and permissions
- Contextual Conditions: Add conditions based on environment, time, MFA status, etc.
- Clarifying Questions: The system asks for clarification when instructions are ambiguous
- Policy Evaluation: Test your policies with simulated access requests
- Export: Generate
final_policy.jsonandvalidation_report.json
- Python 3.10 or higher
- Claude API key (provided in assignment email)
cd RBAC_CRED
# Create virtual environment (recommended)
python -m venv venv
# Activate virtual environment
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate
# Install dependencies
pip install -r requirements.txtThe .env file is already configured with the provided Claude API key. If you need to change it:
# Edit .env file
ANTHROPIC_API_KEY=your-api-key-hereOption A: Run both API and UI together (Recommended)
# On Windows, run in two separate terminals:
# Terminal 1 - Start the API server
python -m uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000
# Terminal 2 - Start the UI
streamlit run src/ui/app.pyOption B: Using Make (if you have Make installed)
make run-api # In terminal 1
make run-ui # In terminal 2- Chat UI: http://localhost:8501
- API Docs: http://localhost:8000/docs
- Health Check: http://localhost:8000/health
Simply type what you want in natural language:
"Admins can do everything"
"Viewers can only read invoices and reports"
"Operators can edit orders in production only"
"Deny delete access to guests"
"Allow analysts to export reports during business hours"
list roles- Show available roleslist resources- Show available resourceslist permissions- Show available permissionslist context- Show context attributes for conditionsshow policy- View current policyvalidate- Validate the policyclear- Start overhelp- Show help
You: Admins can do everything
Bot: β
Rule 'Admin Full Access' added successfully.
Admin role now has all permissions on all resources.
You: Viewers can only read invoices
Bot: β
Rule 'Viewer Read Invoices' added successfully.
Viewers can now read invoices.
You: Operators can edit orders
Bot: I need a bit more information. In which environment should
operators be able to edit orders? (production, staging, development)
You: Only in staging
Bot: β
Rule 'Operator Edit Orders Staging' added successfully.
Operators can edit orders when environment is staging.
You: validate
Bot: β
Policy is valid! 3 rules defined, no errors.
You: (Click "Export Policy" in sidebar)
Bot: Policy exported to output/final_policy.json
RBAC_CRED/
βββ src/
β βββ api/ # FastAPI backend
β β βββ main.py # API endpoints
β βββ agent/ # Conversation agent
β β βββ conversation_agent.py # Claude-powered NL processing
β β βββ session_manager.py # Session persistence
β βββ core/ # Core policy engine
β β βββ policy_builder.py # Policy construction
β β βββ decision_engine.py # ALLOW/DENY evaluation
β β βββ schema_cache.py # Schema caching
β βββ mock_apis/ # Mock discovery APIs
β β βββ roles_api.py # Roles & permissions
β β βββ resource_api.py # Resource schemas
β β βββ context_api.py # Context attributes
β β βββ validator_api.py # Policy validation
β βββ models/ # Pydantic data models
β β βββ policy.py # Policy, Rule, Condition
β β βββ role.py # Role, Permission
β β βββ resource.py # Resource, Action
β β βββ context.py # Context attributes
β βββ ui/ # Streamlit chat interface
β βββ app.py # Chat UI
βββ tests/ # Unit tests
βββ output/ # Generated artifacts
β βββ final_policy.json
β βββ validation_report.json
βββ data/ # Cached data & sessions
βββ Makefile # Build commands
βββ docker-compose.yml # Docker setup
βββ requirements.txt # Dependencies
βββ README.md # This file
βββ DESIGN.md # Architecture documentation
# Run all tests
pytest
# Run with verbose output
pytest -v
# Run specific test file
pytest tests/test_decision_engine.py
# Run with coverage
pytest --cov=src# Build and run with Docker Compose
docker-compose up --build
# Stop containers
docker-compose downadmin- Full system administratoroperator- Operational userviewer- Read-only accessauditor- Audit activitiesdeveloper- Development resourcesanalyst- Data analysismanager- Team managementguest- Limited access
invoice- Financial invoicesuser_profile- User accountsreport- Analytics reportspayment- Payment transactionsorder- Customer ordersproduct- Product catalogcustomer- Customer accountsaudit_log- Audit logsconfiguration- System settingsdashboard- Analytics dashboards
read,write,delete,create,listexport,import,approve,rejectexecute,configure,audit
environment: production, staging, development, testingtime_of_day: business_hours, off_hours, morning, eveningday_of_week: weekday, weekend, monday-sundaymfa_verified: true, falsedata_classification: public, internal, confidential, restricteddevice_type: desktop, mobile, tablet, api, service- And more...
After exporting, you'll find:
output/final_policy.json- The complete policy definitionoutput/validation_report.json- Validation results
| Endpoint | Method | Description |
|---|---|---|
/api/chat |
POST | Send a chat message |
/api/sessions |
GET/POST | Manage sessions |
/api/policy/{session_id} |
GET | Get current policy |
/api/policy/validate/{session_id} |
POST | Validate policy |
/api/policy/export/{session_id} |
POST | Export to files |
/api/evaluate |
POST | Evaluate access request |
/api/discovery/roles |
GET | Discover roles |
/api/discovery/resources |
GET | Discover resources |
/api/discovery/context |
GET | Discover context attributes |
See full API documentation at http://localhost:8000/docs
Make sure the API is running on port 8000:
python -m uvicorn src.api.main:app --reload --host 0.0.0.0 --port 8000Ensure your .env file contains the API key:
ANTHROPIC_API_KEY=sk-ant-api03-...
Make sure you're running from the project root directory and the virtual environment is activated.
This project is for CRED's backend engineer internship assessment.