Skip to content

Commit 7726e9f

Browse files
committed
fix(auth): allow anyone to get cluster-info in kube-public
1 parent c70a9cd commit 7726e9f

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/auth/filter/filter.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ const (
6060
decisionAllow = "allow"
6161
decisionForbid = "forbid"
6262
reasonError = "internal error"
63+
64+
kubePublicNS = "kube-public"
6365
)
6466

6567
var (
@@ -182,6 +184,11 @@ func UnprotectedAuthorized(attributes authorizer.Attributes) authorizer.Decision
182184
return authorizer.DecisionAllow
183185
}
184186

187+
// https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
188+
if attributes.GetNamespace() == kubePublicNS && isGetVerb(verb) {
189+
return authorizer.DecisionAllow
190+
}
191+
185192
return authorizer.DecisionNoOpinion
186193
}
187194

@@ -323,3 +330,7 @@ func splitPath(path string) []string {
323330
}
324331
return strings.Split(path, "/")
325332
}
333+
334+
func isGetVerb(verb string) bool {
335+
return strings.HasPrefix(verb, "get")
336+
}

web/console/src/webApi/tkestack.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Request from './request';
22

33
export const getTkeStackVersion = async () => {
4-
const rsp = await Request.get<any, { items: Array<{ data?: { tkeVersion?: string } }> }>(
5-
'/api/v1/namespaces/kube-public/configmaps',
4+
const rsp = await Request.get<any, { data?: { tkeVersion: string } }>(
5+
'/api/v1/namespaces/kube-public/configmaps/cluster-info',
66
{
77
headers: {
88
'X-TKE-ClusterName': 'global'
99
}
1010
}
1111
);
12-
return rsp?.items?.[0]?.data?.tkeVersion ?? '';
12+
return rsp?.data?.tkeVersion ?? '';
1313
};

0 commit comments

Comments
 (0)