|
1 | 1 | # OpenFGA Operator Demo Applications |
2 | 2 |
|
| 3 | +This directory contains comprehensive demo applications showcasing the OpenFGA operator's capabilities for implementing fine-grained authorization in real-world scenarios. |
| 4 | + |
| 5 | +## Demo Applications |
| 6 | + |
| 7 | +### 1. Banking Application Demo |
| 8 | +**Location**: `banking-app/` |
| 9 | + |
| 10 | +A comprehensive banking application demonstrating: |
| 11 | +- **RBAC Implementation**: Customer, teller, manager, loan officer, and admin roles |
| 12 | +- **Multi-ownership Support**: Joint accounts with multiple owners and co-owners |
| 13 | +- **Transaction Controls**: Fine-grained permissions for deposits, withdrawals, and transfers |
| 14 | +- **Loan Processing**: Approval workflows with proper authorization chains |
| 15 | +- **Branch-based Security**: Employee access limited to their branch |
| 16 | + |
| 17 | +**Key Features**: |
| 18 | +- Bank-branch-account hierarchy |
| 19 | +- Multi-ownership for joint accounts |
| 20 | +- Role-based transaction permissions |
| 21 | +- Loan officer workflows |
| 22 | +- Manager override capabilities |
| 23 | + |
| 24 | +### 2. GenAI RAG Agent Demo |
| 25 | +**Location**: `genai-rag/` |
| 26 | + |
| 27 | +A Generative AI RAG (Retrieval-Augmented Generation) application demonstrating: |
| 28 | +- **Knowledge Base Management**: Curator, contributor, and reader roles |
| 29 | +- **Document-Level Security**: Individual document permissions with inheritance |
| 30 | +- **Content Filtering**: RAG responses filtered based on document access rights |
| 31 | +- **AI Model Access Control**: Separate permissions for using and configuring models |
| 32 | +- **Session-Based RAG**: Controlled RAG sessions with participant management |
| 33 | + |
| 34 | +**Key Features**: |
| 35 | +- Three-tier role system for knowledge management |
| 36 | +- Document-level permissions with inheritance |
| 37 | +- Content filtering for RAG responses |
| 38 | +- AI model usage and configuration controls |
| 39 | +- Session-based access with intersection permissions |
| 40 | + |
| 41 | +## Architecture |
| 42 | + |
| 43 | +Both demos implement the following architectural patterns: |
| 44 | + |
| 45 | +### Authorization Models |
| 46 | +- **OpenFGA DSL Format**: Complete authorization models in JSON format |
| 47 | +- **Relationship-Based**: Tuples defining relationships between users and resources |
| 48 | +- **Hierarchical Permissions**: Role inheritance and computed relationships |
| 49 | +- **Intersection Logic**: Complex permission combinations using OpenFGA's operators |
| 50 | + |
| 51 | +### Demo Structure |
| 52 | +``` |
| 53 | +demos/ |
| 54 | +├── banking-app/ |
| 55 | +│ ├── authorization-model.json # OpenFGA model definition |
| 56 | +│ ├── banking_demo.rs # Demo implementation |
| 57 | +│ └── README.md # Documentation |
| 58 | +├── genai-rag/ |
| 59 | +│ ├── authorization-model.json # OpenFGA model definition |
| 60 | +│ ├── genai_rag_demo.rs # Demo implementation |
| 61 | +│ └── README.md # Documentation |
| 62 | +└── README.md # This file |
| 63 | +``` |
| 64 | + |
| 65 | +### Code Organization |
| 66 | +- **Data Models**: Structs representing entities (users, accounts, documents, etc.) |
| 67 | +- **Authorization Logic**: Implementation of OpenFGA authorization checks |
| 68 | +- **Test Scenarios**: Comprehensive test coverage for all authorization scenarios |
| 69 | +- **Helper Methods**: Utility functions for common authorization patterns |
| 70 | + |
| 71 | +## Running the Demos |
| 72 | + |
| 73 | +### Prerequisites |
| 74 | +```bash |
| 75 | +# Ensure you have Rust installed |
| 76 | +rustc --version |
| 77 | + |
| 78 | +# Navigate to the project root |
| 79 | +cd /path/to/authcore-openfga-operator |
| 80 | +``` |
| 81 | + |
| 82 | +### Build and Test |
| 83 | +```bash |
| 84 | +# Build the project with demos |
| 85 | +cargo build |
| 86 | + |
| 87 | +# Run all tests including demo tests |
| 88 | +cargo test |
| 89 | + |
| 90 | +# Run only banking demo tests |
| 91 | +cargo test banking_demo |
| 92 | + |
| 93 | +# Run only GenAI RAG demo tests |
| 94 | +cargo test genai_rag_demo |
| 95 | + |
| 96 | +# Run with verbose output |
| 97 | +cargo test -- --nocapture |
| 98 | +``` |
| 99 | + |
| 100 | +### Integration with OpenFGA |
| 101 | + |
| 102 | +The authorization models can be imported into a running OpenFGA server: |
| 103 | + |
| 104 | +```bash |
| 105 | +# Start OpenFGA server (example using Docker) |
| 106 | +docker run -p 8080:8080 openfga/openfga run |
| 107 | + |
| 108 | +# Import banking model |
| 109 | +curl -X POST http://localhost:8080/stores \ |
| 110 | + -H "Content-Type: application/json" \ |
| 111 | + -d @demos/banking-app/authorization-model.json |
| 112 | + |
| 113 | +# Import GenAI model |
| 114 | +curl -X POST http://localhost:8080/stores \ |
| 115 | + -H "Content-Type: application/json" \ |
| 116 | + -d @demos/genai-rag/authorization-model.json |
| 117 | +``` |
| 118 | + |
| 119 | +## Key Authorization Patterns Demonstrated |
| 120 | + |
| 121 | +### 1. Role-Based Access Control (RBAC) |
| 122 | +Both demos implement hierarchical RBAC where higher-level roles inherit permissions from lower-level roles. |
| 123 | + |
| 124 | +### 2. Multi-ownership |
| 125 | +The banking demo shows how to handle joint accounts and shared resources with multiple owners. |
| 126 | + |
| 127 | +### 3. Contextual Permissions |
| 128 | +Permissions that depend on the context (e.g., branch employees can only access accounts in their branch). |
| 129 | + |
| 130 | +### 4. Content Filtering |
| 131 | +The GenAI demo shows how to filter content in responses based on user permissions. |
| 132 | + |
| 133 | +### 5. Intersection Permissions |
| 134 | +Complex authorization logic where users need multiple permissions simultaneously. |
| 135 | + |
| 136 | +### 6. Hierarchical Inheritance |
| 137 | +Permissions that cascade down organizational hierarchies. |
| 138 | + |
| 139 | +## Testing Approach |
| 140 | + |
| 141 | +Each demo includes comprehensive tests covering: |
| 142 | + |
| 143 | +### Positive Test Cases |
| 144 | +- Users with proper permissions can perform authorized actions |
| 145 | +- Role inheritance works correctly |
| 146 | +- Multi-ownership scenarios function properly |
| 147 | + |
| 148 | +### Negative Test Cases |
| 149 | +- Users without permissions are denied access |
| 150 | +- Unauthorized operations are blocked |
| 151 | +- Cross-organizational access is prevented |
| 152 | + |
| 153 | +### Edge Cases |
| 154 | +- Boundary conditions for role hierarchies |
| 155 | +- Complex permission intersections |
| 156 | +- Cascading permission changes |
| 157 | + |
| 158 | +## Production Deployment |
| 159 | + |
| 160 | +These demos serve as templates for production applications: |
| 161 | + |
| 162 | +1. **Model Deployment**: Import the authorization models into your OpenFGA server |
| 163 | +2. **Tuple Management**: Implement tuple creation/deletion for your entities |
| 164 | +3. **Authorization Checks**: Integrate the authorization logic into your application |
| 165 | +4. **Performance Optimization**: Add caching and bulk operations as needed |
| 166 | + |
| 167 | +## Documentation |
| 168 | + |
| 169 | +Each demo includes detailed documentation covering: |
| 170 | +- Authorization model explanation |
| 171 | +- Entity relationships |
| 172 | +- Permission matrices |
| 173 | +- Usage examples |
| 174 | +- Test scenarios |
| 175 | + |
| 176 | +See the individual README files in each demo directory for detailed information. |
| 177 | + |
| 178 | +## Contributing |
| 179 | + |
| 180 | +When adding new demo applications: |
| 181 | + |
| 182 | +1. Follow the established directory structure |
| 183 | +2. Include comprehensive OpenFGA authorization model |
| 184 | +3. Implement realistic test scenarios |
| 185 | +4. Add thorough documentation |
| 186 | +5. Ensure all tests pass |
| 187 | + |
| 188 | +## References |
| 189 | + |
| 190 | +- [OpenFGA Documentation](https://openfga.dev/docs) |
| 191 | +- [OpenFGA Authorization Models](https://openfga.dev/docs/modeling/getting-started) |
| 192 | +- [Relationship-Based Access Control](https://openfga.dev/docs/concepts#what-is-relationship-based-access-control-rebac) |
| 193 | +======= |
3 | 194 | This directory contains demonstration applications showcasing the capabilities of the OpenFGA Operator for different use cases. |
4 | 195 |
|
5 | 196 | ## Available Demos |
@@ -79,4 +270,4 @@ After completing these demos, you will understand: |
79 | 270 | For questions or issues with these demos: |
80 | 271 | - Check the individual demo README files |
81 | 272 | - Review the main [OpenFGA Operator documentation](../README.md) |
82 | | -- Open an issue in the repository |
| 273 | +- Open an issue in the repository |
0 commit comments