azure - AKS RBAC - 角色绑定(bind)无效

标签 azure kubernetes azure-aks azure-rbac

我正在按照说明 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/

相关文章:

node.js - 在 Azure Web 服务上部署 Node JS 应用程序

azure - 当我在 App Insights 中打开实时指标时,为什么会收到 "Not available: your app is offline or using an older SDK'?

azure - ADF - HTTP API - 管道查询、排序/orderby 语法?

azure - Azure 中基于 SAML 的 IDP(带有签名响应和加密断言)设置?

kubernetes - 为什么部署rook-ceph后在kubernetes中找不到osd pod?

kubernetes - 如何让 Kerberos 身份验证在 k8s 中工作

kubernetes - 当 Pod 通常需要低 CPU 但定期扩展时,如何使用 K8S HPA 和自动缩放器

docker - 同步pod出错,无法进行Registry.access.redhat.com(Kubernetes)

azure - Kubernetes pod 抛出 CredentialUnavailableException : EnvironmentCredential authentication unavailable