Skip to content

Conversation

@avirajsingh7
Copy link
Collaborator

@avirajsingh7 avirajsingh7 commented Apr 10, 2025

Target issue is #131

This PR lays the foundation for implementing Role-Based Access Control (RBAC) using Casbin. It introduces the core components needed for flexible and scalable permission management across organizations and projects.

Database Table

  • Introduced casbin_rule table via Alembic migration.
  • Structured to support:
    • p (policy rules)
    • g (org-level role assignments)
    • g2 (project-level role assignments)

Policy Loader

  • Utility function update_casbin_policies to load policies from a JSON file.
  • JSON-driven policy structure for clarity and maintainability.
  • Integrated as a data migration to seed policies on setup.

Casbin Integration

  • Basic rbac_model.conf model for supporting multi-level RBAC (org and project).
  • Casbin Enforcer and adapter initialization.
  • Policy auto-save enabled and policy loading during app startup via lifespan.

Initial Policies

Organization-Level Roles

Role Permissions Inherits Project Role
org_reader Read-only access to org data project_reader
org_writer Read, Create and Update org data project_writer
org_admin Full access (read, write, delete) project_admin

Organizational roles automatically inherit the equivalent project-level roles across all projects in that organization.

Project-Level Roles

Role Permissions
project_reader Read-only access to project data
project_writer Read, Create and Update project data
project_admin Full access (read, write, delete)

Tests

  • Introduced basic test suite (test_rbac.py) to validate policy enforcement.
  • Covers multiple users across different orgs and projects with various roles.

Checklist

Before submitting a pull request, please ensure that you mark these task.

  • Ran fastapi run --reload app/main.py or docker compose up in the repository root and test.
  • If you've fixed a bug or added code that is tested and has test cases.

This pull request introduces the foundational setup for Casbin Role-Based Access Control (RBAC) within the ProjectTech4DevAI/ai-platform repository. The changes include the addition of a Casbin rule table with appropriate columns and index, as well as initial Casbin policies through an Alembic migration, focusing on RBAC policy updates from a JSON file. A new RBAC model configuration file is introduced, defining roles and matcher logic, although it lacks error handling and documentation. The Casbin RBAC implementation is integrated into the FastAPI app, with lifespan management included. Additionally, the CasbinRule model is added for RBAC policy rules, and the import for access control management is updated. The pull request also includes a function to update Casbin policies from a JSON file.

@kodus-ai
Copy link

kodus-ai bot commented Apr 10, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@kodus-ai
Copy link

kodus-ai bot commented Apr 10, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@codecov
Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 99.47644% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
backend/app/core/rbac/update_casbin_policies.py 97.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@kodus-ai
Copy link

kodus-ai bot commented Apr 10, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

1 similar comment
@kodus-ai
Copy link

kodus-ai bot commented Apr 10, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@kodus-ai
Copy link

kodus-ai bot commented Apr 17, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@kodus-ai
Copy link

kodus-ai bot commented Apr 17, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@kodus-ai
Copy link

kodus-ai bot commented Apr 17, 2025

Code Review Completed! 🔥

The code review was successfully completed based on your current configurations.

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@kodus-ai
Copy link

kodus-ai bot commented Apr 17, 2025

Kody Review Complete

Great news! 🎉
No issues were found that match your current review configurations.

Keep up the excellent work! 🚀

Kody Guide: Usage and Configuration
Interacting with Kody
  • Request a Review: Ask Kody to review your PR manually by adding a comment with the @kody start-review command at the root of your PR.

  • Provide Feedback: Help Kody learn and improve by reacting to its comments with a 👍 for helpful suggestions or a 👎 if improvements are needed.

Current Kody Configuration
Review Options

The following review options are enabled or disabled:

Options Enabled
Security
Code Style
Kody Rules
Refactoring
Error Handling
Maintainability
Potential Issues
Documentation And Comments
Performance And Optimization
Breaking Changes

Access your configuration settings here.

@AkhileshNegi
Copy link
Collaborator

Closing this for now as it is not a priority for now, Will come back to it later

@AkhileshNegi AkhileshNegi deleted the feature/rbac branch October 13, 2025 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants