kubernetes:来自服务器的错误(禁止):即使授予权限,用户“system:anonymous”也无法列出群集范围内的节点

问题描述 投票:0回答:2

即使在向用户授予群集角色后,我也会获得Error from server (Forbidden): User "system:anonymous" cannot list nodes at the cluster scope. (get nodes)

我在〜/ .kube / config文件中设置了用户 - context: cluster: kubernetes user: [email protected] name: user@kubernetes的以下设置

并在下面添加到admin.yaml以创建集群角色和集群角色绑定

kind: CluserRouster: kubernetes user: [email protected] name: nsp@kubernetese apiVersion: rbac.authorization.k8s.io/v1alpha1 metadata: name: admin-role rules: - apiGroups: ["*"] resources: ["*"] verbs: ["*"] --- oidckind: ClusterRoleBinding apiVersion: rbac.authorization.k8s.io/v1alpha1 metadata: name: admin-binding subjects: - kind: User name: [email protected] roleRef: kind: ClusterRole name: admin-role

当我尝试命令时,我仍然会收到错误。 kubectl [email protected] get nodes Error from server (Forbidden): User "system:anonymous" cannot list nodes at the cluster scope. (get nodes)

有人可以建议如何继续。

kubernetes oidc kubeadm
2个回答
2
投票

您的问题不在于ClusterRoleBindings,而在于用户身份验证。 Kubernetes告诉你,它将你识别为system:anonymous(类似于* NIX的无人)而不是[email protected](你应用了你的绑定)。

在您的特定情况下,原因是username标志使用HTTP基本身份验证,并且需要password标志来实际执行任何操作。但即使您提供了密码,您仍然需要实际告诉API服务器接受该特定用户。

看看this Kubernetes文档的一部分,该文档涉及不同的身份验证方法。为了使usernamepassword身份验证工作,您需要查看静态密码文件部分,但我实际上建议您使用X509 Client Certs,因为它们更安全且操作更简单(在服务器上没有秘密,没有状态可以在API服务器之间复制)。


0
投票

在我的情况下,由于RBAC,我收到了几乎类似的错误

错误

root@k8master:~# kubectl cluster-info dump --insecure-skip-tls-verify=true
Error from server (Forbidden): nodes is forbidden: User "system:anonymous" cannot list resource "nodes" in API group "" at the cluster scope

解决方案:作为解决方案我在下面做了一些事情来重新配置我的用户以访问集群

cd $HOME
sudo whoami
sudo cp /etc/kubernetes/admin.conf $HOME/
sudo chown $(id -u):$(id -g) $HOME/admin.conf
export KUBECONFIG=$HOME/admin.conf
echo "export KUBECONFIG=$HOME/admin.conf" | tee -a ~/.bashrc

做完上面的时候,我采取了集群转储,我得到了结果

root@k8master:~# kubectl cluster-info
Kubernetes master is running at https://192.168.10.15:6443
KubeDNS is running at https://192.168.10.15:6443/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy
© www.soinside.com 2019 - 2024. All rights reserved.