aquasecurity / kube-hunter

Hunt for security weaknesses in Kubernetes clusters
Apache License 2.0
4.7k stars 581 forks source link

Adding support for log redirection using --log-file option (#329) #387

Closed milindchawre closed 3 years ago

milindchawre commented 3 years ago

Description

Fixes #329 Added --log-file option to redirect log output to a user specified file.

Contribution Guidelines

Please Read through the Contribution Guidelines.

Fixed Issues

Please mention any issues fixed in the PR by referencing it properly in the commit message. As per the convention, use appropriate keywords such as fixes, closes, resolves to automatically refer the issue. Please consult official github documentation for details.

Fixes #(329)

"BEFORE" and "AFTER" output

To verify that the change works as desired, please include an output of terminal before and after the changes under headings "BEFORE" and "AFTER".

BEFORE

No way to redirect log output to any file.

AFTER

hunterlog1

Contribution checklist

Notes

Have modified the existing test case for logging. Not completely sure whether that is enough.

codecov[bot] commented 3 years ago

Codecov Report

Merging #387 into master will increase coverage by 0.09%. The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #387      +/-   ##
==========================================
+ Coverage   63.42%   63.52%   +0.09%     
==========================================
  Files          42       42              
  Lines        2286     2289       +3     
==========================================
+ Hits         1450     1454       +4     
+ Misses        836      835       -1     
Impacted Files Coverage Δ
kube_hunter/conf/__init__.py 95.83% <100.00%> (+0.18%) :arrow_up:
kube_hunter/conf/logging.py 100.00% <100.00%> (ø)
kube_hunter/conf/parser.py 76.92% <100.00%> (+0.92%) :arrow_up:
kube_hunter/core/events/handler.py 91.08% <0.00%> (+0.99%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update e632001...a3b418d. Read the comment docs.

milindchawre commented 3 years ago

ping @iYehuda

NickYan7 commented 2 years ago

Nice job! And how can I redirect the result when I use docker to deploy the kube-hunter? Such as I execute docker run -it --rm --network host xxx/kube-hunter, the --log-file is not work... If I execute docker run -it --rm --network host xxx/kube-hunter > ./result.txt, it won't accept the any parameter so that I can't use kube-hunter by option 2 (Interface Scaning).

I also tried echo 2 | docker run -it --rm --network host xxx/kube-hunter > ./scan_result.txt, it is not work although... 😂 Screenshot 2021-08-24 下午3 12 15

Check this please, thanks a lot

@milindchawre