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

feat: consider ingress and egress rules for networkpolicies #310

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

Conversation

tthvo
Copy link
Contributor

@tthvo tthvo commented Jun 18, 2024

What this PR does / why we need it?

This PR added consideration for discovering second-level unused NetworkPolicies with matching .spec.podSelector, but unmatched pods in Ingress/Egress rules.

See #296 (comment)

kor version: vdev

  _  _____  ____
 | |/ / _ \|  _ \
 | ' / | | | |_) |
 | . \ |_| |  _ <
 |_|\_\___/|_| \_\

Unused resources in namespace: "default"
+---+---------------+---------------------+---------------------------------------------------------+
| # | RESOURCE TYPE |    RESOURCE NAME    |                         REASON                          |
+---+---------------+---------------------+---------------------------------------------------------+
| 1 | NetworkPolicy | test-network-policy | NetworkPolicy Ingress and Egress rules apply to 0 pods |
+---+---------------+---------------------+---------------------------------------------------------+

PR Checklist

  • This PR adds K8s exceptions (false positives)
  • This PR adds new code
  • This PR includes tests for new/existing code
  • This PR adds docs

GitHub Issue

Solves #312

Notes for your reviewers

Rules with ipBlock is considered "used" here.

@codecov-commenter
Copy link

codecov-commenter commented Jun 18, 2024

Codecov Report

Attention: Patch coverage is 66.66667% with 24 lines in your changes missing coverage. Please review.

Project coverage is 42.39%. Comparing base (181141d) to head (d60bb53).

Files Patch % Lines
pkg/kor/networkpolicies.go 62.50% 11 Missing and 13 partials ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #310      +/-   ##
==========================================
+ Coverage   42.01%   42.39%   +0.38%     
==========================================
  Files          61       61              
  Lines        3175     3236      +61     
==========================================
+ Hits         1334     1372      +38     
- Misses       1633     1644      +11     
- Partials      208      220      +12     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@doronkg
Copy link
Contributor

doronkg commented Jun 18, 2024

@tthvo I've created a new issue to address this enhancement - #312, please update the description and reference it.
Let us know when the draft is ready to review 💪

@yonahd yonahd linked an issue Jun 18, 2024 that may be closed by this pull request
@tthvo tthvo force-pushed the netpol branch 2 times, most recently from ca7c6b8 to a55a8d8 Compare June 25, 2024 20:12
@tthvo tthvo marked this pull request as ready for review June 25, 2024 20:57
@tthvo
Copy link
Contributor Author

tthvo commented Jun 25, 2024

@doronkg @yonahd I think this is ready now for review. I have run some extensive tests but might miss some cases. Please let me know what you think :D

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.

feature: Discover second-level unused NetworkPoliciess
3 participants