Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A potential risk in spiderpool that could lead to takeover of the cluster #3361

Closed
HouqiyuA opened this issue Apr 15, 2024 · 9 comments · Fixed by #3522 or #3608
Closed

A potential risk in spiderpool that could lead to takeover of the cluster #3361

HouqiyuA opened this issue Apr 15, 2024 · 9 comments · Fixed by #3522 or #3608

Comments

@HouqiyuA
Copy link

What would you like to be added?

Dear Team Members:

Greetings! Our team is very interested in your project and we recently identified a potential RBAC security risk while doing a security assessment of your project. Therefore, we would like to report it to you and provide you with the relevant details so that you can fix and improve it accordingly. I couldn't find a private email to report security risks, so I raised this issue. If there is anything inappropriate about it, I hope you can forgive me.
Details:

In this Kubernetes project, there exists a ClusterRole that has been granted list secrets high-risk permissions. These permissions allow the role to list confidential information across the cluster. An attacker could impersonate the ServiceAccount bound to this ClusterRole and use its high-risk permissions to list secrets information across the cluster. By combining the permissions of other roles, an attacker can elevate the privileges and further take over the entire cluster.

we constructed the following attack vectors.

First, you need to get a token for the ServiceAccount that has this high-risk privilege. If you are already in a Pod and have this override, you can directly run the following command to get the token: cat /var/run/secrets/[kubernetes.io/serviceaccount/](http://kubernetes.io/serviceaccount/) token. If you are on a node other than a Pod, you can run the following command to get the kubectl describe secret .

Use the obtained token information to authenticate with the API server. By including the token in the request, you can be recognized as a legitimate user with a ServiceAccount and gain all privileges associated with the ServiceAccount. As a result, this ServiceAccount identity can be used to list all secrets in the cluster.

We give two ways to further utilize ServiceAccount Token with other privileges to take over the cluster:

Method 1: Elevation of Privilege by Utilizing ServiceAccount Token Bound to ClusterAdmin

Directly use a Token with the ClusterAdmin role permissions that has the authority to control the entire cluster. By authenticating with this token, you can gain full control of the cluster.

Method 2: Create Privileged Containers with ServiceAccount Token with create pods permission You can use this ServiceAccount Token to create a privileged container that mounts the root directory and schedules it to the master node in a taint-tolerant way, so that you can access and leak the master node's kubeconfig configuration file. In this way you can take over the entire cluster.

For the above attack chain we have developed exploit code and uploaded it to github: https://github.com/HouqiyuA/k8s-rbac-poc
Mitigation methods are explored:

Carefully evaluate the permissions required for each user or service account to ensure that it is following the principle of least privilege and to avoid over-authorization.

If list secrets is a required permission, consider using more granular RBAC rules. Role Binding can be used to grant list secrets permissions instead of ClusterRole, which restricts permissions to specific namespaces or resources rather than the entire cluster.

Isolate different applications into different namespaces and use namespace-level RBAC rules to restrict access. This reduces the risk of privilege leakage across namespaces

Looking forward to hearing from you and discussing this risk in more detail with us, thank you very much for your time and attention.

Best wishes.

HouqiyuA

Why is this needed?

None

How to implement it (if possible)?

None

Additional context

None

@cyclinder
Copy link
Collaborator

Hi @HouqiyuA, thanks for the report!

Currently, spiderpool's RBAC permissions are configured in a minimal privilege design, in other words, it does not have full control over the cluster, it only has the permissions needed by the spiderpool components to access cluster resources. If an attacker steals our token, they shouldn't be able to take over the cluster completely, right?

In response to your method 1, I would say: "It's ok but not good". We don't want to gain full control of the cluster.

For method 2:

Sorry, I'm unfamiliar with this, Could you provide an example? thanks. this should be the case for most of the kubernetes projects in the community today (e.g. calico, cilium), and they should all have the same risks. I'm curious as to how they handle this.

@HouqiyuA
Copy link
Author

HouqiyuA commented Apr 16, 2024 via email

@cyclinder
Copy link
Collaborator

oh, you are right, I just noticed the spiderpool-admin has configured apiGroups: [*], this is unexpected. thanks for the catch!

we should remove this, Are you able to send a PR for this if you are interested in this?

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    meta.helm.sh/release-name: spiderpool
    meta.helm.sh/release-namespace: kube-system
  creationTimestamp: "2024-04-16T03:03:03Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: spiderpool-admin
  resourceVersion: "1630"
  uid: 9802fdef-d582-40ca-96be-5fab2e5cbf1f
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - namespaces
  - nodes
  - pods
  - pods/status
  verbs:
  - delete
  - deletecollection
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch

@HouqiyuA
Copy link
Author

HouqiyuA commented Apr 16, 2024 via email

@cyclinder
Copy link
Collaborator

can you give me a cve?

sorry, I can't understand this, what does your exact mean?

@HouqiyuA
Copy link
Author

HouqiyuA commented Apr 17, 2024 via email

@HouqiyuA
Copy link
Author

oh, you are right, I just noticed the spiderpool-admin has configured apiGroups: [*], this is unexpected. thanks for the catch!

we should remove this, Are you able to send a PR for this if you are interested in this?

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  annotations:
    meta.helm.sh/release-name: spiderpool
    meta.helm.sh/release-namespace: kube-system
  creationTimestamp: "2024-04-16T03:03:03Z"
  labels:
    app.kubernetes.io/managed-by: Helm
  name: spiderpool-admin
  resourceVersion: "1630"
  uid: 9802fdef-d582-40ca-96be-5fab2e5cbf1f
rules:
- apiGroups:
  - ""
  resources:
  - configmaps
  - endpoints
  - namespaces
  - nodes
  - pods
  - pods/status
  verbs:
  - delete
  - deletecollection
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - ""
  resources:
  - events
  verbs:
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch
- apiGroups:
  - '*'
  resources:
  - '*'
  verbs:
  - get
  - list
  - watch

Has the issue been fixed? Can we be assigned a CVE number after fixing this issue?

@ty-dc ty-dc added the kind/bug label Apr 29, 2024
@cyclinder
Copy link
Collaborator

Hi @HouqiyuA, Sorry for the slow response. The issue hasn't been fixed, Are you interested in fixing this? If not, I will send a PR for this. Thanks!

@HouqiyuA
Copy link
Author

HouqiyuA commented Apr 30, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment