Skip to content

fix: add DefaultDetector with DFS-based RBAC cycle detection#1632

Merged
hsluoyz merged 6 commits intomasterfrom
copilot/implement-default-detector
Dec 31, 2025
Merged

fix: add DefaultDetector with DFS-based RBAC cycle detection#1632
hsluoyz merged 6 commits intomasterfrom
copilot/implement-default-detector

Conversation

Copy link
Contributor

Copilot AI commented Dec 31, 2025

fix: #1627

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@hsluoyz hsluoyz marked this pull request as ready for review December 31, 2025 12:48
Copilot AI and others added 2 commits December 31, 2025 12:53
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@github-actions
Copy link

github-actions bot commented Dec 31, 2025

Benchmark Comparison

Comparing base branch (53fb4e4)
vs PR branch (dc7d0e6)

goos: linux
goarch: amd64
pkg: github.com/casbin/casbin/v3
cpu: AMD EPYC 7763 64-Core Processor                
                                                 │ base-bench.txt │             pr-bench.txt             │
                                                 │     sec/op     │    sec/op     vs base                │
CachedRaw-4                                          17.63n ± ∞ ¹   17.67n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedBasicModel-4                                   173.0n ± ∞ ¹   172.3n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModel-4                                    170.8n ± ∞ ¹   175.0n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelSmall-4                               190.9n ± ∞ ¹   190.8n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMedium-4                              195.3n ± ∞ ¹   192.0n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelLarge-4                               161.6n ± ∞ ¹   160.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithResourceRoles-4                   170.3n ± ∞ ¹   172.5n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDomains-4                         178.5n ± ∞ ¹   188.2n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedABACModel-4                                    2.888µ ± ∞ ¹   2.877µ ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedKeyMatchModel-4                                190.1n ± ∞ ¹   188.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDeny-4                            171.9n ± ∞ ¹   173.0n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedPriorityModel-4                                169.3n ± ∞ ¹   175.4n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedWithEnforceContext-4                           299.4n ± ∞ ¹   303.7n ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMediumParallel-4                      176.1n ± ∞ ¹   170.7n ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicySmall-4                                     498.9n ± ∞ ¹   542.4n ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyMedium-4                                    551.5n ± ∞ ¹   546.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyLarge-4                                     571.3n ± ∞ ¹   565.3n ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicySmall-4                                     558.1n ± ∞ ¹   534.4n ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyMedium-4                                    693.2n ± ∞ ¹   682.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyLarge-4                                     1.314µ ± ∞ ¹   1.273µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicySmall-4                                  540.5n ± ∞ ¹   559.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyMedium-4                                 582.4n ± ∞ ¹   593.5n ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyLarge-4                                  648.1n ± ∞ ¹   669.0n ± ∞ ¹       ~ (p=1.000 n=1) ²
Raw-4                                                17.64n ± ∞ ¹   17.57n ± ∞ ¹       ~ (p=1.000 n=1) ²
BasicModel-4                                         3.579µ ± ∞ ¹   3.713µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModel-4                                          5.436µ ± ∞ ¹   5.691µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/small-4                               52.70µ ± ∞ ¹   52.86µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/medium-4                              529.0µ ± ∞ ¹   548.9µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/large-4                               5.953m ± ∞ ¹   5.958m ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSmall-4                                     60.01µ ± ∞ ¹   64.43µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelMedium-4                                    579.1µ ± ∞ ¹   597.3µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelLarge-4                                     5.990m ± ∞ ¹   6.151m ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithResourceRoles-4                         5.318µ ± ∞ ¹   5.518µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDomains-4                               5.072µ ± ∞ ¹   5.326µ ± ∞ ¹       ~ (p=1.000 n=1) ²
ABACModel-4                                          2.833µ ± ∞ ¹   2.937µ ± ∞ ¹       ~ (p=1.000 n=1) ²
ABACRuleModel-4                                      4.280m ± ∞ ¹   4.429m ± ∞ ¹       ~ (p=1.000 n=1) ²
KeyMatchModel-4                                      6.245µ ± ∞ ¹   6.441µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDeny-4                                  6.933µ ± ∞ ¹   7.202µ ± ∞ ¹       ~ (p=1.000 n=1) ²
PriorityModel-4                                      4.245µ ± ∞ ¹   4.294µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDomainPatternLarge-4                    14.73µ ± ∞ ¹   15.07µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerSmall-4                                   70.44µ ± ∞ ¹   72.43µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerMedium-4                                  751.6µ ± ∞ ¹   750.3µ ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerLarge-4                                   9.663m ± ∞ ¹   9.304m ± ∞ ¹       ~ (p=1.000 n=1) ²
BuildRoleLinksWithPatternLarge-4                     345.5m ± ∞ ¹   360.4m ± ∞ ¹       ~ (p=1.000 n=1) ²
BuildRoleLinksWithDomainPatternLarge-4               12.75m ± ∞ ¹   12.74m ± ∞ ¹       ~ (p=1.000 n=1) ²
BuildRoleLinksWithPatternAndDomainPatternLarge-4     355.6m ± ∞ ¹   366.5m ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithPatternLarge-4                            1.142µ ± ∞ ¹   1.151µ ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithDomainPatternLarge-4                      490.4n ± ∞ ¹   505.9n ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithPatternAndDomainPatternLarge-4            1.140µ ± ∞ ¹   1.163µ ± ∞ ¹       ~ (p=1.000 n=1) ²
ConcurrentHasLinkWithMatching-4                      2.083µ ± ∞ ¹   2.132µ ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                              5.538µ         5.626µ        +1.59%
¹ need >= 6 samples for confidence interval at level 0.95
² need >= 4 samples to detect a difference at alpha level 0.05

                                                 │ base-bench.txt │             pr-bench.txt              │
                                                 │      B/op      │     B/op       vs base                │
