【问题标题】:AKS RBAC - Rolebinding has no effectAKS RBAC - 角色绑定无效
【发布时间】:2020-05-23 18:17:14
【问题描述】:

我正在按照说明 here 在与 Azure AD 集成的 AKS 群集中设置 RBAC。我在我的 AAD 租户中创建了一个 AD 组,向其中添加了一个用户。然后按照说明在 AKS 群集中为该组分配“群集用户角色”。创建了一个 Role 和 Rolebinding 如下图:

角色:

apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  namespace: development
  name: restricted-role
rules:
- apiGroups: [""] 
  resources: ["pods"]
  verbs: ["get", "watch", "list"]

角色绑定:

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 kubeuser@xxx.onmicrosoft.com --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 等并查看结果,就好像角色绑定根本没有任何影响一样。我还通过checking 验证了我的集群有

“启用RBAC”:真

谁能告诉我这个配置有什么问题?

【问题讨论】:

  • 在最后一个命令之后你得到什么样的kubeconfig 文件?它是否包含如下部分:用户:auth-provider:config:apiserver-id: client-id: environment:AzurePublicCloud tenant-id: name:azure
  • 没有。我的 kube 配置有 api 版本、集群、证书授权数据、服务器、名称、上下文、命名空间和用户
  • 那么您的集群似乎没有启用 AAD。你能运行命令吗: az aks show -g -n --query aadProfile
  • 谢谢,由于某种原因,我的 AAD 集成设置不正确。我进行了重置,然后它开始工作。谢谢
  • 好吧,你可以添加一个答案来为正在寻找它的社区展示解决方案。

标签: azure kubernetes azure-aks azure-rbac


【解决方案1】:

使用命令:

az aks show -g <rg> -n <clusterName> --query aadProfile

您可以确认集群是否启用了 AAD。如果启用,您从中获取的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

【讨论】:

    猜你喜欢
    • 2020-07-07
    • 2021-07-16
    • 2021-07-24
    • 2018-06-13
    • 2016-03-25
    • 2017-04-24
    • 2015-11-12
    • 2019-07-25
    • 2020-07-20
    相关资源
    最近更新 更多