Implementation Summary: Azure Custom Role Designer¶
🎯 Overview¶
A complete, production-ready CLI tool for platform engineers to create, update, and manage Azure custom roles with granular permission control.
✨ What Was Created¶
Core Tool Components¶
- custom_role_designer.py (Main CLI Tool)
- 400+ lines of Click-based CLI interface
- Interactive and command-line modes
- Beautiful console output with Rich library
-
10+ commands for role management
-
role_manager.py (Role Management)
- Pydantic data models for Azure roles
- Load/save JSON role definitions
- Merge multple roles with deduplication
- Remove permissions with filtering
-
Local file management
-
permission_filter.py (Filtering Engine)
- String pattern filtering (wildcards and regex)
- Permission type classification (control/data plane)
- Advanced filtering combinations
-
Permission extraction and merging
-
azure_client.py (Azure Integration)
- Azure SDK integration via Azure Identity
- Create custom roles in Azure
- Update existing roles
- List roles from subscription
- Delete roles
- Support for Azure CLI, Service Principal, and Managed Identity
Documentation¶
- README.md - Quick start guide with installation and usage
- PLATFORM_ENGINEER_GUIDE.md - Comprehensive guide for platform engineers with:
- Detailed installation instructions
- Authentication methods
- Basic and advanced usage
- Workflow scenarios
- Best practices
- Troubleshooting
- FEATURE_REFERENCE.md - Complete feature reference with:
- All commands documented
- Usage patterns
- Data model documentation
- Filtering syntax
- Integration examples
Configuration & Setup¶
- .env.example - Environment variable template for Azure auth
- setup.sh - Automated setup script
- .gitignore - Git configuration
- requirements.txt - Python dependencies
Examples & Testing¶
- examples/ directory with sample roles:
junior-developer.json- Restrictive permissionssenior-developer.json- Full permissions-
devops-developer.json- DevOps-focused permissions -
tests.py - Comprehensive unit tests for:
- Permission filtering
- Role management
- Merging operations
- Permission removal
📋 All Requirements Covered¶
✅ Start a role from scratch¶
azure-custom-role-tool create --name "MyRole" --description "Description"
✅ Cherry pick from other roles¶
azure-custom-role-tool merge --roles "source-role" --filter "Microsoft.Storage*"
✅ Merge one or more permissions from existing roles¶
azure-custom-role-tool merge --roles "role1,role2,role3"
✅ Filter by string in permission¶
azure-custom-role-tool merge --roles "source" --filter "*blobs*"
✅ Filter by control/data permissions¶
azure-custom-role-tool merge --roles "source" --filter-type data
✅ Remove permissions based on existing role¶
azure-custom-role-tool remove --filter "*delete*"
✅ Remove permissions with same filters¶
azure-custom-role-tool remove --filter "*delete*" --filter-type control
📁 Complete File Structure¶
azure-custom-role-tool/
├── README.md # Quick start guide
├── PLATFORM_ENGINEER_GUIDE.md # Comprehensive usage guide
├── FEATURE_REFERENCE.md # Complete feature documentation
├── requirements.txt # Python dependencies
├── .env.example # Environment template
├── .gitignore # Git configuration
├── setup.sh # Automated setup script
├── custom_role_designer.py # Main CLI tool (400+ lines)
├── role_manager.py # Role management (350+ lines)
├── permission_filter.py # Filtering engine (250+ lines)
├── azure_client.py # Azure integration (200+ lines)
├── tests.py # Unit tests (300+ lines)
├── examples/
│ ├── junior-developer.json # Example role
│ ├── senior-developer.json # Example role
│ └── devops-developer.json # Example role
└── roles/ # Local role storage
🚀 Quick Start¶
1. Installation¶
cd azure-custom-role-tool
bash setup.sh
Or manually:
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
az login
2. Create a Custom Role¶
azure-custom-role-tool create --name "MyRole" --description "My custom role"
azure-custom-role-tool merge --roles "senior-developer" --filter "Storage*"
azure-custom-role-tool remove --filter "*delete*"
azure-custom-role-tool save --name "my-role"
azure-custom-role-tool publish --name "my-role"
3. Interactive Mode¶
azure-custom-role-tool
🎨 Key Features¶
Powerful Filtering¶
- String patterns with wildcards:
Microsoft.Storage*,*read,*blobs* - Permission type filtering:
controlordataplane - Combinable filters for precision
Multiple Usage Modes¶
- Interactive mode: Menu-driven interface
- Command-line mode: Scripting and CI/CD
- Batch operations: Process multiple roles
Azure Integration¶
- Direct deployment to Azure
- Support for multiple authentication methods
- List and manage roles in subscription
Safe Operations¶
- Overwrite protection on saves
- Deduplication of permissions
- Preview before publishing
Well-Documented¶
- Inline code documentation
- Comprehensive user guides
- Example roles
- Unit tests
🔧 Technology Stack¶
- Language: Python 3.8+
- CLI Framework: Click
- UI Library: Rich
- Azure SDK: azure-identity, azure-mgmt-authorization
- Data Validation: Pydantic
- Testing: pytest
📊 Code Statistics¶
- Total Lines of Code: ~2,000+
- Core Modules: 4 (designer, manager, filter, azure_client)
- CLI Commands: 10+ main commands
- Test Coverage: Comprehensive unit tests
- Documentation: 3 major guides + inline docs
🎓 Usage Examples¶
Example 1: Create Developer Role¶
azure-custom-role-tool create --name "AppDeveloper" --description "App development"
azure-custom-role-tool merge --roles "junior-developer,reader"
azure-custom-role-tool merge --roles "senior-developer" --filter "Microsoft.Web*"
azure-custom-role-tool remove --filter "*delete*"
azure-custom-role-tool save --name "app-developer"
Example 2: Environment-Specific Roles¶
# Dev - permissive
azure-custom-role-tool create --name "DataEng-Dev"
azure-custom-role-tool merge --roles "senior-developer"
# Prod - restrictive
azure-custom-role-tool create --name "DataEng-Prod"
azure-custom-role-tool merge --roles "data-reader"
azure-custom-role-tool merge --roles "pipeline-operator"
azure-custom-role-tool remove --filter "*delete*"
Example 3: Team Permissions¶
azure-custom-role-tool create --name "CloudOpsTeam"
azure-custom-role-tool merge --roles "devops-developer,infrastructure-admin,monitoring-reader"
azure-custom-role-tool remove --filter "*delete*"
azure-custom-role-tool remove --filter "*deallocate*"
azure-custom-role-tool publish
🔐 Security Features¶
- Azure CLI authentication (no secrets in code)
- Service Principal support for CI/CD
- Managed Identity support
- Environmental variable configuration
- Role name validation
- Permission review before publishing
📚 Documentation Included¶
- README.md - Get started in 5 minutes
- PLATFORM_ENGINEER_GUIDE.md - Complete platform engineer guide with:
- Installation & setup
- Authentication methods
- Basic & advanced usage
- Workflow scenarios
- Best practices
- Troubleshooting
- FEATURE_REFERENCE.md - Exhaustive feature documentation
- Inline code comments - Throughout all modules
- Example roles - In examples/ directory
✅ Testing¶
Run the unit tests:
python -m pytest tests.py -v
Tests cover: - Permission filtering (data/control plane detection) - String pattern matching - Role creation and loading - Merging operations - Permission removal - Save/load functionality
🎯 Next Steps¶
- Installation: Follow README.md setup instructions
- Learning: Read PLATFORM_ENGINEER_GUIDE.md
- Reference: Check FEATURE_REFERENCE.md for all commands
- Examples: Review example roles in examples/ directory
- Integration: Integrate into CI/CD pipelines
💡 Use Cases¶
- ✅ Create least-privilege roles
- ✅ Manage role versions across environments
- ✅ Team permission management
- ✅ Automated role provisioning in CI/CD
- ✅ Role review and auditing
- ✅ Permission consolidation from multiple roles
🔄 Integration Points¶
- Git: Save roles in version control
- CI/CD: Publish roles via pipelines
- Azure: Direct subscription integration
- Scripts: Command-line automation
- Teams: Interactive mode for humans
📝 Notes¶
- All commands are stateful (current role tracking)
- Permissions are automatically deduplicated
- Role IDs are auto-generated but can be overridden
- Timestamps are automatically maintained
- Local roles can be easily committed to Git
Support¶
For issues or questions: 1. Check PLATFORM_ENGINEER_GUIDE.md troubleshooting section 2. Review example roles for patterns 3. Check inline code documentation 4. Contact platform engineering team
Status: ✅ Complete and Ready for Use
Version: 1.0
Date Created: January 2024