Skip to content

barryj0915/create_roles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Braintrust RBAC Setup Script

Automated setup script for creating custom role-based access control (RBAC) permission groups in Braintrust. This script creates personas for different team roles and assigns appropriate permissions.

⚠️ DISCLAIMER: This is an example script for demonstration purposes and is not production-ready code. It lacks comprehensive error handling, input validation, retry logic, logging, and security hardening required for production use. Review and modify according to your organization's security policies and requirements before deploying.

Prerequisites

  • Python 3.x
  • requests library (pip install requests)
  • Braintrust API key
  • Braintrust organization name

Installation

pip install requests

Configuration

Set the following environment variables:

export BRAINTRUST_API_KEY="your-api-key-here"
export BRAINTRUST_ORG_NAME="your-organization-name"

Usage

python create_rolespy.py

Personas Created

The script creates six permission groups with predefined roles:

Persona Role Permissions
Engineering Managers Viewer Read-only access to org/projects, experiments, scores, dashboards, logs, traces; alert subscriptions
Domain Experts Viewer Read-only with future commenting and dataset contribution capabilities (Phase 2)
Software Engineers - App Dev Engineer Full control within assigned projects; create/edit prompts, datasets, experiments, scores
QA Engineers Engineer Project-scoped read/write; create/maintain test datasets; run evaluations
AI Solutions Engineering Owner Full admin access across orgs/projects; manage roles, datasets, experiments, scorers
Observability App Teams Engineer Project-scoped admin for their application with full traces/logs, dashboards, alert management

Features

  • Automated Group Creation: Creates permission groups for each persona
  • Role Assignment: Assigns base roles (Owner, Engineer, Viewer) to groups via ACLs
  • Organization Discovery: Automatically resolves organization ID from name
  • Error Handling: Comprehensive error handling with clear status messages
  • Caching: Role ID caching for improved performance

Script Output

The script provides detailed progress information:

  • ✓ Success indicators for completed operations
  • ✗ Error indicators with detailed messages
  • Summary report of created groups
  • Next steps guidance

Post-Setup Steps

After running the script:

  1. Assign Users to Groups: Add team members to appropriate permission groups via Braintrust UI
  2. Configure Project-Level Permissions: Set project-specific access for Engineers and QA groups
  3. Setup Phase 2 Permissions: Enable commenting and dataset contributions for Domain Experts
  4. Configure Alerts: Setup alert subscriptions for Engineering Managers
  5. Implement Custom Scorers: Grant SDK access for AI Solutions Engineering team
  6. Monitoring & Audit: Regularly review access logs and conduct permission audits

API Reference

This script uses the Braintrust API v1:

  • /organization - Organization lookup
  • /role - Role management
  • /group - Permission group creation
  • /acl - Access control list management

Documentation

Class Reference

BraintrustRBACManager

Main class for managing RBAC operations.

Methods

  • get_organization_id() - Retrieve organization ID from name
  • get_role_id(role_name) - Get role ID by name with caching
  • create_custom_role(role_name, permissions, member_permissions) - Create custom role
  • create_permission_group(group_name, description, member_users) - Create permission group
  • assign_group_to_role(group_id, role_id, object_type, object_id, restrict_object_type) - Assign group to role via ACL
  • setup_persona(persona_name, description, role_name) - Complete persona setup with group and role assignment

Troubleshooting

Error: BRAINTRUST_API_KEY environment variable not set

  • Ensure the API key environment variable is exported in your shell

Error: Organization 'name' not found

  • Verify the organization name is correct
  • Check API key has access to the organization

Failed to create role

  • Some custom roles may need to be created via Braintrust UI first
  • Check API permissions and organization access

About

A script to create custom roles in braintrust.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages