使用API/CLI對阿里雲子賬戶做ACK(Kubernetes) RBAC授權

Prerequisite

Prepare kube config for resource admin user kubernetes-admin before you get start cli and api calls.

Download public/privite kubernetes config file from cluster detail dashboard

https://cs.console.aliyun.com/#/k8s/cluster/<your_cluster_id>/info?eci=false

Otherwise fetch kubenetes config file with openAPI

https://help.aliyun.com/document_detail/86798.html?spm=a2c4g.11186623.6.804.385a49feoJu0gZ

Notice:
certificate-authority-data: kubeconfig ca
user->client-certificate-data: kubeconfig cert
user->client-key-data: kubeconfig key

Decode the base64 for above 3 ca/certs file to put into kubeconfig config.
echo * | base64 –d

RBAC

Grant permission of ACK RBAC thru CLI of kubectl

"cs:admin": cluster admin and full read/write access
"cs:ops": cluster operator without write access of pv/namespace/node
"cs:dev": developer of namespace level access

Additional network-view role is added for readonly access of network operator

"custom:network-view": read access for node/service/endpoints

wget http://ack-downloads.oss-cn-hangzhou.aliyuncs.com/rbac/ack-grant -O ack-grant  && chmod 755 ack-grant

./ack-grant <USER_ID> <ROLE: one of custom:network-view, cs:admin, cs:ops and cs:dev>

Use Python SDK to grant privilege to sub-account of aliyun

Kubernete Python SDK

pip install kubernetes
wget http://ack-downloads.oss-cn-hangzhou.aliyuncs.com/rbac/ack-grant.py -O ack-grant.py

python  ack-grant.py -u <UID of sub-account> -r cs:ops -c /Users/eric/.kube/config_f3

RBAC API

Example to DELETE existing clusterrolebinding

curl -k -v -XDELETE  -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: kubectl/v1.10.3 (darwin/amd64) kubernetes/2bba012" https://<public/private IP of Kubernetes API server>:6443/apis/rbac.authorization.k8s.io/v1/clusterrolebindings/<UID of sub-account>-clusterrolebinding

Create new clusterrolebinding

Request Body: {"apiVersion":"rbac.authorization.k8s.io/v1","kind":"ClusterRoleBinding","metadata":{"name":"<UID of sub-account>-clusterrolebinding","namespace":""},"roleRef":{"apiGroup":"rbac.authorization.k8s.io","kind":"ClusterRole","name":"cs:ops"},"subjects":[{"apiGroup":"rbac.authorization.k8s.io","kind":"User","name":"<UID of sub-account>"}]}

curl -k -v -XPOST  -H "Accept: application/json" -H "Content-Type: application/json" -H "User-Agent: kubectl/v1.10.3 (darwin/amd64) kubernetes/2bba012" https://<public/private IP of Kubernetes API server>:6443/apis/rbac.authorization.k8s.io/v1/clusterrolebindings
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章