kubernetes 禁止消息可能包含RBAC信息,

gpnt7bae  于 10个月前  发布在  Kubernetes
关注(0)|答案(8)|浏览(126)

发生了什么?
Kubernetes API服务器在禁止访问错误消息中可能包含额外的RBAC信息。经过身份验证的用户可能会意外地获得关于可能的Kubernetes RBAC配置问题的信息。

你期望会发生什么?
错误消息不包含RBAC信息。

我们如何尽可能精确地重现它?

测试1

  1. kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  2. kubectl auth can-i create pods -n kube-system --as=system:anonymous
  3. curl -k https://KUBERNETES_API_SERVER_HOST:KUBERNETES_API_SERVER_PORT/foo
  1. kubectl apply -f - <<EOF
  2. kind: ClusterRoleBinding
  3. apiVersion: rbac.authorization.k8s.io/v1
  4. metadata:
  5. name: test
  6. roleRef:
  7. apiGroup: rbac.authorization.k8s.io
  8. kind: ClusterRole
  9. name: test
  10. subjects:
  11. - apiGroup: rbac.authorization.k8s.io
  12. kind: Group
  13. name: system:unauthenticated
  14. EOF
  1. kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  2. kubectl auth can-i create pods -n kube-system --as=system:anonymous
  3. curl -k https://KUBERNETES_API_SERVER_HOST:KUBERNETES_API_SERVER_PORT/foo

测试1的示例结果:

  1. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  2. no
  3. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:anonymous
  4. Error from server (Forbidden): selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope
  5. vagrant@verify-cluster:~$ curl -k https://c105.containers.test.cloud.ibm.com:31573/foo
  6. {
  7. "kind": "Status",
  8. "apiVersion": "v1",
  9. "metadata": {},
  10. "status": "Failure",
  11. "message": "forbidden: User \"system:anonymous\" cannot get path \"/foo\"",
  12. "reason": "Forbidden",
  13. "details": {},
  14. "code": 403
  15. }vagrant@verify-cluster:~$ kubectl apply -f - <<EOF
  16. > kind: ClusterRoleBinding
  17. > apiVersion: rbac.authorization.k8s.io/v1
  18. > metadata:
  19. > name: test
  20. > roleRef:
  21. > apiGroup: rbac.authorization.k8s.io
  22. > kind: ClusterRole
  23. > name: test
  24. > subjects:
  25. > - apiGroup: rbac.authorization.k8s.io
  26. > kind: Group
  27. > name: system:unauthenticated
  28. > EOF
  29. clusterrolebinding.rbac.authorization.k8s.io/test created
  30. vagrant@verify-cluster:~$
  31. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  32. no
  33. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:anonymous
  34. Error from server (Forbidden): selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope: RBAC: clusterrole.rbac.authorization.k8s.io "test" not found
  35. vagrant@verify-cluster:~$ curl -k https://c105.containers.test.cloud.ibm.com:31573/foo
  36. {
  37. "kind": "Status",
  38. "apiVersion": "v1",
  39. "metadata": {},
  40. "status": "Failure",
  41. "message": "forbidden: User \"system:anonymous\" cannot get path \"/foo\": RBAC: clusterrole.rbac.authorization.k8s.io \"test\" not found",
  42. "reason": "Forbidden",
  43. "details": {},
  44. "code": 403
  45. }vagrant@verify-cluster:~$

带有结果的测试2: Kubernetes API服务器已更新为 --anonymous-auth=false

  1. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  2. no
  3. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:anonymous
  4. Error from server (Forbidden): selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope
  5. vagrant@verify-cluster:~$ curl -k https://c105.containers.test.cloud.ibm.com:31573/foo
  6. {
  7. "kind": "Status",
  8. "apiVersion": "v1",
  9. "metadata": {},
  10. "status": "Failure",
  11. "message": "Unauthorized",
  12. "reason": "Unauthorized",
  13. "code": 401
  14. }vagrant@verify-cluster:~$
  15. vagrant@verify-cluster:~$
  16. vagrant@verify-cluster:~$
  17. vagrant@verify-cluster:~$ kubectl apply -f - <<EOF
  18. > kind: ClusterRoleBinding
  19. > apiVersion: rbac.authorization.k8s.io/v1
  20. > metadata:
  21. > name: test
  22. > roleRef:
  23. > apiGroup: rbac.authorization.k8s.io
  24. > kind: ClusterRole
  25. > name: test
  26. > subjects:
  27. > - apiGroup: rbac.authorization.k8s.io
  28. > kind: Group
  29. > name: system:serviceaccounts
  30. > - apiGroup: rbac.authorization.k8s.io
  31. > kind: Group
  32. > name: system:unauthenticated
  33. > EOF
  34. clusterrolebinding.rbac.authorization.k8s.io/test created
  35. vagrant@verify-cluster:~$
  36. vagrant@verify-cluster:~$
  37. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:serviceaccount:default:default
  38. no - RBAC: clusterrole.rbac.authorization.k8s.io "test" not found
  39. vagrant@verify-cluster:~$ kubectl auth can-i create pods -n kube-system --as=system:anonymous
  40. Error from server (Forbidden): selfsubjectaccessreviews.authorization.k8s.io is forbidden: User "system:anonymous" cannot create resource "selfsubjectaccessreviews" in API group "authorization.k8s.io" at the cluster scope: RBAC: clusterrole.rbac.authorization.k8s.io "test" not found
  41. vagrant@verify-cluster:~$ curl -k https://c105.containers.test.cloud.ibm.com:31573/foo
  42. {
  43. "kind": "Status",
  44. "apiVersion": "v1",
  45. "metadata": {},
  46. "status": "Failure",
  47. "message": "Unauthorized",
  48. "reason": "Unauthorized",
  49. "code": 401
  50. }vagrant@verify-cluster:~$

