Permission Set analysis, hierarchy viewer, and "Who has X?" auditing...
Salesforce Permission Set analysis, visualization, and auditing tool
Use sf-permissions when the user needs to:
| Capability | Description |
|---|---|
| Hierarchy Viewer | Visualize all PS/PSG in an org as ASCII trees |
| Permission Detector | Find which PS/PSG grant a specific permission |
| User Analyzer | Show all permissions assigned to a user |
| CSV Exporter | Export PS configuration for documentation |
| Metadata Generator | Generate Permission Set XML (delegates to sf-metadata) |
| Tooling API | Query tab settings, system permissions via Tooling API |
# Python dependencies
pip install simple-salesforce rich
# Salesforce CLI (for authentication)
sf --version # Must be installed and authenticated
This skill reuses existing sf CLI authentication. Ensure you're authenticated:
# Check current org
sf org display
# Authenticate if needed
sf org login web --alias myorg
When a user asks about permissions, identify which capability they need:
| User Says | Capability | Function |
|---|---|---|
| "Show permission hierarchy" | Hierarchy Viewer | hierarchy_viewer.py |
| "Who has access to Account?" | Permission Detector | permission_detector.py |
| "What permissions does John have?" | User Analyzer | user_analyzer.py |
| "Export Sales_Manager PS to CSV" | CSV Exporter | permission_exporter.py |
| "Generate PS XML with these permissions" | Metadata Generator | permission_generator.py |
# List available orgs
sf org list
# Default to current target org, or ask user to specify
sf org display --target-org <alias>
# Run from sf-permissions/scripts/
python -c "
from auth import get_sf_connection
sf = get_sf_connection('myorg') # or None for default
print(f'Connected to: {sf.sf_instance}')
"
Purpose: Show all Permission Sets and Permission Set Groups in the org
cd ~/.claude/plugins/marketplaces/sf-skills/sf-permissions/scripts
python cli.py hierarchy [--target-org ALIAS] [--format ascii|mermaid]
Output Example:
š¦ ORG PERMISSION HIERARCHY
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
š Permission Set Groups (3)
āāā š Sales_Cloud_User (Active)
ā āāā View_All_Accounts
ā āāā Edit_Opportunities
ā āāā Run_Reports
āāā š Service_Cloud_User (Active)
ā āāā Case_Management
āāā š Marketing_User (Outdated)
āāā Campaign_Access
š Standalone Permission Sets (12)
āāā Admin_Tools
āāā API_Access
āāā ... (10 more)
Purpose: Find which PS/PSG grant a specific permission
Supported Permission Types:
object - Object CRUD (Create, Read, Update, Delete, ViewAll, ModifyAll)field - Field-Level Security (Read, Edit)apex - Apex Class accessvf - Visualforce Page accessflow - Flow accesscustom - Custom Permissiontab - Tab visibilitycd ~/.claude/plugins/marketplaces/sf-skills/sf-permissions/scripts
# Object permissions
python cli.py detect object Account --access delete
python cli.py detect object Opportunity --access create,read,edit
# Field permissions
python cli.py detect field Account.AnnualRevenue --access edit
# Apex class access
python cli.py detect apex MyApexClass
# Custom permission
python cli.py detect custom Can_Approve_Expenses
# Tab visibility
python cli.py detect tab Account
Output Example:
š PERMISSION DETECTION RESULTS
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
Query: Delete access to Account
Found in 3 Permission Sets:
š Permission Set ā Group Membership ā Users
āāāāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāāāāāāāāāāāāāāāāāāāā¼āāāāāāā
System_Administrator ā ā Standalone ā 2
Sales_Operations_Manager ā ā Sales_Cloud_PSG ā 5
Data_Steward ā ā Data_Management_PSG ā 1
Total users with this access: 8
Purpose: Show all permissions assigned to a specific user
cd ~/.claude/plugins/marketplaces/sf-skills/sf-permissions/scripts
python cli.py user "john.smith@company.com"
python cli.py user 005xx000001234AAA # User ID also works
Output Example:
š¤ USER PERMISSION ANALYSIS
āāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāāā
User: John Smith (john.smith@company.com)
Profile: Standard User
š Via Permission Set Groups (2)
āāā š Sales_Cloud_User
ā āāā View_All_Accounts ā
ā āāā Edit_Opportunities ā
ā āāā Run_Reports ā
āāā š Service_Cloud_User
āāā Case_Management ā
š Direct Permission Sets (3)
āāā API_Access
āāā Custom_App_Access
āāā Einstein_Analytics_User
Purpose: Export PS configuration to CSV for documentation/auditing
cd ~/.claude/plugins/marketplaces/sf-skills/sf-permissions/scripts
python cli.py export Sales_Manager --output /tmp/sales_manager.csv
CSV Output Columns:
Purpose: Get available objects, fields, Apex classes for autocomplete/validation
from metadata_fetcher import (
get_available_objects,
get_object_fields,
get_apex_classes,
get_custom_permissions
)
sf = get_sf_connection()
objects = get_available_objects(sf)
fields = get_object_fields(sf, 'Account')
Uses the rich library for professional terminal output:
For embedding in Markdown/documentation:
python cli.py hierarchy --format mermaid > hierarchy.md
graph TD
subgraph Permission Set Groups
PSG1[Sales_Cloud_User]
PSG2[Service_Cloud_User]
end
subgraph Permission Sets
PS1[View_All_Accounts]
PS2[Edit_Opportunities]
PS3[Case_Management]
end
PSG1 --> PS1
PSG1 --> PS2
PSG2 --> PS3
If the user wants to create a new Permission Set based on analysis:
# Generate Permission Set XML
python cli.py generate \
--name "New_Sales_PS" \
--label "New Sales Permission Set" \
--objects Account:crud,Opportunity:cru \
--fields Account.AnnualRevenue:rw \
--apex MyApexClass,AnotherClass \
--output /tmp/New_Sales_PS.permissionset-meta.xml
Or delegate to sf-metadata skill for more complex generation.
-- All Permission Sets (excluding PSGs)
SELECT Id, Name, Label, Description, IsOwnedByProfile
FROM PermissionSet
WHERE IsOwnedByProfile = false AND Type != 'Group'
-- All Permission Set Groups
SELECT Id, DeveloperName, MasterLabel, Status, Description
FROM PermissionSetGroup
-- PSG Components (which PS are in which PSG)
SELECT PermissionSetGroupId, PermissionSetGroup.DeveloperName,
PermissionSetId, PermissionSet.Name
FROM PermissionSetGroupComponent
-- User's PS Assignments
SELECT AssigneeId, PermissionSetId, PermissionSet.Name,
PermissionSetGroupId, PermissionSetGroup.DeveloperName
FROM PermissionSetAssignment
WHERE AssigneeId = '005...'
-- Object permissions for a specific PS
SELECT SobjectType, PermissionsCreate, PermissionsRead,
PermissionsEdit, PermissionsDelete,
PermissionsViewAllRecords, PermissionsModifyAllRecords
FROM ObjectPermissions
WHERE ParentId = '0PS...'
-- Find PS with specific object access
SELECT Parent.Name, Parent.Label, SobjectType,
PermissionsCreate, PermissionsRead, PermissionsEdit, PermissionsDelete
FROM ObjectPermissions
WHERE SobjectType = 'Account' AND PermissionsDelete = true
-- Field permissions for a specific PS
SELECT Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE ParentId = '0PS...'
-- Find PS with specific field access
SELECT Parent.Name, Field, PermissionsRead, PermissionsEdit
FROM FieldPermissions
WHERE Field = 'Account.AnnualRevenue' AND PermissionsEdit = true
-- Setup entity access for a PS
SELECT SetupEntityType, SetupEntityId
FROM SetupEntityAccess
WHERE ParentId = '0PS...'
-- Find PS with access to specific Apex class
SELECT Parent.Name, Parent.Label
FROM SetupEntityAccess
WHERE SetupEntityType = 'ApexClass'
AND SetupEntityId IN (SELECT Id FROM ApexClass WHERE Name = 'MyClass')
-- Custom permissions
SELECT Parent.Name
FROM SetupEntityAccess
WHERE SetupEntityType = 'CustomPermission'
AND SetupEntityId IN (SELECT Id FROM CustomPermission WHERE DeveloperName = 'Can_Approve')
User: "Who has delete access to the Account object?"
1. Run permission detector for object:Account with delete access
2. For each PS found, get PSG membership
3. For each PS/PSG, count assigned users
4. Display results in table format
User: "Why can't John edit Opportunities?"
1. Run user analyzer for john@company.com
2. Check if any PS grants Opportunity edit
3. If not, suggest which PS/PSG to assign
4. Check for conflicting profile restrictions
User: "Export the Sales_Manager PS for documentation"
1. Run exporter for Sales_Manager
2. Generate CSV with all permissions
3. Optionally generate Mermaid diagram showing PSG membership
Re-authenticate with sf CLI:
sf org login web --alias myorg
Large orgs may have thousands of PS. Use filters:
# Filter by name pattern
sf.query("SELECT Id, Name FROM PermissionSet WHERE Name LIKE 'Sales%'")
Some metadata (like tab settings) requires Tooling API:
from tooling_api import tooling_query
results = tooling_query(sf, "SELECT Name, Visibility FROM PermissionSetTabSetting")
| Skill | Integration |
|---|---|
sf-metadata |
Generate Permission Set XML from analysis results |
sf-apex |
Identify Apex classes to grant access to |
sf-deploy |
Deploy generated Permission Sets |
sf-data |
Query user assignments in bulk |
User: "Give me a complete picture of permissions in my org"
Claude:
1. Runs hierarchy viewer to show all PS/PSG
2. Identifies PSGs with "Outdated" status
3. Counts users per PS
4. Generates Mermaid diagram for documentation
User: "Find all PS that grant ModifyAllData"
Claude:
1. Queries PermissionSet for PermissionsModifyAllData = true
2. Lists PS names and assigned user counts
3. Flags any non-admin PS with this powerful permission
User: "Create a PS for contractors with read-only Account access"
Claude:
1. Uses permission_generator.py to create XML
2. Sets Account object to Read-only (no Create/Edit/Delete)
3. Outputs .permissionset-meta.xml file