Skip to content

Commit

Permalink
#3 : add workaround with traefik bug parsing with nested []string in …
Browse files Browse the repository at this point in the history
…config struct
  • Loading branch information
alexandreh2ag committed Jan 5, 2023
1 parent 1b72403 commit 10f6576
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ func New(ctx context.Context, next http.Handler, config *Config, name string) (h
return nil, errors.New("sourceRange is empty, IPWhiteLister not created")
}

// workaround to bug in traefik/paerser who format []string{"A", "B"} to string("24║A║B") or string("║A║B")
// see: https://github.com/traefik/traefik/issues/9638
config.IPWhiteList.SourceRange = stringToSliceHook(config.IPWhiteList.SourceRange)
config.BasicAuth.Users = stringToSliceHook(config.BasicAuth.Users)

checker, err := NewChecker(config.IPWhiteList.SourceRange)
if err != nil {
return nil, fmt.Errorf("cannot parse CIDR whitelist %s: %w", config.IPWhiteList.SourceRange, err)
Expand Down Expand Up @@ -129,3 +134,14 @@ func basicUserParser(user string) (string, string, error) {
}
return split[0], split[1], nil
}

func stringToSliceHook(data []string) []string {
if strings.Contains(data[0], "║") {
values := strings.Split(data[0], "║")
if len(values) >= 2 && values[0] == "" && values[1] == "24" {
return values[2:]
}
return values
}
return data
}

0 comments on commit 10f6576

Please sign in to comment.