我们需要了解其他任何信息吗?
这个问题最初是在 https://hackerone.com 上提交的,但已被关闭。有人告诉我在这里打开一个问题。

Kubernetes版本
测试了Kubernetes版本1.26.15和1.30.0-rc.1,但其他版本可能也受到影响。测试是在使用IBM Cloud Kubernetes Service部署的Kubernetes集群上进行的。

云提供商

操作系统版本

安装工具
IBM Cloud Kubernetes Service

容器运行时(CRI)和版本(如适用)

相关插件(CNI,CSI等)和版本(如适用)

jq6vz3qz

jq6vz3qz1#

这个问题目前正在等待分类。
如果SIG或子项目确定这是一个相关的问题,他们将通过应用triage/accepted标签并提供进一步的指导来接受它。
组织成员可以通过在评论中写入/triage accepted来添加triage/accepted标签。
有关使用PR评论与我互动的说明,请查看here。如果您对我的行为有任何问题或建议,请针对kubernetes/test-infra仓库提出一个问题。

rfbsl7qr

rfbsl7qr2#

/sig-auth

b4lqfgs4

b4lqfgs43#

/sig auth

zengzsys

zengzsys4#

作为缓解措施:不要错误配置您的Kubernetes集群;具体来说,不要将未经身份验证的用户绑定到缺失的ClusterRole。

0s0u357o

0s0u357o5#

slack thread 开始:

4uqofj5v

4uqofj5v6#

我会将此问题保持开放一段时间以获取更多社区反馈,但我不认为我们会对此做出任何更改。

irlmq6kh

irlmq6kh7#

我的一般关注是,可能会有额外的错误信息泄露,这些信息可能更有价值。我同意这个特定的例子并不是很有影响力。

p4rjhz4m

p4rjhz4m8#

我的一般担忧是可能会泄露出更多的错误信息,这些信息可能更有价值。我同意这个特定的示例并不是很有影响力。
任何错误都来自于传递给此方法的 visitor:
kubernetes/pkg/registry/rbac/validation/rule.go
第 179 行到第 237 行 in f3a7aa7
| | func (rDefaultRuleResolver) VisitRulesFor(user user.Info, namespacestring, visitorfunc(source fmt.Stringer, rulerbacv1.PolicyRule, errerror) bool) { |
| | ifclusterRoleBindings, err:=r.clusterRoleBindingLister.ListClusterRoleBindings(); err!=nil { |
| | if!visitor(nil, nil, err) { |
| | return |
| | } |
| | } else { |
| | sourceDescriber:=&clusterRoleBindingDescriber{} |
| | for_, clusterRoleBinding:=rangeclusterRoleBindings { |
| | subjectIndex, applies:=appliesTo(user, clusterRoleBinding.Subjects, "") |
| | if!applies { |
| | continue |
| | } |
| | rules, err:=r.GetRoleReferenceRules(clusterRoleBinding.RoleRef, "") |
| | iferr!=nil { |
| | if!visitor(nil, nil, err) { |
| | return |
| | } |
| | continue |
| | } |
| | sourceDescriber.binding=clusterRoleBinding |
| | sourceDescriber.subject=&clusterRoleBinding.Subjects[subjectIndex] |
| | fori:=rangerules { |
| | if!visitor(sourceDescriber, &rules[i], nil) { |
| | return |
| | } |
| | } |
| | } |
| | } |
| | |
| | iflen(namespace) >0 { |
| | ifroleBindings, err:=r.roleBindingLister.ListRoleBindings(namespace); err!=nil { |
| | if!visitor(nil, nil, err) { |
| | return |
| | } |
| | } else { |
| | sourceDescriber:=&roleBindingDescriber{} |
| | for_, roleBinding:=rangeroleBindings { |
| | subjectIndex, applies:=appliesTo(user, roleBinding.Subjects, namespace) |
| | if!applies { |
| | continue |
| | } |
| | rules, err:=r.GetRoleReferenceRules(roleBinding.RoleRef, namespace) |
| | iferr!=nil { |
| | if!visitor(nil, nil, err) { |
| | return |
| // 这里省略了部分代码 ...
它们都归结为 "无法获取/列出四种 RBAC资源中的一个"。

展开查看全部

相关问题