一、認(rèn)證
- User Accounts
- Service Accounts
Service Account 自動(dòng)化:
- Service Account Admission Controller
- Token Controller
- Service Account Controller
1、Service Account Admission Controller
通過 Admission Controller 插件來實(shí)現(xiàn)對 pod 修改,它是 apiserver 的一部分。創(chuàng)建或更新 pod 時(shí)會同步進(jìn)行修改 pod。當(dāng)插件處于激活狀態(tài)(在大多數(shù)發(fā)行版中都默認(rèn)情況)創(chuàng)建或修改 pod 時(shí),會按以下操作執(zhí)行:
1、如果 pod 沒有設(shè)置 ServiceAccount,則將 ServiceAccount 設(shè)置為 default。
2、確保 pod 引用的 ServiceAccount 存在,否則將會拒絕請求。
3、如果 pod 不包含任何 ImagePullSecrets,則將ServiceAccount 的 ImagePullSecrets 會添加到 pod 中。
4、為包含 API 訪問的 Token 的 pod 添加了一個(gè) volume。
5、把 volumeSource 添加到安裝在 pod 的每個(gè)容器中,掛載在 /var/run/secrets/kubernetes.io/serviceaccount。
2、Token Controller
TokenController 作為 controller-manager 的一部分運(yùn)行。異步行為:
- 觀察 serviceAccount 的創(chuàng)建,并創(chuàng)建一個(gè)相應(yīng)的 Secret 來允許 API 訪問。
- 觀察 serviceAccount 的刪除,并刪除所有相應(yīng)的ServiceAccountToken Secret
- 觀察 secret 添加,并確保關(guān)聯(lián)的 ServiceAccount 存在,并在需要時(shí)向 secret 中添加一個(gè) Token。
- 觀察 secret 刪除,并在需要時(shí)對應(yīng) ServiceAccount 的關(guān)聯(lián)
3、Service Account Controller
Service Account Controller 在 namespaces 里管理ServiceAccount,并確保每個(gè)有效的 namespaces 中都存在一個(gè)名為 “default” 的 ServiceAccount。
二、授權(quán)(RBAC)
類別:
- Role
- ClusterRole
- RoleBinding
- ClusterRoleBinding
1、Role
代表一個(gè)角色,會包含一組權(quán)限,沒有拒絕規(guī)則,只是附加允許。它是 Namespace 級別的資源,只能作用與 Namespace 之內(nèi)。
# 查看已有的角色信息
kubectl get role -n ingress-nginx -oyaml
配置文件
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
labels:
app.kubernetes.io/name: ingress-nginx
app.kubernetes.io/part-of: ingress-nginx
name: nginx-ingress
namespace: ingress-nginx
roles:
- apiGroups:
- ""
resources:
- configmaps
- pods
- secrets
- namespaces
verbs:
- get
- apiGroups:
- ""
resourceNames:
- ingress-controller-label-nginx
resources:
- configmaps
verbs:
- get
- update
- apiGroups:
- ""
resources:
- configmaps
verbs:
- create
2、ClusterRole
功能與 Role 一樣,區(qū)別是資源類型為集群類型,而 Role 只在 Namespace
# 查看某個(gè)集群角色的信息
kubectl get clusterrole view -oyaml
3、RoleBinding
Role 或 ClusterRole 只是用于制定權(quán)限集合,具體作用與什么對象上,需要使用 RoleBinding 來進(jìn)行綁定。
作用于 Namespace 內(nèi),可以將 Role 或 ClusterRole 綁定到 User、Group、Service Account 上。
# 查看 rolebinding 信息
kubectl get rolebinding --all-namespaces
# 查看指定 rolebinding 的配置信息
kubectl get rolebinding <role_binding_name> --all-namespaces -oyaml
配置文件文章來源:http://www.zghlxwxcb.cn/news/detail-681033.html
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
......
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name nginx-ingress-role
subjects:
- kind: ServiceAccount
name: nginx-ingress-serviceaccount
namespace: ingress-nginx
4、ClusterRoleBinding
與 RoleBinding 相同,但是作用于集群之上,可以綁定到該集群下的任意 User、Group 或 Service Account文章來源地址http://www.zghlxwxcb.cn/news/detail-681033.html
到了這里,關(guān)于(八)k8s實(shí)戰(zhàn)-身份認(rèn)證與權(quán)限的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!