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

K8s provider: support KUBECONFIG environment variable containing multiple paths #162

Open
raesene opened this issue Aug 15, 2022 · 3 comments
Assignees
Labels
good first issue Good for newcomers kind/bug Something isn't working platform/k8s status/confirmed

Comments

@raesene
Copy link
Contributor

raesene commented Aug 15, 2022

What is not working?
Running Kubernetes Attacks when the user is using a KUBECONFIG environment variable

What OS are you using?
Mac OS X

What is your Stratus Red Team version?
2.3.0

Full output?
First run with KUBECONFIG set, output looks like this

stratus detonate k8s.persistence.create-token
2022/08/15 18:30:03 Checking your authentication against kubernetes
2022/08/15 18:30:03 unable to build kube config: stat /Users/rory.mccune/.kube/config:/Users/rory.mccune/.kube/kubeconfigs/kubeadm2nodeconfig.yaml:/Users/rory.mccune/.kube/kubeconfigs/traceeclusterconfig.yaml:/Users/rory.mccune/.kube/kubeconfigs/kubeadm122config.yaml:/Users/rory.mccune/.kube/kubeconfigs/kubeadmcontainerd.yaml:/Users/rory.mccune/.kube/kubeconfigs/calicotracee.yaml:/Users/rory.mccune/.kube/kubeconfigs/kube123.yaml:/Users/rory.mccune/.kube/kubeconfigs/kubeadm118.yaml:/Users/rory.mccune/.kube/kubeconfigs/ubuntu2110.yaml:/Users/rory.mccune/.kube/kubeconfigs/kube124.yaml:/Users/rory.mccune/.kube/kubeconfigs/kubeadm123win.yaml: no such file or directory

If I then unset the KUBECONFIG variable the attack works ok.

stratus detonate k8s.persistence.create-token
2022/08/15 18:30:17 Checking your authentication against kubernetes
2022/08/15 18:30:18 Creating a long-lived token for the service account clusterrole-aggregation-controller in kube-system
2022/08/15 18:30:18 Successfully created a long-lived token valid for 1 year:
@christophetd
Copy link
Contributor

Thanks for reporting! What behavior would you expect?

@raesene
Copy link
Contributor Author

raesene commented Aug 21, 2022

So I think the general expectation here is that Stratus would pick up the current-context being used by the user and send requests to the cluster in that context. This should work with environment variables and the default Kubernetes kubeconfig. At the moment stratus is handling some cases ok but not working with a case of an environment variable with multiple kubeconfigs in it.

It looks like the one way to set that is to use the NewDefaultClientConfigLoadingRules call in clientcmd . One example of a tool that uses it is rbac-police

@christophetd
Copy link
Contributor

Stratus Red Team already picks up the current context - it should also honor the KUBECONFIG environment variable if it's set, c.f. https://github.com/DataDog/stratus-red-team/blob/main/v2/internal/providers/kubernetes.go#L51-L85, but it fails to consider that it may contain multiple paths separated by : (https://kubernetes.io/docs/tasks/access-application-cluster/configure-access-multiple-clusters/#set-the-kubeconfig-environment-variable)

Thanks, updated the issue name to make clearer what we need to fix

@christophetd christophetd changed the title Running Kubernetes Attacks when the user is using a KUBECONFIG environment variable K8s provider: support KUBECONFIG environment variable containing multiple paths Aug 22, 2022
@christophetd christophetd added the good first issue Good for newcomers label Jan 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/bug Something isn't working platform/k8s status/confirmed
Projects
None yet
Development

No branches or pull requests

2 participants