Skip to content

feat-2187: add additional default roles while bootstrap#2188

Merged
crivetimihai merged 7 commits intoIBM:mainfrom
KKNithin:feature-2187-add-additional-roles-during-bootstrap
Jan 25, 2026
Merged

feat-2187: add additional default roles while bootstrap#2188
crivetimihai merged 7 commits intoIBM:mainfrom
KKNithin:feature-2187-add-additional-roles-during-bootstrap

Conversation

@KKNithin
Copy link
Collaborator

@KKNithin KKNithin commented Jan 19, 2026

resolves new feature request #2187

Closes #2187

@crivetimihai
Copy link
Member

Review Feedback

Hi @KKNithin, thank you for this feature addition. I've done a deep review and found some issues that need to be addressed before merging.

Critical Bug: Missing Early Exit

The code logs a warning when the file doesn't exist but still tries to open it:

# bootstrap_db.py lines 276-280
if not additonal_default_roles_path.exists():
    logger.warning(f"Catalog file not found: {additonal_default_roles_path}")
    # BUG: No return/continue here!

with open(additonal_default_roles_path, "r", encoding="utf-8") as f:  # Will fail!

Compare to the correct pattern already in the codebase at catalog_service.py:73-75:

if not catalog_path.exists():
    logger.warning(f"Catalog file not found: {catalog_path}")
    return {"catalog_servers": [], "categories": [], "auth_types": []}  # Returns early!

Fix: Add early exit after the warning (e.g., don't try to open the file if it doesn't exist).


Invalid JSON Example in .env.example

The example JSON uses Python syntax, not valid JSON:

# Current (INVALID JSON):
#     "is_system_role": True,   # Python True, not JSON true
# },                             # Trailing comma not allowed in JSON

Fix: Use valid JSON syntax:

[{
    "name": "example_role_1",
    "description": "Read-only access to resources",
    "scope": "team",
    "permissions": ["teams.join", "tools.read", "resources.read"],
    "is_system_role": true
}]

If a user copies the current example, their JSON file will fail to parse with a confusing error.


Other Issues

Issue Location Fix
Typo: additonal_ should be additional_ bootstrap_db.py (4 occurrences) Rename variables
Wrong message: "Catalog file not found" bootstrap_db.py:277 Change to "Additional roles file not found"
Missing newline at end of file .env.example Add newline

What Works Well

  • Feature is disabled by default (safe)
  • Good test coverage
  • Permissions are validated by role_service.create_role()
  • Helm chart updated
  • Documentation in .env.example

Please address these issues and I'll re-review. Let me know if you have any questions!

@KKNithin
Copy link
Collaborator Author

@crivetimihai I have resolved your code review comments

can you please review it for approval

Copy link
Collaborator

@madhav165 madhav165 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@crivetimihai The functionality of adding roles worked when I tested by updating the .env variables and crated the role JSON.

However, the new roles can't be used without more changes to the RBAC system which is hardcoded to look for roles in EmailTeamMember rather than UserRoles. Team member management also does not link them to the Roles in the code.

@crivetimihai crivetimihai added this to the Release 1.0.0-RC1 milestone Jan 21, 2026
Nithin Katta and others added 7 commits January 25, 2026 13:10
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Fixes identified by code review:
1. Path resolution: Fixed parent.parent.parent -> parent.parent to correctly
   resolve project root from mcpgateway/bootstrap_db.py
2. JSON validation: Added validation that loaded JSON is a list of dicts with
   required keys (name, scope, permissions). Invalid entries are skipped with
   warnings instead of crashing bootstrap.
3. Improved logging: Log all attempted paths when file not found

Added tests:
- test_bootstrap_roles_with_dict_instead_of_list: Validates error when JSON is
  a dict instead of array
- test_bootstrap_roles_with_missing_required_keys: Validates warning when roles
  are missing required fields

Added documentation:
- docs/docs/manage/rbac.md: New "Bootstrap Custom Roles" section with
  configuration examples for Docker Compose and Kubernetes
- docs/docs/architecture/adr/036-bootstrap-custom-roles.md: ADR documenting
  the feature design, error handling, and security considerations

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
ChatGPT review identified that description and is_system_role were accessed
unconditionally via role_def["key"], causing KeyError for minimal roles.

Fix:
- Use role_def.get("description", "") with empty string default
- Use role_def.get("is_system_role", False) with False default

Added test:
- test_bootstrap_roles_with_minimal_valid_role: Verifies a role with only
  required fields (name, scope, permissions) is created successfully with
  correct defaults for optional fields

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
@crivetimihai crivetimihai force-pushed the feature-2187-add-additional-roles-during-bootstrap branch from 3fa3765 to 1bb7207 Compare January 25, 2026 14:22
@crivetimihai
Copy link
Member

