Apply bottom-up and top-down role mining techniques to discover optimal RBAC roles from existing user-permission assignments, reducing role explosion and enforcing least privilege.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Apply bottom-up and top-down role mining techniques to discover optimal RBAC roles from existing user-permission assignments, reducing role explosion and enforcing least privilege.
Role mining is the process of analyzing existing user-permission assignments to discover optimal roles for a Role-Based Access Control (RBAC) system. Organizations accumulate excessive permissions over time through job changes, project assignments, and ad-hoc access grants, leading to "role explosion" where thousands of granular roles exist with significant overlap. Role mining uses data analysis -- including clustering algorithms, formal concept analysis, and graph-based methods -- to consolidate permissions into a minimal set of roles that accurately represent business functions while enforcing least privilege.
When to Use
When deploying or configuring building role mining for rbac optimization capabilities in your environment
When establishing security controls aligned to compliance requirements
When building or improving security architecture for this domain
When conducting security assessments that require this implementation
Common Misconfigurations & Verification
Coverage gamed by over-broad roles: pushing core_permissions threshold down (e.g. >50% instead of >80%) inflates coverage to "95%" by handing every cluster member permissions only half of them actually use. Verify deviation/extra-permission rate stays <5% alongside the coverage figure — high coverage with high deviation means the role grants more than people hold.
Jaccard on a sparse matrix: with a low-density UPA matrix, Jaccard distance collapses dissimilar users into one cluster, producing a giant "catch-all" role. Confirm silhouette score is reported per-k and inspect the largest role for unrelated job codes.
Outliers folded into roles: admin/break-glass accounts with unique permission sets get absorbed, leaking privileged entitlements into a standard role. Verify outlier detection runs first and high-risk permissions (Domain Admin, prod-write) are excluded from auto-mined roles.
No business validation: mined roles map to data clusters, not job functions, so they pass metrics but fail audit. Confirm each role has a named business owner and job-code mapping.
Verification: recompute effective access as R × P and diff against the original UPA matrix — every removed permission must be an intended least-privilege reduction, every added permission flagged; re-run evaluate_role_set and assert coverage >95% AND deviation <5% together.
Prerequisites
Export of current user-permission assignments (CSV/database)
Identity governance platform or directory service access
Python 3.9+ with pandas, scikit-learn, numpy
Understanding of organizational structure and job functions
Stakeholder access for role validation workshops
Core Concepts
Role Mining Approaches
Approach
Description
Best For
Bottom-Up
Analyze existing permissions to discover common patterns
Large datasets with organic permission growth
Top-Down
Design roles from business requirements and job descriptions
Greenfield RBAC or organizational restructuring
Hybrid
Combine bottom-up analysis with top-down business validation
Most production environments
Role Mining Algorithms
1. Permission Clustering: Group users with similar permission sets using k-means or hierarchical clustering. Users in the same cluster share a common role.
2. Formal Concept Analysis (FCA): Mathematical framework that identifies complete set of concepts (user groups sharing exact permission sets) from a binary user-permission matrix.
3. Graph-Based Mining: Model users and permissions as a bipartite graph, then find dense subgraphs representing candidate roles.
4. Boolean Matrix Decomposition: Decompose the user-permission matrix U into U ≈ R × P where R maps users to roles and P maps roles to permissions.
Role Mining Metrics
Metric
Formula
Target
Role Count
Total distinct roles after mining
Minimize
Coverage
Permissions explained by mined roles / Total permissions
> 95%
Weighted Structural Complexity (WSC)
Sum of role-user + role-permission assignments
Minimize
Deviation
Extra permissions not covered by assigned roles
< 5%
Workflow
Step 1: Extract User-Permission Data
Collect the current access state from all identity sources:
from sklearn.cluster import AgglomerativeClustering
from sklearn.metrics import silhouette_score
deffind_optimal_clusters(matrix, max_k=50):
"""Find optimal number of roles using silhouette analysis."""
scores = []
for k inrange(2, min(max_k, matrix.shape[0])):
clustering = AgglomerativeClustering(
n_clusters=k, metric="jaccard", linkage="average"
)
labels = clustering.fit_predict(matrix)
score = silhouette_score(matrix, labels, metric="jaccard")
scores.append((k, score))
optimal_k = max(scores, key=lambda x: x[1])[0]
return optimal_k, scores
defmine_roles_clustering(upa_matrix, n_clusters):
"""Mine roles using hierarchical clustering on Jaccard distance."""
clustering = AgglomerativeClustering(
n_clusters=n_clusters, metric="jaccard", linkage="average"
)
user_matrix = upa_matrix.values
labels = clustering.fit_predict(user_matrix)
roles = {}
for cluster_id inrange(n_clusters):
cluster_users = upa_matrix.index[labels == cluster_id]
cluster_permissions = upa_matrix.loc[cluster_users]
# Core role = permissions held by >80% of cluster members
permission_frequency = cluster_permissions.mean()
core_permissions = permission_frequency[permission_frequency >= 0.8].index.tolist()
roles[f"Role_{cluster_id}"] = {
"permissions": core_permissions,
"user_count": len(cluster_users),
"users": cluster_users.tolist(),
"coverage": permission_frequency[permission_frequency >= 0.8].mean()
}
return roles, labels
Step 3: Formal Concept Analysis
defmine_roles_fca(upa_matrix, min_support=3):
"""Mine roles using Formal Concept Analysis (frequent closed itemsets)."""from itertools import combinations
users = upa_matrix.index.tolist()
permissions = upa_matrix.columns.tolist()
concepts = []
# Find all maximal permission sets shared by at least min_support usersfor size inrange(len(permissions), 0, -1):
for perm_combo in combinations(permissions, size):
perm_set = set(perm_combo)
# Find users who have ALL permissions in this set
matching_users = []
for user in users:
user_perms = set(upa_matrix.columns[upa_matrix.loc[user] == 1])
if perm_set.issubset(user_perms):
matching_users.append(user)
iflen(matching_users) >= min_support:
# Check if this is a closed concept (no superset with same extent)
is_closed = Truefor concept in concepts:
ifset(matching_users) == set(concept["users"]) and \
perm_set.issubset(set(concept["permissions"])):
is_closed = Falsebreakif is_closed:
concepts.append({
"permissions": list(perm_set),
"users": matching_users,
"support": len(matching_users)
})
iflen(concepts) > 100: # Limit for performancebreakreturn concepts
Step 4: Evaluate and Select Roles
defevaluate_role_set(roles, upa_matrix):
"""Evaluate the quality of a mined role set."""
total_assignments = upa_matrix.values.sum()
covered_assignments = 0
extra_assignments = 0for role_name, role_data in roles.items():
role_perms = set(role_data["permissions"])
for user in role_data["users"]:
user_perms = set(upa_matrix.columns[upa_matrix.loc[user] == 1])
covered = role_perms.intersection(user_perms)
extra = role_perms - user_perms
covered_assignments += len(covered)
extra_assignments += len(extra)
metrics = {
"total_roles": len(roles),
"total_assignments": total_assignments,
"covered_assignments": covered_assignments,
"coverage_rate": covered_assignments / total_assignments if total_assignments else0,
"extra_permissions": extra_assignments,
"deviation_rate": extra_assignments / (covered_assignments + extra_assignments) if (covered_assignments + extra_assignments) else0,
"avg_role_size": np.mean([len(r["permissions"]) for r in roles.values()]),
"avg_users_per_role": np.mean([r["user_count"] for r in roles.values()]),
}
return metrics
Step 5: Business Validation
After mining candidate roles:
Map mined roles to business functions (department, job title)
Conduct workshops with business unit managers to validate role definitions
Identify outlier permissions that indicate misconfiguration
Refine roles based on feedback and re-evaluate metrics
Document role definitions with business justification
Validation Checklist
User-permission matrix extracted from all identity sources