Skip to content

Commit 1571e4f

Browse files
committed
fix: pass domains in ConditionalRoleManager transitive link check
1 parent f64a3c0 commit 1571e4f

3 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
p, role_top, domainx, data_top, read
2+
p, role_solo, domainx, data_solo, read
3+
g, alice, role_mid, domainx, _, _
4+
g, role_mid, role_top, domainx, 0000-01-01 00:00:00, 0000-01-02 00:00:00
5+
g, alice, role_solo, domainx, 0000-01-01 00:00:00, 0000-01-02 00:00:00

model_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,19 @@ func TestTemporalRolesModelWithDomain(t *testing.T) {
769769
testDomainEnforce(t, e, "alice", "domain_not_exist", "data8", "write", false)
770770
}
771771

772+
func TestTemporalRolesModelWithDomainTransitive(t *testing.T) {
773+
e, _ := NewEnforcer("examples/rbac_with_domain_temporal_roles_model.conf", "examples/rbac_with_domain_temporal_roles_transitive_policy.csv")
774+
775+
e.AddNamedDomainLinkConditionFunc("g", "alice", "role_mid", "domainx", util.TimeMatchFunc)
776+
e.AddNamedDomainLinkConditionFunc("g", "role_mid", "role_top", "domainx", util.TimeMatchFunc)
777+
e.AddNamedDomainLinkConditionFunc("g", "alice", "role_solo", "domainx", util.TimeMatchFunc)
778+
779+
// single-hop expired link -> correctly denied (control)
780+
testDomainEnforce(t, e, "alice", "domainx", "data_solo", "read", false)
781+
// two-hop chain whose 2nd link is expired -> must be denied as well
782+
testDomainEnforce(t, e, "alice", "domainx", "data_top", "read", false)
783+
}
784+
772785
func TestReBACModel(t *testing.T) {
773786
e, _ := NewEnforcer("examples/rebac_model.conf", "examples/rebac_policy.csv")
774787

rbac/default-role-manager/role_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -817,7 +817,7 @@ func (crm *ConditionalRoleManager) hasLinkHelper(targetName string, roles map[st
817817
})
818818
}
819819

820-
return crm.hasLinkHelper(targetName, nextRoles, level-1)
820+
return crm.hasLinkHelper(targetName, nextRoles, level-1, domains...)
821821
}
822822

823823
func (crm *ConditionalRoleManager) getNextRoles(currentRole, nextRole *Role, domains []string, nextRoles map[string]*Role) bool {

0 commit comments

Comments
 (0)