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

discovery: Make kubectl.py able to find kubectl #511

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

martbhell
Copy link

@martbhell martbhell commented Jun 3, 2022

Description

I was trying to get kube-hunter to display something about the remote k3s cluster with only port 6443 accessible.
While doing so I saw in the debug log output that it couldn't find kubectl, even though it's in $PATH

Doing so I eventually made conclusion that the arguments in subprocess check_output function in python 3.8.10 needs to be a
list. I do not know if this has changed in python. There might be better ways to change this. At least this change makes the code find the kubectl version.

Contribution Guidelines

Please Read through the Contribution Guidelines.

Fixed Issues

Fixes #512

"BEFORE" and "AFTER" output

BEFORE

Before the change the error in "--log debug" would look like:

2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client

AFTER

And if I add small code change to also print the exception error it
prints:

2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl [Errno 2] No such file or directory: 'kubectl version --client'
2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client

Contribution checklist

  • I have read the Contributing Guidelines.
  • The commits refer to an active issue in the repository.
  • I have added automated testing to cover this case.

Notes

Haven't added any testing as I'm completely unfamiliar with Mock. Suggestion for what to test would be much appreciated!

The arguments in subprocess check_output in python 3.8.10 needs to be a
list.

Before the change the error in "--log debug" would look like:

```
2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client
```

And if I add small code change to also print the exception error it
prints:
```
2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl [Errno 2] No such file or directory: 'kubectl version --client'
2022-06-03 13:54:56,497 DEBUG kube_hunter.modules.discovery.kubectl Could not find kubectl client
```
@CLAassistant
Copy link

CLAassistant commented Jun 3, 2022

CLA assistant check
All committers have signed the CLA.

Co-authored-by: Md Safiyat Reza <reza.safiyat@gmail.com>
@martbhell
Copy link
Author

And shlex seems to have been in python3 for a long time. Looks good to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

discover: kubectl.py does not find kubectl
3 participants