CachedRaw-4                                           0.000 ± ∞ ¹     0.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedBasicModel-4                                    104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModel-4                                     104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelSmall-4                                104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMedium-4                               104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelLarge-4                                96.00 ± ∞ ¹     96.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithResourceRoles-4                    104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDomains-4                          120.0 ± ∞ ¹     120.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedABACModel-4                                   1.505Ki ± ∞ ¹   1.504Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
CachedKeyMatchModel-4                                 152.0 ± ∞ ¹     152.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDeny-4                             104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedPriorityModel-4                                 104.0 ± ∞ ¹     104.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedWithEnforceContext-4                            240.0 ± ∞ ¹     240.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMediumParallel-4                       105.0 ± ∞ ¹     105.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicySmall-4                                      150.0 ± ∞ ¹     150.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyMedium-4                                     157.0 ± ∞ ¹     157.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyLarge-4                                      165.0 ± ∞ ¹     165.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicySmall-4                                      152.0 ± ∞ ¹     152.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyMedium-4                                     170.0 ± ∞ ¹     170.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyLarge-4                                      457.0 ± ∞ ¹     457.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicySmall-4                                   166.0 ± ∞ ¹     166.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyMedium-4                                  174.0 ± ∞ ¹     174.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyLarge-4                                   181.0 ± ∞ ¹     181.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
Raw-4                                                 0.000 ± ∞ ¹     0.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
BasicModel-4                                        1.474Ki ± ∞ ¹   1.475Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModel-4                                         2.018Ki ± ∞ ¹   2.017Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelSizes/small-4                              19.82Ki ± ∞ ¹   19.80Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelSizes/medium-4                             187.2Ki ± ∞ ¹   187.1Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelSizes/large-4                              1.813Mi ± ∞ ¹   1.814Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelSmall-4                                    19.89Ki ± ∞ ¹   19.88Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelMedium-4                                   190.1Ki ± ∞ ¹   190.2Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelLarge-4                                    1.844Mi ± ∞ ¹   1.843Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelWithResourceRoles-4                        2.671Ki ± ∞ ¹   2.673Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelWithDomains-4                              1.784Ki ± ∞ ¹   1.787Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
ABACModel-4                                         1.498Ki ± ∞ ¹   1.501Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
ABACRuleModel-4                                     1.268Mi ± ∞ ¹   1.267Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
KeyMatchModel-4                                     2.995Ki ± ∞ ¹   3.001Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelWithDeny-4                                 2.426Ki ± ∞ ¹   2.424Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
PriorityModel-4                                     1.722Ki ± ∞ ¹   1.724Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelWithDomainPatternLarge-4                   8.490Ki ± ∞ ¹   8.490Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerSmall-4                                  11.67Ki ± ∞ ¹   11.67Ki ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerMedium-4                                 123.0Ki ± ∞ ¹   123.0Ki ± ∞ ¹       ~ (p=1.000 n=1) ³
RoleManagerLarge-4                                  1.287Mi ± ∞ ¹   1.287Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
BuildRoleLinksWithPatternLarge-4                    86.03Mi ± ∞ ¹   86.01Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
BuildRoleLinksWithDomainPatternLarge-4              4.495Mi ± ∞ ¹   4.488Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
BuildRoleLinksWithPatternAndDomainPatternLarge-4    87.75Mi ± ∞ ¹   87.66Mi ± ∞ ¹       ~ (p=1.000 n=1) ³
HasLinkWithPatternLarge-4                             177.0 ± ∞ ¹     177.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithDomainPatternLarge-4                       80.00 ± ∞ ¹     80.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithPatternAndDomainPatternLarge-4             177.0 ± ∞ ¹     177.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
ConcurrentHasLinkWithMatching-4                       622.0 ± ∞ ¹     622.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                                         ⁴                  +0.00%               ⁴
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal
³ need >= 4 samples to detect a difference at alpha level 0.05
⁴ summaries must be >0 to compute geomean

                                                 │ base-bench.txt │             pr-bench.txt             │
                                                 │   allocs/op    │  allocs/op    vs base                │
