天天看点

使用API/CLI对阿里云子账户做ACK(Kubernetes) RBAC授权使用CloudShell 来一次完成ACK集群的RAM授权和RBAC授权PrerequisiteRBACRBAC API

使用CloudShell 来一次完成ACK集群的RAM授权和RBAC授权

  1. 登录CloudShell获取一个配置完整集群管理命令行
使用API/CLI对阿里云子账户做ACK(Kubernetes) RBAC授权使用CloudShell 来一次完成ACK集群的RAM授权和RBAC授权PrerequisiteRBACRBAC API
  1. 授权

List existing users

aliyun ram ListUsers  | jq -r ".Users.User[].UserName"

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

Grant permission once

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

e.g.

./ack-grant-once eric custom:network-view

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