Closed huxiaoliang closed 3 years ago
@wangao1236 we have to fix this issue asap, it impacted tkestack release e2e test case as well, thanks please @JiaYongfei comments more for your case
The same problem exist while creating these resources: machine/cronhpa/ipam/tappcontroller
`machine:.platform.tkestack.io \"\" is forbidden: User \"system:serviceaccount:kube-system:k8sadmin\" cannot createMachine resource \"machine:*\" in API group \"platform.tkestack.io\" at the cluster scope: cluster: global has invalid tenantID
cronhpa:.platform.tkestack.io \"\" is forbidden: User \"system:serviceaccount:kube-system:k8sadmin\" cannot createCronhpa resource \"cronhpa:*\" in API group \"platform.tkestack.io\" at the cluster scope: cluster: global has invalid tenantID
ipam:.platform.tkestack.io \"\" is forbidden: User \"system:serviceaccount:kube-system:k8sadmin\" cannot createIpam resource \"ipam:*\" in API group \"platform.tkestack.io\" at the cluster scope: cluster: global has invalid tenantID
tappcontroller:.platform.tkestack.io \"\" is forbidden: User \"system:serviceaccount:kube-system:k8sadmin\" cannot createTappcontroller resource \"tappcontroller:*\" in API group \"platform.tkestack.io\" at the cluster scope: cluster: global has invalid tenantID`
The same problem exist while creating these resources: machine/cronhpa/ipam/tappcontroller
`machine:.platform.tkestack.io "" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createMachine resource "machine:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID
cronhpa:.platform.tkestack.io "" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createCronhpa resource "cronhpa:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID
ipam:.platform.tkestack.io "" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createIpam resource "ipam:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID
tappcontroller:.platform.tkestack.io "" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createTappcontroller resource "tappcontroller:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID`
Which clusterRole is bound to this serviceAccount ?
The same problem exist while creating these resources: machine/cronhpa/ipam/tappcontroller
machine:_.platform.tkestack.io "_" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createMachine resource "machine:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID cronhpa:_.platform.tkestack.io "_" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createCronhpa resource "cronhpa:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID ipam:_.platform.tkestack.io "_" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createIpam resource "ipam:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID tappcontroller:_.platform.tkestack.io "_" is forbidden: User "system:serviceaccount:kube-system:k8sadmin" cannot createTappcontroller resource "tappcontroller:*" in API group "platform.tkestack.io" at the cluster scope: cluster: global has invalid tenantID
Which clusterRole is bound to this serviceAccount ?
cluster-admin
@wangao1236 reopend since it cause build failed
Step 1/5 : FROM alpine:3.10
3.10: Pulling from library/alpine
Digest: sha256:f0e9534a598e501320957059cb2a23774b4d4072e37c7b2cf7e95b241f019e35
Status: Downloaded newer image for alpine:3.10
---> 536a684cf733
Step 2/5 : RUN echo "hosts: files dns" >> /etc/nsswitch.conf
---> Running in f3cf55eb5623
standard_init_linux.go:211: exec user process caused "exec format error"
The command '/bin/sh -c echo "hosts: files dns" >> /etc/nsswitch.conf' returned a non-zero code: 1
make[2]: *** [image.build.linux_arm64.tke-audit-api] Error 1
make[1]: *** [push.multiarch] Error 2
make: *** [release.build] Error 2
build/lib/image.mk:73: recipe for target 'image.build.linux_arm64.tke-audit-api' failed
service account token only works on kube-system
ns, so reopen it @wangao1236
tke-installer for test rbac issue:
version=revert-rbac && wget https://tke-release-1251707795.cos.ap-guangzhou.myqcloud.com/tke-installer-linux-amd64-$version.run{,.sha256} && sha256sum --check --status tke-installer-linux-amd64-$version.run.sha256 && chmod +x tke-installer-linux-amd64-$version.run && ./tke-installer-linux-amd64-$version.run
revert commits: https://github.com/tkestack/tke/commit/644dec56dc57970d425b6deef94e3b638657ff2d https://github.com/tkestack/tke/commit/d656744b5ffc3b9b40f2f7a05f0fa0054763637f https://github.com/tkestack/tke/commit/ab387453407f802eb12cdafe465714f9a65b20b5
test processes:
kubectl create serviceaccount cls-user -n kube-public
create role: kubectl apply -f clsrole.yaml
cat clsrole.yaml
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: cls-reader rules:
kubectl apply -f clsrolebind.yaml
cat clsrolebind.yaml
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRoleBinding metadata: name: cls-user:cls-reader roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: cls-reader subjects:
kubectl -n kube-public describe secret $(sudo kubectl -n kube-public get secret | (grep cls-user || echo "$_") | awk '{print $1}') | grep token: | awk '{print $2}'
create kubeconfig file with above admin token:
cat cls-user.kubeconfig
apiVersion: v1 kind: Config clusters:
edit webhook abac policy: kubectl edit -n tke cm tke-auth-api
replace
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"system:*","namespace":"*", "resource":"*","apiGroup":"*", "group": "*", "nonResourcePath":"*"}}
to
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"system:kube-*|system:serviceaccount:kube-system:*","namespace":"*", "resource":"*","apiGroup":"*tkestack.io", "group": "*", "nonResourcePath":"*"}}
{"apiVersion":"abac.authorization.kubernetes.io/v1beta1","kind":"Policy","spec":{"user":"^system:serviceaccount:tke:default$","namespace":"*", "resource":"*","apiGroup":"*", "group": "*", "nonResourcePath":"*"}}
and rebuild tke-auth-api pod.
test this kubeconfig kubectl --kubeconfig ./cls-user.kubeconfig get cluster
Error from server (Forbidden): cluster:*.platform.tkestack.io "*" is forbidden: User "system:serviceaccount:kube-public:cls-user" cannot listClusters resource "cluster:*" in API group "platform.tkestack.io" at the cluster scope: permission for listClusters on cluster:* not verify
rbac doesn't work.
edit platform configmap: kubectl edit -n tke cm tke-platform-api
, remove
[authorization]
mode = "Webhook"
webhook_config_file = "/app/conf/tke-authz-webhook.yaml"
and rebuild tke-platform-api pod
try again: kubectl --kubeconfig ./cls-user.kubeconfig get cluster
NAME CREATED AT
global 2021-08-18T08:08:43Z
rbac works, and not found any func is blocked yet.
why rbace works: https://kubernetes.io/docs/tasks/extend-kubernetes/configure-aggregation-layer/#authentication-flow
if we set webhook for extension apiserver, authentication will not use above authentication flow.
Tkestack set kube-apiserver authentication with Node, RBAC and Webhook, so in default authentication flow we already have Webhook mode, no need set Webhook in extension apiserver.
apiVersion: v1 kind: Config clusters:
root@VM-0-80-ubuntu:~# cat /etc/kubernetes/known_tokens.csv 1m6CJoJ1BQZcQMQOKdlwbPnjS2W,admin,admin,system:masters root@VM-0-80-ubuntu:~#