CachedRaw-4                                           0.000 ± ∞ ¹    0.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedBasicModel-4                                    4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModel-4                                     4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelSmall-4                                4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMedium-4                               4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelLarge-4                                3.000 ± ∞ ¹    3.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithResourceRoles-4                    4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDomains-4                          4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedABACModel-4                                     18.00 ± ∞ ¹    18.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedKeyMatchModel-4                                 4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelWithDeny-4                             4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedPriorityModel-4                                 4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedWithEnforceContext-4                            5.000 ± ∞ ¹    5.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
CachedRBACModelMediumParallel-4                       4.000 ± ∞ ¹    4.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicySmall-4                                      6.000 ± ∞ ¹    6.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyMedium-4                                     6.000 ± ∞ ¹    6.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasPolicyLarge-4                                      7.000 ± ∞ ¹    7.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicySmall-4                                      6.000 ± ∞ ¹    6.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyMedium-4                                     7.000 ± ∞ ¹    7.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
AddPolicyLarge-4                                      9.000 ± ∞ ¹    9.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicySmall-4                                   7.000 ± ∞ ¹    7.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyMedium-4                                  7.000 ± ∞ ¹    7.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
RemovePolicyLarge-4                                   8.000 ± ∞ ¹    8.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
Raw-4                                                 0.000 ± ∞ ¹    0.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
BasicModel-4                                          17.00 ± ∞ ¹    17.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModel-4                                           35.00 ± ∞ ¹    35.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/small-4                                480.0 ± ∞ ¹    480.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/medium-4                              4.828k ± ∞ ¹   4.828k ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelSizes/large-4                               48.20k ± ∞ ¹   48.25k ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelSmall-4                                      615.0 ± ∞ ¹    615.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelMedium-4                                    6.018k ± ∞ ¹   6.018k ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelLarge-4                                     60.33k ± ∞ ¹   60.30k ± ∞ ¹       ~ (p=1.000 n=1) ³
RBACModelWithResourceRoles-4                          28.00 ± ∞ ¹    28.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDomains-4                                25.00 ± ∞ ¹    25.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
ABACModel-4                                           17.00 ± ∞ ¹    17.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
ABACRuleModel-4                                      40.09k ± ∞ ¹   40.09k ± ∞ ¹       ~ (p=1.000 n=1) ²
KeyMatchModel-4                                       37.00 ± ∞ ¹    37.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDeny-4                                   49.00 ± ∞ ¹    49.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
PriorityModel-4                                       22.00 ± ∞ ¹    22.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RBACModelWithDomainPatternLarge-4                     72.00 ± ∞ ¹    72.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerSmall-4                                    797.0 ± ∞ ¹    797.0 ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerMedium-4                                  8.741k ± ∞ ¹   8.741k ± ∞ ¹       ~ (p=1.000 n=1) ²
RoleManagerLarge-4                                   89.74k ± ∞ ¹   89.74k ± ∞ ¹       ~ (p=1.000 n=1) ²
BuildRoleLinksWithPatternLarge-4                     3.600M ± ∞ ¹   3.600M ± ∞ ¹       ~ (p=1.000 n=1) ³
BuildRoleLinksWithDomainPatternLarge-4               145.2k ± ∞ ¹   145.2k ± ∞ ¹       ~ (p=1.000 n=1) ³
BuildRoleLinksWithPatternAndDomainPatternLarge-4     3.679M ± ∞ ¹   3.679M ± ∞ ¹       ~ (p=1.000 n=1) ³
HasLinkWithPatternLarge-4                             13.00 ± ∞ ¹    13.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithDomainPatternLarge-4                       5.000 ± ∞ ¹    5.000 ± ∞ ¹       ~ (p=1.000 n=1) ²
HasLinkWithPatternAndDomainPatternLarge-4             13.00 ± ∞ ¹    13.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
ConcurrentHasLinkWithMatching-4                       21.00 ± ∞ ¹    21.00 ± ∞ ¹       ~ (p=1.000 n=1) ²
geomean                                                         ⁴                 +0.00%               ⁴
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal
³ need >= 4 samples to detect a difference at alpha level 0.05
⁴ summaries must be >0 to compute geomean

