Skip to content

ADR-0036: Bootstrap Custom Roles from Configuration FileΒΆ

  • Status: Accepted
  • Date: 2026-01-25
  • Deciders: Core Engineering Team

ContextΒΆ

Organizations deploying MCP Gateway need to pre-configure custom RBAC roles that match their organizational structure and access policies. Currently, the only way to create custom roles is through the Admin API after deployment, which creates additional manual steps and potential security gaps during the initial deployment window.

Common use cases requiring custom roles:

  • Data Analyst role: Read-only access to tools and resources for data analysis workflows
  • Auditor role: Global read access for compliance and security audits
  • CI/CD role: Limited permissions for automation pipelines
  • Operator role: Permissions to manage servers without full admin access

DecisionΒΆ

We will allow administrators to define custom roles in a JSON configuration file that is automatically loaded during database bootstrap. The feature is:

  1. Disabled by default - Requires explicit opt-in via MCPGATEWAY_BOOTSTRAP_ROLES_IN_DB_ENABLED=true
  2. File-based configuration - Roles defined in a JSON file specified by MCPGATEWAY_BOOTSTRAP_ROLES_IN_DB_FILE
  3. Validated on load - JSON structure is validated; invalid entries are skipped with warnings
  4. Idempotent - Existing roles are detected and skipped; safe to run multiple times

Configuration SchemaΒΆ

[
  {
    "name": "role_name",          // Required: unique identifier
    "scope": "team|global",       // Required: access scope
    "permissions": ["..."],       // Required: array of permission strings
    "description": "...",         // Optional: human-readable description
    "is_system_role": true|false  // Optional: prevent user modification
  }
]

File ResolutionΒΆ

When a relative path is provided: 1. Check current working directory 2. Check project root (mcpgateway/bootstrap_db.py β†’ parent.parent)

Error HandlingΒΆ

Error Case Behavior
File not found Log warning, continue with default roles
Invalid JSON Log error, continue with default roles
JSON is not an array Log error, continue with default roles
Entry missing required keys Skip entry with warning, process valid entries
Entry is not a dict Skip entry with warning, process valid entries

ConsequencesΒΆ

PositiveΒΆ

  • βœ… Organizations can pre-configure roles matching their access policies
  • βœ… Eliminates manual role creation after deployment
  • βœ… Supports GitOps workflows (roles defined in version control)
  • βœ… Reduces security gap during initial deployment
  • βœ… Graceful degradation on configuration errors

NegativeΒΆ

  • ❌ Adds complexity to bootstrap process
  • ❌ Requires understanding of permission strings
  • ❌ Configuration errors may go unnoticed if not monitoring logs

NeutralΒΆ

  • πŸ”„ Roles can still be created/modified via Admin API after bootstrap
  • πŸ”„ Feature is opt-in; no impact on existing deployments

Alternatives ConsideredΒΆ

Option Why Not
Helm values only Not all deployments use Helm; need container-agnostic solution
Environment variable per role Complex syntax for arrays of permissions; hard to manage
Database seed scripts Requires DB access; doesn't integrate with bootstrap flow
Admin API on startup Requires API to be available; chicken-and-egg problem

Security ConsiderationsΒΆ

  1. File access: Configuration file should be mounted read-only
  2. Validation: All entries are validated before processing
  3. No secrets: Role definitions don't contain sensitive data
  4. Audit trail: All role creation is logged

ImplementationΒΆ

  • mcpgateway/config.py: Add configuration settings
  • mcpgateway/bootstrap_db.py: Add role loading and validation logic
  • tests/unit/mcpgateway/test_bootstrap_db.py: Comprehensive test coverage
  • RBAC Configuration - End-user documentation
  • Issue #2187 - Feature request
  • PR #2188 - Implementation