Skip to content

Commit

Permalink
fix: inspect cluster without privilegedUsername (#2183)
Browse files Browse the repository at this point in the history
Co-authored-by: xdonggao <xdonggao@tencent.com>
  • Loading branch information
GaoXiaodong and xdonggao authored Dec 5, 2022
1 parent 4eebafd commit 6e1a4a9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 7 additions & 5 deletions pkg/auth/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package filter
import (
"fmt"
"net/http"
"net/http/httputil"
"strconv"
"strings"
"unicode"
Expand Down Expand Up @@ -79,11 +78,14 @@ func ExtractClusterNames(ctx context.Context, req *http.Request, resource string
clusterNames.Insert(clusterName)
}

clusterNames.Insert(cluster.NamePattern.FindAllString(resource, -1)...)
filterResourceClusterNames := cluster.ClusterPattern.FindAllString(resource, -1)
for _, filterClusterName := range filterResourceClusterNames {
clusterNames.Insert(cluster.NamePattern.FindAllString(filterClusterName, -1)...)
}

data, err := httputil.DumpRequest(req, true)
if err == nil {
clusterNames.Insert(cluster.NamePattern.FindAllString(string(data), -1)...)
filterURLClusterNames := cluster.ClusterPattern.FindAllString(req.URL.String(), -1)
for _, filterClusterName := range filterURLClusterNames {
clusterNames.Insert(cluster.NamePattern.FindAllString(filterClusterName, -1)...)
}

return clusterNames.List()
Expand Down
3 changes: 2 additions & 1 deletion pkg/platform/registry/cluster/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ const (
)

var (
NamePattern = regexp.MustCompile(`(cls-[a-z0-9]+|global)`)
ClusterPattern = regexp.MustCompile(`(/clusters/cls-[a-z0-9]+|/clusters/global)`)
NamePattern = regexp.MustCompile(`(cls-[a-z0-9]+|global)`)
)

// Strategy implements verification logic for cluster.
Expand Down

0 comments on commit 6e1a4a9

Please sign in to comment.