feat: implement path block and user block

Fixes #313
This commit is contained in:
Stavros
2025-08-29 16:19:44 +03:00
parent 598abc5fe1
commit 26deb80f4c
2 changed files with 29 additions and 10 deletions

View File

@@ -112,7 +112,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
return return
} }
authEnabled, err := controller.Auth.IsAuthEnabled(uri, labels.Path.Allow) authEnabled, err := controller.Auth.IsAuthEnabled(uri, labels.Path)
if err != nil { if err != nil {
log.Error().Err(err).Msg("Failed to check if auth is enabled for resource") log.Error().Err(err).Msg("Failed to check if auth is enabled for resource")

View File

@@ -289,6 +289,13 @@ func (auth *AuthService) IsResourceAllowed(c *gin.Context, context config.UserCo
return utils.CheckFilter(labels.OAuth.Whitelist, context.Email) return utils.CheckFilter(labels.OAuth.Whitelist, context.Email)
} }
if labels.Users.Block != "" {
log.Debug().Msg("Checking blocked users")
if utils.CheckFilter(labels.Users.Block, context.Username) {
return false
}
}
log.Debug().Msg("Checking users") log.Debug().Msg("Checking users")
return utils.CheckFilter(labels.Users.Allow, context.Username) return utils.CheckFilter(labels.Users.Allow, context.Username)
} }
@@ -316,19 +323,31 @@ func (auth *AuthService) IsInOAuthGroup(c *gin.Context, context config.UserConte
return false return false
} }
func (auth *AuthService) IsAuthEnabled(uri string, pathAllow string) (bool, error) { func (auth *AuthService) IsAuthEnabled(uri string, path config.PathLabels) (bool, error) {
if pathAllow == "" { // Check for block list
return true, nil if path.Block != "" {
regex, err := regexp.Compile(path.Block)
if err != nil {
return true, err
}
if !regex.MatchString(uri) {
return false, nil
}
} }
regex, err := regexp.Compile(pathAllow) // Check for allow list
if path.Allow != "" {
regex, err := regexp.Compile(path.Allow)
if err != nil { if err != nil {
return true, err return true, err
} }
if regex.MatchString(uri) { if regex.MatchString(uri) {
return false, nil return false, nil
}
} }
return true, nil return true, nil