Skip to content

Commit ffae191

Browse files
authored
Merge pull request #14 from jralmaraz/copilot/fix-13
Fix Clippy linting errors in demo modules to resolve CI failures
2 parents da9532f + 96980a1 commit ffae191

File tree

11 files changed

+4314
-2
lines changed

11 files changed

+4314
-2
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ tracing = "0.1"
1919
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2020
futures = "0.3"
2121
schemars = "0.8"
22+
chrono = { version = "0.4", features = ["serde"] }

demos/README.md

Lines changed: 192 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,196 @@
11
# OpenFGA Operator Demo Applications
22

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+
=======
3194
This directory contains demonstration applications showcasing the capabilities of the OpenFGA Operator for different use cases.
4195

5196
## Available Demos
@@ -79,4 +270,4 @@ After completing these demos, you will understand:
79270
For questions or issues with these demos:
80271
- Check the individual demo README files
81272
- Review the main [OpenFGA Operator documentation](../README.md)
82-
- Open an issue in the repository
273+
- Open an issue in the repository

demos/banking-app/README.md

Lines changed: 105 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Banking Application Demo
22

3+
This demo showcases how to implement fine-grained authorization for a banking application using OpenFGA. The demo includes a comprehensive authorization model that supports realistic banking scenarios with RBAC (Role-Based Access Control), multi-ownership, and transaction controls.
4+
35
A comprehensive banking microservice that demonstrates fine-grained authorization using OpenFGA. This demo showcases real-world banking scenarios including account management, transactions, and loan processing with role-based access control.
46

57
## 🏗️ Architecture
@@ -368,4 +370,106 @@ This demo is licensed under the Apache 2.0 License - see the [LICENSE](../../LIC
368370
For issues and questions:
369371
- Check the [main documentation](../../README.md)
370372
- Open an issue in the repository
371-
- Join the OpenFGA community discussions
373+
- Join the OpenFGA community discussions
374+
375+
## Authorization Model
376+
377+
The OpenFGA authorization model defines the following entity types and relationships:
378+
379+
### Entity Types
380+
381+
1. **Bank**
382+
- Relations: `admin`, `manager`, `employee`
383+
- Supports hierarchical roles where managers inherit employee permissions
384+
385+
2. **Branch**
386+
- Relations: `parent_bank`, `manager`, `teller`, `employee`, `admin`
387+
- Branch employees can perform operations on accounts in their branch
388+
- Inherits admin permissions from parent bank
389+
390+
3. **Account**
391+
- Relations: `parent_branch`, `owner`, `co_owner`, `authorized_user`, `can_view`, `can_deposit`, `can_withdraw`, `can_transfer`
392+
- Supports multi-ownership with joint accounts through co-owners
393+
- Different permission levels for different operations
394+
395+
4. **Loan**
396+
- Relations: `parent_branch`, `borrower`, `co_borrower`, `loan_officer`, `can_view`, `can_approve`, `can_modify`
397+
- Supports loan processing workflows with proper approval chains
398+
399+
5. **Transaction**
400+
- Relations: `source_account`, `target_account`, `initiated_by`, `can_view`, `can_reverse`
401+
- Transaction visibility based on account relationships
402+
- Manager-level permissions for transaction reversals
403+
404+
### Key Features
405+
406+
- **RBAC Implementation**: Clear role hierarchy with customer, teller, manager, loan officer, and admin roles
407+
- **Multi-ownership Support**: Joint accounts with multiple owners and co-owners
408+
- **Fine-grained Permissions**: Different permission levels for viewing, depositing, withdrawing, and transferring
409+
- **Branch-based Access Control**: Employees can only access accounts in their branch
410+
- **Loan Processing Workflow**: Proper authorization chains for loan approval and modification
411+
- **Transaction Security**: Controlled access to transaction data and reversal capabilities
412+
413+
## Demo Scenarios
414+
415+
The demo includes the following test scenarios:
416+
417+
### Account Access Control
418+
- Account owners can view, deposit, withdraw, and transfer
419+
- Co-owners have the same permissions as owners
420+
- Branch tellers can view and process deposits
421+
- Branch managers can view and process withdrawals
422+
- Unauthorized users are denied access
423+
424+
### Loan Processing
425+
- Borrowers and co-borrowers can view their loans
426+
- Loan officers can view, approve, and modify loans
427+
- Branch managers can view and approve loans
428+
- Unauthorized users cannot access loan information
429+
430+
### Transaction Control
431+
- Transaction visibility is based on account ownership
432+
- Only branch managers can reverse transactions
433+
- Proper audit trails for all operations
434+
435+
## Usage
436+
437+
```rust
438+
use crate::demos::banking_app::BankingDemo;
439+
440+
// Create demo instance
441+
let demo = BankingDemo::new();
442+
443+
// Check authorization
444+
let request = AuthorizationRequest {
445+
user: "user:alice".to_string(),
446+
relation: "can_view".to_string(),
447+
object: "account:acc1".to_string(),
448+
};
449+
let response = demo.check_authorization(&request);
450+
assert!(response.allowed);
451+
452+
// Get OpenFGA tuples
453+
let tuples = demo.get_tuples();
454+
println!("Total tuples: {}", tuples.len());
455+
```
456+
457+
## Testing
458+
459+
Run the banking demo tests:
460+
461+
```bash
462+
cargo test banking_demo
463+
```
464+
465+
The tests cover:
466+
- Basic authorization scenarios
467+
- RBAC enforcement
468+
- Multi-ownership support
469+
- Transaction controls
470+
- Loan processing workflows
471+
- Edge cases and unauthorized access attempts
472+
473+
## OpenFGA Model File
474+
475+
The complete OpenFGA authorization model is available in `authorization-model.json` and can be imported into an OpenFGA server for production use.

0 commit comments

Comments
 (0)