vchinnipilli / kubestriker

A Blazing fast Security Auditing tool for Kubernetes
https://github.com/vchinnipilli/kubestriker
Apache License 2.0
980 stars 106 forks source link

Doesn't work with my kubeconfig file. #6

Closed anjuls closed 3 years ago

anjuls commented 3 years ago
apiVersion: v1
kind: Config
clusters:
- name: "xxxx-cluster7"
  cluster:
    server: "https://xxxxx.com/k8s/clusters/c-hkpbf"

users:
- name: "xxxx-cluster7"
  user:
    token: "kubeconfig-user-swrnv:*******************************************************"

contexts:
- name: "xxxx-cluster7"
  context:
    user: "xxxx-cluster7"
    cluster: "xxxx-cluster7"

current-context: "xxxx-cluster7"

After selecting option 2 (configfile) -> default, it gives me HTTPS URL to select and then it fails. saying input is not valid.

vasantchinnipilli commented 3 years ago

Hi @anjuls Thank you for reporting this issue.

Could you please help me with the below information?

1) Were you able to scan using Target URL instead of choosing from config file? If yes, did it work normally? 2) Please set your server url and Token as below and try curl command and see if you can get a http 200 response

APISERVER='' TOKEN=''

curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure

3) Is your cluster running on GKE/Azure?

raesene commented 3 years ago

FWIW, that server URL does not look like a standard k8s API server, you wouldn't expect to see a path in the server parameters, just a hostname/IP address and port. Also there's no certificate-authority-data field in cluster, which client apps will usually use to validate the authenticity of the server cert.

So an interesting piece of information that would likely help debug this issue is, what distribution of Kubernetes is in use here?

anjuls commented 3 years ago

I am using EKS and that config file works with other Kubernetes clients (like k9s, kubectl) API Endpoint is behind the ELB so you are seeing that kind of URL and user token is used for authentication.

@kubestrike Target URL didn't work, it just came out without any error. And I got HTTP 200.

kubestrike$ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "ip-xxxxx.us-west-2.compute.internal:443"
    }
  ]
vasantchinnipilli commented 3 years ago

Hi @anjuls ,

Can you please use "ip-xxxxx.us-west-2.compute.internal:443" as listed above to scan your Target?

Please let me know if you have any issues.

Regards, Vasant

anjuls commented 3 years ago
(env) xxx@xxx:~/learning/kubestrike/kubestrike$ curl $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure
{
  "kind": "APIVersions",
  "versions": [
    "v1"
  ],
  "serverAddressByClientCIDRs": [
    {
      "clientCIDR": "0.0.0.0/0",
      "serverAddress": "ip-xxxxx.us-west-2.compute.internal:443"
    }
  ]
(env) xxx@xxx:~/learning/kubestrike/kubestrike$ python -m kubestrike 

  ###########################################################################
  ______          __         __                    __       _ __          __  
  \ \ \ \        / /____  __/ /_  ___        _____/ /______(_) /_____     \ \ 
   \ \ \ \______/ //_/ / / / __ \/ _ \______/ ___/ __/ ___/ / //_/ _ \_____\ \
   / / / /_____/ ,< / /_/ / /_/ /  __/_____(__  ) /_/ /  / / ,< /  __/_____/ /
  /_/_/_/     /_/|_|\__,_/_.___/\___/     /____/\__/_/  /_/_/|_|\___/     /_/ 

  ###########################################################################   v1.0.0

[+] Gearing up Kube-Strike......................................................

Choose one of the below options: (Use arrow keys)
Enter the target K8s Endpoint : ip-xxxx.us-west-2.compute.internal:443
 ---------------------------------------
< Target is neither reachable nor valid >
 ---------------------------------------
          \  ^__^
           \ (oo)\________
             (__)\        )\/\
                  ||----W |
                  ||     ||
vasantchinnipilli commented 3 years ago

Hi @anjuls ,

Just tested on a few clusters and it Seems to be working as expected.

You may have to try with the actual Kubernetes cluster EndPoint.