【问题标题】:Problems with simple RBAC example简单 RBAC 示例的问题
【发布时间】:2019-02-27 21:12:43
【问题描述】:

我想做一个非常简单的例子来学习如何在 Kubernetes 中使用 RBAC 授权。因此我使用文档中的示例:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  namespace: dev
  name: dev-readpods-role
rules:
- apiGroups: [""]
  resources: ["pods"]
  verbs: ["get", "watch", "list"]
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: dev-tester-rolebinding
  namespace: dev
subjects:
- kind: User
  name: Tester
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: Role
  name: dev-readpods-role
  apiGroup: rbac.authorization.k8s.io

角色和角色绑定已创建。

当我使用 Tester 登录并尝试时

kubectl get pods -n dev

我明白了

Error from server (Forbidden): pods is forbidden: User "<url>:<port>/oidc/endpoint/OP#Tester" cannot list pods in the namespace "dev"

我在这里 (RBAC Error in Kubernetes) 读到 api-server 必须以 --authorization-mode=...,RBAC 启动。我怎样才能检查这个?我在其他地方读到,如果我跑了

kubectl api-versions | findstr rbac

并找到条目 RBAC 应该被激活。这是真的吗?

我做错了什么?有什么好办法解决问题吗?

谢谢!

附:我在 IBM Cloud Private 中运行 Kubernetes。

【问题讨论】:

    标签: kubernetes ibm-cloud-private kubernetes-security


    【解决方案1】:

    在 ICP 中,使用 Teams(我认为是 ICP 自己的术语)看起来令人鼓舞。尝试从它开始。但是您需要 ICP 之外的 LDAP 服务器。 https://www.ibm.com/support/knowledgecenter/en/SSBS6K_2.1.0.3/user_management/admin.html

    【讨论】:

    • 谢谢。我通过单击管理控制台解决了它。不是很好,但现在可以了。
    【解决方案2】:

    您需要确定 apiserver 的调用以查看传递给它的 --authorization-mode 标志。通常这包含在 systemd 单元文件或 pod 清单中。我不确定 IBM Cloud 如何启动 apiserver

    【讨论】:

    • 我找到了另一种方法(我会向我的系统管理员询问一个好的方法,只要他回来)。 “ps -aux | grep apiserver” 并且设置了“--authorization-mode=RBAC”,但它不起作用(示例)。有什么问题?
    • 更新:当我以管理员身份登录并运行“kubectl auth can-i list pods --namespace dev --as Tester”时,它会响应“是”。当我以测试人员身份登录并运行“kubectl auth can-i list pods --namespace dev”时,它会响应“否”。我正在使用“kubectl config set-credentials Tester --token=...”和“kubectl config set-context cluster.local-context --user=Tester --namespace=undefined”进行记录。所以看来 Role 中的 Tester 和我登录的 Tester 不一样?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-08
    • 1970-01-01
    • 2012-11-10
    • 1970-01-01
    • 2011-06-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多