Skip to content

Commit

Permalink
fix: inspect cluster without privilegedUsername
Browse files Browse the repository at this point in the history
  • Loading branch information
xdonggao committed Nov 23, 2022
1 parent 477ea6b commit 541dc21
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
13 changes: 8 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"
genericoidc "tkestack.io/tke/pkg/apiserver/authentication/authenticator/oidc"
Expand Down Expand Up @@ -79,12 +78,16 @@ func ExtractClusterNames(ctx context.Context, req *http.Request, resource string
}

clusterNames.Insert(cluster.NamePattern.FindAllString(resource, -1)...)

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

// data, err := httputil.DumpRequest(req, false)
// if err == nil {
// clusterNames.Insert(cluster.NamePattern.FindAllString(string(data), -1)...)
// }

return clusterNames.List()
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/auth/filter/inspector.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,14 @@ import (
"net/http"

k8serrors "k8s.io/apimachinery/pkg/api/errors"

platformv1 "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
"tkestack.io/tke/pkg/apiserver/authentication"
"tkestack.io/tke/pkg/util/log"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
genericfilters "k8s.io/apiserver/pkg/endpoints/filters"
"k8s.io/apiserver/pkg/endpoints/handlers/responsewriters"
"k8s.io/apiserver/pkg/endpoints/request"
genericapiserver "k8s.io/apiserver/pkg/server"
platformv1 "tkestack.io/tke/api/client/clientset/versioned/typed/platform/v1"
"tkestack.io/tke/pkg/apiserver/authentication"
"tkestack.io/tke/pkg/util/log"
)

type Inspector interface {
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 541dc21

Please sign in to comment.