Skip to content

Commit

Permalink
fix(auth): allow anyone to get cluster-info in kube-public
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaosuiba committed Jun 3, 2021
1 parent c70a9cd commit 7726e9f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions pkg/auth/filter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const (
decisionAllow = "allow"
decisionForbid = "forbid"
reasonError = "internal error"

kubePublicNS = "kube-public"
)

var (
Expand Down Expand Up @@ -182,6 +184,11 @@ func UnprotectedAuthorized(attributes authorizer.Attributes) authorizer.Decision
return authorizer.DecisionAllow
}

// https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
if attributes.GetNamespace() == kubePublicNS && isGetVerb(verb) {
return authorizer.DecisionAllow
}

return authorizer.DecisionNoOpinion
}

Expand Down Expand Up @@ -323,3 +330,7 @@ func splitPath(path string) []string {
}
return strings.Split(path, "/")
}

func isGetVerb(verb string) bool {
return strings.HasPrefix(verb, "get")
}
6 changes: 3 additions & 3 deletions web/console/src/webApi/tkestack.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import Request from './request';

export const getTkeStackVersion = async () => {
const rsp = await Request.get<any, { items: Array<{ data?: { tkeVersion?: string } }> }>(
'/api/v1/namespaces/kube-public/configmaps',
const rsp = await Request.get<any, { data?: { tkeVersion: string } }>(
'/api/v1/namespaces/kube-public/configmaps/cluster-info',
{
headers: {
'X-TKE-ClusterName': 'global'
}
}
);
return rsp?.items?.[0]?.data?.tkeVersion ?? '';
return rsp?.data?.tkeVersion ?? '';
};

0 comments on commit 7726e9f

Please sign in to comment.