kubernetes - 基于 Kubernetes 客户端证书的身份验证导致使用 system:anonymous 用户的请求
问题描述
我已按照这些说明在 Kubernetes 中创建普通用户并生成客户端证书https://kubernetes.io/docs/reference/access-authn-authz/certificate-signing-requests/#normal-user
当我尝试通过提供证书和密钥使用 curl 向 API 服务器发送请求时,响应返回为"message": "forbidden: User \"system:anonymous\" cannot get path \"/apis\"
curl -k -v -L --cert ./userone.crt --key ./userone.key -k --request GET https://<host>:443/apis\?timeout\=32s
<Removed some text>
HTTP/1.1 403 Forbidden
< Server: nginx/1.12.2
< Date: Tue, 02 Nov 2021 21:53:03 GMT
< Content-Type: application/json
< Content-Length: 237
< Connection: keep-alive
< Cache-Control: no-cache, private
< X-Content-Type-Options: nosniff
<
{
"kind": "Status",
"apiVersion": "v1",
"metadata": {
},
"status": "Failure",
"message": "forbidden: User \"system:anonymous\" cannot get path \"/apis\"",
"reason": "Forbidden",
"details": {
},
"code": 403
还尝试在我具有提升访问权限的地方模拟这个用户,这个新用户能够访问集群角色和角色绑定中配置的 Pod。这至少证明授权是有效的。
kubectl auth can-i -n xyz get pods --as=userone
yes
问题似乎是新用户无权访问 API 服务器上的 /apis 端点。尝试将 nonResourceURLs 添加为 ClusterRole 的一部分,但这也无济于事。
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: read-only-role
rules:
- apiGroups:
- ""
resources: ["*"]
verbs:
- get
- list
- watch
- nonResourceURLs:
- /metrics
- /api/*
- /apis/*
verbs:
- get
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: read-only-binding
namespace: xyz
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: read-only
subjects:
- apiGroup: rbac.authorization.k8s.io
kind: User
name: userone
我们使用的是 Kubernetes 版本 1.18.17,并且 API 服务器也配置了 --client-ca-file 选项。感谢您对此的帮助。
解决方案
推荐阅读
- django - clean_data 没有从 django 的表单中获取更新的整数值
- ios - 使用 Expo 构建二进制文件会压缩应用程序的大小吗?
- python - argparser 条件字段取决于选项
- ios - 编写使用许多先前输入帧的视频着色器的最有效方法是什么?
- python - 试图抓取一个嵌套在标签中的元素
- python - Django kwarg 总是“pk”?
- python - Python数字虚拟按键不起作用
- google-bigquery - 如何从 Beam 作业批量流式插入 BigQuery
- dart - Flutter:打开简单对话框后如何保持手势事件状态
- c++ - 定义一个函数,使其可以接受列表或向量