CC00220.CloudKubernetes——|KuberNetes&细粒度权限控制.V04|——|RBAC.v04|ServiceAccount|

一、ClusterRole和ClusterRoleBinding架构图说明
### --- ClusterRole和ClusterRoleBinding架构图说明

~~~     首先我们有了一个cluster-admin的ClusterRole
~~~     然后还有一个admin-user的一个ServiceAccount,在kube-system的namespace下
~~~     然后创建了一个clusterRoleBinding,它把这个权限绑定到了ServiceAccount上
~~~     绑定到ServiceAccount上之后这个ServiceAccount就具有了这个ClusterRole的所有的权限
二、ServiceAccount
### --- 查看ServiceAccount

[root@k8s-master01 ~]#  kubectl get sa -n kube-system
NAME                                 SECRETS   AGE
admin-user                           1         23d
### --- 查看ClusterRole
~~~     注:写的都是* ,*表示对系统apigroup下所有的操作都是允许的
~~~     这个权限是非常高的,泄露非常危险

[root@k8s-master01 ~]# kubectl get clusterrole cluster-admin -oyaml
NAME            CREATED AT
cluster-admin   2021-04-09T13:52:18Z    // 这个ClusterRole是系统自动创建的
[root@k8s-master01 ~]# kubectl get clusterrole cluster-admin -oyaml
rules:
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - '*'
- nonResourceURLs:                      // 所有权限下的所有资源
  - '*'
  verbs:
  - '*'
三、serviceaccount的启用方式
### --- 启用方式一:service的启用方式:

~~~     一个pod启动的时候,就可以就可以通过ingress的方式来指定ServiceAccount的权限就是它,
~~~     当然这样操作是非常危险的
### --- 启用方式二:

[root@k8s-master01 ~]#  kubectl get sa
NAME      SECRETS   AGE
default   1         23d
### --- 创建一个ServiceAccount
~~~     注:在创建ServiceAccount之后就会自动生成一个以yanqi开头的secret

[root@k8s-master01 ~]# kubectl create sa yanqi
serviceaccount/yanqi created
[root@k8s-master01 ~]# kubectl get secret
NAME                  TYPE                                  DATA   AGE
yanqi-token-zz7k5     kubernetes.io/service-account-token   3      20s
### --- 查看secret
~~~     注:这个secret是有一个token的,这个token就可以在dashboard上,就具有了增删改查的权限 

[root@k8s-master01 ~]# kubectl desicribe secret yanqi-token-zz7k5
Type:  kubernetes.io/service-account-token
namespace:  7 bytes
token:      eyJhbGciOiJSUzI1NiIsImtpZCI6InQ2ci1YY3cwaTZjVlQ2bzhaeTJiaGhMNE1fblFzMExrWDhOd25PZmFMXzAifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6InlhbnFpLXRva2VuLXp6N2s1Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQubmFtZSI6InlhbnFpIiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZXJ2aWNlLWFjY291bnQudWlkIjoiMDJkYjk4ODEtZGJmZS00ZDU1LTkxYzUtNWUyZjk4ZGQ0NWZlIiwic3ViIjoic3lzdGVtOnNlcnZpY2VhY2NvdW50OmRlZmF1bHQ6eWFucWkifQ.hz2BcbrLcVk8yjbXdS7sGcwAWnlmELR5EnfMWiaLZxYfZvqHy1wwhRyTyoqGkYtOKYZnCZ8vCZYwqZqXHIGZf_tX5COhrpvWmK6KY904Hb6v77nEQI8_sDd1-WoTfC8-bAnCtSWwpedyAWtwiTKp4w0rdLALz_ilTEpRS2CEJNRHQLXsPfDiZ96yhd0xqzv1LsN8b90NGBM5ljLfL4pLKBsh0keepu-SM4vS9b6s7Nf1-ySmPLJekwKFV2HN13o_lOnIQz_jE4M6eKJ1KnMNibiIuCjEXq7AzwR28I6-ZhC8Gei3g6QVPi6NI6y8iVtBMh3KscP2Bo9EVNRl3KOk4g
ca.crt:     1411 bytes
### --- 查看这个secret有什么权限
~~~     注:这个token就是它的值,是加密类型的,解密查看内容

[root@k8s-master01 ~]# kubectl get secret yanqi-token-zz7k5 -oyaml
apiVersion: v1
data:
  ca.crt: LS0tLS1CRUdJTiBDR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2f98dd45fe
    manager: kube-controller-manager
    operation: Update
    time: "2021-05-03T13:44:46Z"
  name: yanqi-token-zz7k5
  namespace: default
  resourceVersion: "1613315"
  uid: d211d58e-259a-49dc-ba9b-15db16b19815
type: kubernetes.io/service-account-token
~~~     # 解密出来的值和describe查看出的值是一致的,那这个token是可以去访问我们的资源

[root@k8s-master01 ~]# echo """ZXlKaGJHY2lPaUpTVXpJMU5pSXNJbXRwWkNJNkluUTJjaTFZWTNjd2FUWmpWbFEyYnpoYWVUSmlhR2hNTkUxZmJsRnpNRXhyV0RoT2QyNVBabUZNWHpBaWZRLmV5SnBjM01pT2lKcmRXSmxjbTVsZEdWekwzTmxjblpwWTJWaFkyTnZkVzUwSWl3aWEzVmlaWEp1WlhSbGN5NXBieTl6WlhKMmFXTmxZV05qYjNWdWRDOXVZVzFsYzNCaFkyVWlPaUprWldaaGRXeDBJaXdpYTNWaVpYSnVaWFJsY3k1cGJ5OXpaWEoyYVdObFlXTmpiM1Z1ZEM5elpXTnlaWFF1Ym1GdFpTSTZJbmxoYm5GcExYUnZhMlZ1TFhwNk4yczFJaXdpYTNWaVpYSnVaWFJsY3k1cGJ5OXpaWEoyYVdObFlXTmpiM1Z1ZEM5elpYSjJhV05sTFdGalkyOTFiblF1Ym1GdFpTSTZJbmxoYm5GcElpd2lhM1ZpWlhKdVpYUmxjeTVwYnk5elpYSjJhV05sWVdOamIzVnVkQzl6WlhKMmFXTmxMV0ZqWTI5MWJuUXVkV2xrSWpvaU1ESmtZams0T0RFdFpHSm1aUzAwWkRVMUxUa3hZelV0TldVeVpqazRaR1EwTldabElpd2ljM1ZpSWpvaWMzbHpkR1Z0T25ObGNuWnBZMlZoWTJOdmRXNTBPbVJsWm1GMWJIUTZlV0Z1Y1draWZRLmh6MkJjYnJMY1ZrOHlqYlhkUzdzR2N3QVdubG1FTFI1RW5mTVdpYUxaeFlmWnZxSHkxd3doUnlUeW9xR2tZdE9LWVpuQ1o4dkNaWXdxWnFYSElHWmZfdFg1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pRS2CEJNRHQLXsPfDiZ96yhd0xqzv1LsN8b90NGBM5ljLfL4pLKBsh0keepu-SM4vS9b6s7Nf1-ySmPLJekwKFV2HN13o_lOnIQz_jE4M6eKJ1KnMNibiIuCjEXq7AzwR28I6-ZhC8Gei3g6QVPi6NI6y8iVtBMh3KscP2Bo9EVNRl3KOk4g
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

yanqi_vip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值