我正在按照说明 here 在与 Azure AD 集成的 AKS 集群中设置 RBAC 。我在 AAD 租户中创建了一个 AD 组,并向其中添加了一个用户。然后,按照说明在 AKS 群集中为该组分配“群集用户角色”。创建了角色和角色绑定(bind),如下所示:
角色:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: development
name: restricted-role
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "watch", "list"]
角色绑定(bind):
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-pods
namespace: development
subjects:
- kind: Group
name: 308f50cb-e05a-4340-99d4-xxxxxxxb
apiGroup: rbac.authorization.k8s.io
namespace: development
roleRef:
kind: Role
name: restricted-role
apiGroup: rbac.authorization.k8s.io
然后我尝试使用新的用户凭据登录:
az login --username <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1b706e797e6e687e695b636363357475767278697468747d6f35787476" rel="noreferrer noopener nofollow">[email protected]</a> --password xxxx
az aks get-credentials --name mycluster --resource-group myrg --overwrite-existing
根据文档,我应该只被允许在开发命名空间上执行 kubectl get pods。但是,使用这个新的用户凭据,我发现我可以执行 kubectl get pods --all-namespaces、kubectl get svc --all-namespaces 等操作并查看结果,就好像角色绑定(bind)根本没有任何影响一样。我也通过checking验证过我的集群有
"enableRBAC": true
有人可以告诉我这个配置有什么问题吗?
最佳答案
使用命令:
az aks show -g <rg> -n <clusterName> --query aadProfile
您可以确认群集是否启用了 Azure Active Directory。如果是这样,您可以通过以下命令获取 kubeconfig 文件:
az aks get-credentials -g <rg_name> -n <aks_name>
应该看起来像:
user:
auth-provider:
config:
apiserver-id: <appserverid>
client-id: <clientid>
environment: AzurePublicCloud
tenant-id: <tenant>
name: azure
关于azure - AKS RBAC - 角色绑定(bind)无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60116358/