Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion internal/service/access_controls_rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func (rule *UserAllowedRule) Evaluate(ctx *ACLContext) Effect {
rule.Log.App.Debug().Str("username", ctx.UserContext.GetUsername()).Msg("User is in users block list, denying access")
return EffectDeny
}
return EffectAllow
}

rule.Log.App.Debug().Msg("Checking users allow list")
Expand All @@ -78,6 +77,9 @@ func (rule *UserAllowedRule) Evaluate(ctx *ACLContext) Effect {

if err != nil {
if errors.Is(err, utils.ErrFilterEmpty) {
if ctx.ACLs.Users.Block != "" {
return EffectAllow
}
return EffectAbstain
}
rule.Log.App.Warn().Err(err).Str("item", ctx.UserContext.GetUsername()).Msg("Invalid entry in users allow list")
Expand Down
60 changes: 60 additions & 0 deletions internal/service/access_controls_rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,66 @@ func TestUserAllowedRule(t *testing.T) {
},
expected: EffectDeny,
},
{
name: "denies user when both block and allow configured and user in block list",
ctx: &ACLContext{
ACLs: &model.App{
Users: model.AppUsers{Block: "evil", Allow: "alice,bob"},
},
UserContext: &model.UserContext{
Provider: model.ProviderLocal,
Local: &model.LocalContext{
BaseContext: model.BaseContext{Username: "evil"},
},
},
},
expected: EffectDeny,
},
{
name: "allows user when both block and allow configured and user in allow list",
ctx: &ACLContext{
ACLs: &model.App{
Users: model.AppUsers{Block: "evil", Allow: "alice,bob"},
},
UserContext: &model.UserContext{
Provider: model.ProviderLocal,
Local: &model.LocalContext{
BaseContext: model.BaseContext{Username: "alice"},
},
},
},
expected: EffectAllow,
},
{
name: "denies user when both block and allow configured and user in neither",
ctx: &ACLContext{
ACLs: &model.App{
Users: model.AppUsers{Block: "evil", Allow: "alice,bob"},
},
UserContext: &model.UserContext{
Provider: model.ProviderLocal,
Local: &model.LocalContext{
BaseContext: model.BaseContext{Username: "charlie"},
},
},
},
expected: EffectDeny,
},
{
name: "denies user when both block and allow match same user",
ctx: &ACLContext{
ACLs: &model.App{
Users: model.AppUsers{Block: "alice", Allow: "alice,bob"},
},
UserContext: &model.UserContext{
Provider: model.ProviderLocal,
Local: &model.LocalContext{
BaseContext: model.BaseContext{Username: "alice"},
},
},
},
expected: EffectDeny,
},
}

for _, tt := range tests {
Expand Down