PR Review & Fixes Summary

This PR has been rebased onto main and includes several fixes identified during code review.

Original Feature

Load custom RBAC roles from a JSON configuration file during database bootstrap, allowing organizations to pre-configure roles before deployment.

Fixes Applied

1. Path Resolution Bug (Medium)

  • Issue: Path(__file__).parent.parent.parent resolved one level above repo root
  • Fix: Changed to Path(__file__).resolve().parent.parent to correctly resolve to project root
  • Also: Added improved logging showing all attempted paths when file not found

2. JSON Structure Validation (Medium)

  • Issue: No validation of JSON structure could crash bootstrap with malformed config
  • Fix: Added validation that:
    • JSON must be an array (not dict)
    • Each entry must be a dict
    • Required keys: name, scope, permissions
    • Invalid entries are skipped with warnings; valid entries are processed

3. Optional Fields Bug (Medium)

  • Issue: description and is_system_role accessed via role_def["key"] causing KeyError for minimal roles
  • Fix: Use .get() with defaults:
    • description defaults to ""
    • is_system_role defaults to False

Tests Added

  • test_bootstrap_roles_with_minimal_valid_role - Verifies roles with only required fields work
  • test_bootstrap_roles_with_dict_instead_of_list - Verifies error when JSON is dict
  • test_bootstrap_roles_with_missing_required_keys - Verifies invalid entries are skipped

Documentation Added

  • docs/docs/manage/rbac.md - New "Bootstrap Custom Roles" section with Docker Compose and Kubernetes examples
  • docs/docs/architecture/adr/036-bootstrap-custom-roles.md - Full ADR documenting design decisions

Commits

1bb720758 fix: Make description and is_system_role optional for bootstrap roles
34bed2bd3 fix: Improve bootstrap roles validation and documentation
2a89ed60f feat-2187: test fix
1d7c9ce11 feat-2187: fixing review comments
3f33ff01f feat-2187: fixing review comments
a4a590f5c feat-2187: fix lint issues
61779ec9f feat-2187: add additional default roles while bootstrap

Test Results

All 35 bootstrap_db tests pass.

Docker Compose Testing

Verified end-to-end:

  • Custom roles loaded from JSON file ✅
  • Roles created with correct permissions ✅
  • Error handling for invalid JSON ✅
  • Graceful degradation when file not found ✅

@crivetimihai crivetimihai merged commit 3568ccb into IBM:main Jan 25, 2026
52 checks passed
kcostell06 pushed a commit to kcostell06/mcp-context-forge that referenced this pull request Feb 24, 2026
* feat-2187: add additional default roles while bootstrap

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>

* feat-2187: fix lint issues

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>

* feat-2187: fixing review comments

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>

* feat-2187: fixing review comments

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>

* feat-2187: test fix

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>

* fix: Improve bootstrap roles validation and documentation

Fixes identified by code review:
1. Path resolution: Fixed parent.parent.parent -> parent.parent to correctly
   resolve project root from mcpgateway/bootstrap_db.py
2. JSON validation: Added validation that loaded JSON is a list of dicts with
   required keys (name, scope, permissions). Invalid entries are skipped with
   warnings instead of crashing bootstrap.
3. Improved logging: Log all attempted paths when file not found

Added tests:
- test_bootstrap_roles_with_dict_instead_of_list: Validates error when JSON is
  a dict instead of array
- test_bootstrap_roles_with_missing_required_keys: Validates warning when roles
  are missing required fields

Added documentation:
- docs/docs/manage/rbac.md: New "Bootstrap Custom Roles" section with
  configuration examples for Docker Compose and Kubernetes
- docs/docs/architecture/adr/036-bootstrap-custom-roles.md: ADR documenting
  the feature design, error handling, and security considerations

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

* fix: Make description and is_system_role optional for bootstrap roles

ChatGPT review identified that description and is_system_role were accessed
unconditionally via role_def["key"], causing KeyError for minimal roles.

Fix:
- Use role_def.get("description", "") with empty string default
- Use role_def.get("is_system_role", False) with False default

Added test:
- test_bootstrap_roles_with_minimal_valid_role: Verifies a role with only
  required fields (name, scope, permissions) is created successfully with
  correct defaults for optional fields

Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>

---------

Signed-off-by: Nithin Katta <Nithin.Katta@ibm.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Nithin Katta <Nithin.Katta@ibm.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>
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.

[FEATURE][AUTH]: Extend default_roles to add additional roles during bootstrap

3 participants