diff --git a/pkg/auth/authenticator.go b/pkg/auth/authenticator.go index f87455b..e89f043 100644 --- a/pkg/auth/authenticator.go +++ b/pkg/auth/authenticator.go @@ -2,7 +2,9 @@ package auth import ( "context" + "net" "net/http" + "regexp" "sync" "github.com/go-logr/logr" @@ -230,3 +232,32 @@ func NewAuthenticator(logger logr.Logger) (*Authenticator, error) { } return &a, nil } + +func CheckIP(ip string, ipAllowList []string) (bool, error) { + clientIP := net.ParseIP(ip) + + for _, AllowedRangeIP := range ipAllowList { + _, subnet, err := net.ParseCIDR(AllowedRangeIP) + if err != nil { + return false, err + } + + if subnet.Contains(clientIP) { + return true, nil + } + } + return false, nil +} + +func CheckDomain(domain string, domainAllowedList []string) (bool, error) { + for _, pattern := range domainAllowedList { + matched, err := regexp.MatchString(pattern, domain) + if err != nil { + return false, err + } + if matched { + return true, nil + } + } + return false, nil +}