rbac 基于角色的访问控制
主体(subject)
user: 用户
Group: 用户组
serviceaccount: 服务账号
kubectl create sa psp-denial-sa -n staging
角色:
role: 授权特定命名空间的访问权限
kubectl create role role-2 -n db --verb=delete --resource=namespaces
clusterrole: 授权所有的命名空间访问权限
kubectl create clusterrole restrict-access-role --verb=use --resource=psp --resource-name=restrict-policy
角色绑定:
rolebiding: 将角色绑定到主体(指定名称空间授权)
kubectl create rolebinding role-2-binding --role=role-2 --serviceaccount=db:service-account-web -n db
clusterrolebinding:将集群角色绑定到主体 (集群范围授权)
kubectl create clusterrolebinding dany-access-bind --clusterrole=restrict-access-role --serviceaccount=staging:psp-denial-sa
pod 挂载sa
apiVersion: v1
kind: Pod
metadata:
name: nginx
spec:
containers:
- image: nginx
name: nginx
volumeMounts:
- mountPath: /var/run/secrets/tokens
name: vault-token
serviceAccountName: build-robot
volumes:
- name: vault-token
projected:
sources:
- serviceAccountToken:
path: vault-token
expirationSeconds: 7200
audience: vault