🤖 This comment will be automatically updated with the latest benchmark results.

…e error handling

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement DefaultDetector with RBAC cycle detection Implement DefaultDetector with DFS-based RBAC cycle detection Dec 31, 2025
Copilot AI requested a review from hsluoyz December 31, 2025 13:02
@hsluoyz
Copy link
Member

hsluoyz commented Dec 31, 2025

@copilot fix failed CI test:

<html>
<body>
<!--StartFragment--><div class="mt-1 mb-3 px-3" style="box-sizing: border-box; margin-top: 4px !important; margin-bottom: 16px !important; padding-right: 16px !important; padding-left: 16px !important; color: rgb(31, 35, 40); font-family: -apple-system, BlinkMacSystemFont, &quot;Segoe UI&quot;, &quot;Noto Sans&quot;, Helvetica, Arial, sans-serif, &quot;Apple Color Emoji&quot;, &quot;Segoe UI Emoji&quot;; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="mx-0 mx-md-1" style="box-sizing: border-box; margin-right: 4px !important; margin-left: 4px !important;"><h2 class="text-bold h4" style="box-sizing: border-box; margin-top: 0px; margin-bottom: 0px; font-size: 16px !important; font-weight: 600 !important;">Annotations</h2><div class="color-fg-muted text-small" style="box-sizing: border-box; color: rgb(89, 99, 110) !important; font-size: 12px !important;">3 errors and 2 warnings</div></div></div>
golangciissues found
--
golangci: detector/default_detector.go#L56ST1005: error strings should not be capitalized (stylecheck)
golangci: detector/default_detector_test.go#L242Comment should end in a period (godot)

<!--EndFragment-->
</body>
</html>Annotations
3 errors and 2 warnings
[golangci](https://github.com/casbin/casbin/actions/runs/20619440511/job/59218788550#step:4:28)
issues found
[golangci: detector/default_detector.go#L56](https://github.com/casbin/casbin/pull/1632/files#annotation_43560947816)
ST1005: error strings should not be capitalized (stylecheck)
[golangci: detector/default_detector_test.go#L242](https://github.com/casbin/casbin/pull/1632/files#annotation_43560947820)
Comment should end in a period (godot)

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot fix failed CI test:

...

Fixed in commit 8f5984e:

  1. Changed error string to lowercase: "cycle detected" (stylecheck compliance)
  2. Added period to comment (godot compliance)

@knyk-dev
Copy link
Contributor

Please review the Check method in detector/default_detector.go and implement a defensive nil check.

Requirements:

  1. At the very beginning of the Check function, verify if the passed rbac.RoleManager (rm) is nil.
  2. If rm is nil, return a descriptive error immediately (e.g., "role manager cannot be nil") instead of proceeding.
  3. This is to prevent runtime panics during the subsequent type assertion (rm.(rangeableRM)) or method calls.

@hsluoyz
Copy link
Member

hsluoyz commented Dec 31, 2025

@copilot Please review the Check method in detector/default_detector.go and implement a defensive nil check.

Requirements:

  1. At the very beginning of the Check function, verify if the passed rbac.RoleManager (rm) is nil.
  2. If rm is nil, return a descriptive error immediately (e.g., "role manager cannot be nil") instead of proceeding.
  3. This is to prevent runtime panics during the subsequent type assertion (rm.(rangeableRM)) or method calls.

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 31, 2025

@copilot Please review the Check method in detector/default_detector.go and implement a defensive nil check.

Requirements:
...

Implemented in commit dc7d0e6:

  1. Added nil check at the beginning of the Check method
  2. Returns error "role manager cannot be nil" if rm is nil
  3. Added test TestDefaultDetector_NilRoleManager to verify the nil check works correctly

@hsluoyz hsluoyz changed the title Implement DefaultDetector with DFS-based RBAC cycle detection feat: add DefaultDetector with DFS-based RBAC cycle detection Dec 31, 2025
@hsluoyz hsluoyz changed the title feat: add DefaultDetector with DFS-based RBAC cycle detection fix: add DefaultDetector with DFS-based RBAC cycle detection Dec 31, 2025
@hsluoyz hsluoyz merged commit 68963d0 into master Dec 31, 2025
5 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] Implement DefaultDetector with RBAC cycle detection

4 participants