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

explainability #459

Merged
merged 72 commits into from
Feb 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
4684411
explainability
tanyaveksler Dec 10, 2024
8217a4b
More delicate handling of intersection of ingress and egress connecti…
tanyaveksler Dec 10, 2024
1e7cbb9
make linter happy
tanyaveksler Dec 23, 2024
faa7ad7
Merge branch 'main' into explainability_new_clean
tanyaveksler Dec 23, 2024
181b9ac
fixing lint errors
tanyaveksler Dec 23, 2024
67ef886
Merge branch 'main' into explainability_new_clean
tanyaveksler Dec 23, 2024
d50485b
More delicate handlinng of IPblock default connections explanation;
tanyaveksler Dec 23, 2024
cd17f64
More compact explainability print
tanyaveksler Jan 6, 2025
326a88e
Fixed lint error
tanyaveksler Jan 6, 2025
4395e77
Merge branch 'main' into explainability_new_clean
tanyaveksler Jan 6, 2025
929c75d
More compact explanation printing.
tanyaveksler Jan 6, 2025
ffe247c
Added more explainability tests.
tanyaveksler Jan 6, 2025
520ef12
Added more explainability tests.
tanyaveksler Jan 7, 2025
9c947f6
Merge branch 'main' into explainability_new_clean
tanyaveksler Jan 7, 2025
409629a
Added a comment
tanyaveksler Jan 7, 2025
48ceb56
Sorting together explanations for specific ports and for all ports in…
tanyaveksler Jan 7, 2025
4686e3e
Added more tests
tanyaveksler Jan 7, 2025
710077a
Added more delicate collect/override implying rules mechanism (consid…
tanyaveksler Jan 13, 2025
49050df
Make linter happy
tanyaveksler Jan 13, 2025
d78e3c4
Changed explanation output for empty Xgress rules;
tanyaveksler Jan 14, 2025
4ab3d96
make linter happy;
tanyaveksler Jan 14, 2025
2f52f7b
make linter happy
tanyaveksler Jan 14, 2025
76c3876
Merge branch 'main' into explainability_new_clean
tanyaveksler Jan 14, 2025
ae74452
changed names of pods in anp_banp_blog_demo test
tanyaveksler Jan 14, 2025
3385cb1
Changed named of pods in anp_banp_blog_demo_2 (according to the chang…
tanyaveksler Jan 14, 2025
2a86aeb
Merge branch 'main' into explainability_new_clean
tanyaveksler Jan 20, 2025
718b34d
Changed default IP block conections explanation to be the same as sys…
tanyaveksler Jan 20, 2025
44f6c94
Added explanability option documtation to REAME
tanyaveksler Jan 20, 2025
2328c54
Removed unused functions / code.
tanyaveksler Jan 20, 2025
8cb665d
Small change in explanability formatting; changed expected results ac…
tanyaveksler Jan 21, 2025
00c229b
Another change in explanation output formatting and in the expected o…
tanyaveksler Jan 21, 2025
3057057
Make linter happy.
tanyaveksler Jan 27, 2025
006dc26
Merge branch 'main' into explainability_new_clean
tanyaveksler Jan 27, 2025
78bf5fe
Added more tests.
tanyaveksler Jan 27, 2025
ac7f587
Fixed explanation handling for ingress controller.
tanyaveksler Jan 27, 2025
5a35d3c
Merge branch 'main' into explainability_new_clean;
tanyaveksler Feb 4, 2025
dd1cfbb
fixing linter errors.
tanyaveksler Feb 4, 2025
5894002
fixing linter errors.
tanyaveksler Feb 4, 2025
b0ed51c
Merge branch 'explainability_new_clean' of github.com:np-guard/netpol…
tanyaveksler Feb 4, 2025
c262857
Merge branch 'main' into explainability_new_clean
tanyaveksler Feb 4, 2025
88d34db
Avoid running explainability analysis and exposure analysis together
tanyaveksler Feb 4, 2025
c656c2c
make linter happy
tanyaveksler Feb 4, 2025
04fe5ed
Fixed ingress resources handling: collecting all ingress implying rul…
tanyaveksler Feb 4, 2025
7db86b6
Fixed collection explainability rules in Union of ConnectionSets - mo…
tanyaveksler Feb 10, 2025
7116922
Merge branch 'main' into explainability_new_clean
tanyaveksler Feb 10, 2025
91255e4
make linter happy
tanyaveksler Feb 10, 2025
66aed97
Reorganized and simplified categories in explainability output to imp…
tanyaveksler Feb 10, 2025
ef3eab0
More readable formatting of explainability output.
tanyaveksler Feb 11, 2025
782a212
More output format changes.
tanyaveksler Feb 11, 2025
65a24e8
Merge branch 'main' into explainability_new_clean
tanyaveksler Feb 11, 2025
9a938f9
Removed rule numbering. Instead, organizing rules by layers, and sort…
tanyaveksler Feb 11, 2025
76d95ae
make linter happy.
tanyaveksler Feb 11, 2025
8453eaa
update .gitignore
adisos Feb 12, 2025
9b4437b
tiny change in output
shireenf-ibm Feb 13, 2025
f796234
Merge branch 'main' into explainability_new_clean
shireenf-ibm Feb 13, 2025
f83ed64
lint fix
shireenf-ibm Feb 13, 2025
707a73b
changing LIST to list
shireenf-ibm Feb 13, 2025
68cdf79
update explain_analysis.md
adisos Feb 13, 2025
cc5f954
changes in outputs + update explain_analysis.md
shireenf-ibm Feb 13, 2025
fbb5f6b
running make test-update removes empty lines on top of files
shireenf-ibm Feb 13, 2025
e652c38
adding warning when running --explain with unsupported format
shireenf-ibm Feb 13, 2025
b30d395
ignore explain value for not supported formats
shireenf-ibm Feb 13, 2025
a32750d
fix lint errors
shireenf-ibm Feb 13, 2025
ff2df49
update example test
adisos Feb 13, 2025
8f15cd3
fix: remove connlist No conns lines from unsupported formats when run…
shireenf-ibm Feb 13, 2025
bb60efa
Merge branch 'explainability_new_clean' of github.com:np-guard/netpol…
shireenf-ibm Feb 13, 2025
49808ad
`list` support explain flag with exposure flag (#503)
shireenf-ibm Feb 13, 2025
81aa3b2
remove unused OnlyCommonRules() and unexport OnlyDefaultRule()
adisos Feb 13, 2025
6a9a9c2
unexport Explanation field in singleConnFields
adisos Feb 13, 2025
f196e42
revert changes to a deprecated func
shireenf-ibm Feb 13, 2025
bbef37f
replace "list" with "connections" - explain output
shireenf-ibm Feb 16, 2025
ec654e0
updating explain output - np rules explain
shireenf-ibm Feb 16, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
More delicate handling of intersection of ingress and egress connecti…
…ons (to preserve explainability data from both directions).

Updating testing data accordingly.
  • Loading branch information
tanyaveksler committed Dec 10, 2024
commit 8217a4bcd3cabcdb2c59ab755b2182505deaee05
4 changes: 1 addition & 3 deletions pkg/netpol/connlist/explanation_test.go
Original file line number Diff line number Diff line change
@@ -52,12 +52,10 @@ var explainTests = []struct {
// testDirName: "anp_test_10",
// },
{
testDirName: "anp_banp_blog_demo",
focusWorkload: "my-monitoring",
testDirName: "anp_banp_blog_demo",
},
{
testDirName: "anp_banp_blog_demo_2",
// focusWorkload: "my-monitoring",
},
// {
// testDirName: "ipblockstest",
49 changes: 36 additions & 13 deletions pkg/netpol/internal/common/augmented_intervalset.go
Original file line number Diff line number Diff line change
@@ -249,6 +249,32 @@
rules.Egress.Union(other.Egress, collectRules)
}

func (rules *ImplyingRulesType) onlyIngressDirection() bool {
return !rules.Ingress.Empty() && rules.Egress.Empty()
}

func (rules *ImplyingRulesType) onlyEgressDirection() bool {
return rules.Ingress.Empty() && !rules.Egress.Empty()
}

// OverrideUnlessOppositeDirections checks whether rules and other contain only rules of opposite directions
// (one of them only Ingress and another only Egress).
// This happens when performing intersection between ingress and egress connections.
// In this case the function preserves implying rules of both directions (for detailed explainability report).
// If this is not the case of 'opposite durections' scenario, the function overrides current implying rules by others'.
func (rules *ImplyingRulesType) OverrideUnlessOppositeDirections(other ImplyingRulesType) {
if rules.onlyIngressDirection() && other.onlyEgressDirection() {

Check failure on line 266 in pkg/netpol/internal/common/augmented_intervalset.go

GitHub Actions / golangci-lint

ifElseChain: rewrite if-else to switch statement (gocritic)
// opposite directions (Ingress in rules and Egress in other) -> keep Ingress, copy Egress
rules.Egress = other.Egress.Copy()
} else if rules.onlyEgressDirection() && other.onlyIngressDirection() {
// opposite directions (Egress in rules and Ingress in other) -> keep Egress, copy Ingress
rules.Ingress = other.Ingress.Copy()
} else {
// this is not the case of opposite directions -> override everything
*rules = other.Copy()
}
}

func (rules ImplyingRulesType) mayBeUpdatedBy(other ImplyingRulesType, collectRules bool) bool {
return rules.Ingress.mayBeUpdatedBy(other.Ingress, collectRules) || rules.Egress.mayBeUpdatedBy(other.Egress, collectRules)
}
@@ -453,12 +479,11 @@
// split set[left] into two intervals, while the implying rules of the second interval should get the new value (from v)
new1 := AugmentedInterval{interval: interval.New(set[left].interval.Start(), v.interval.Start()-1),
inSet: set[left].inSet, implyingRules: set[left].implyingRules.Copy()}
var newImplyingRules ImplyingRulesType
newImplyingRules := set[left].implyingRules.Copy()
if set[left].inSet == v.inSet {
newImplyingRules = set[left].implyingRules.Copy()
newImplyingRules.Union(v.implyingRules, collectRules)
} else {
newImplyingRules = v.implyingRules.Copy()
newImplyingRules.OverrideUnlessOppositeDirections(v.implyingRules)
}
new2 := AugmentedInterval{interval: interval.New(v.interval.Start(), min(set[left].interval.End(), v.interval.End())),
inSet: v.inSet, implyingRules: newImplyingRules}
@@ -470,14 +495,13 @@
(set[right].inSet != v.inSet || set[right].implyingRules.mayBeUpdatedBy(v.implyingRules, collectRules)) {
break // this is the corner case handled following the loop below
}
var newImplyingRules ImplyingRulesType
newImplyingRules := set[ind].implyingRules.Copy()
if set[ind].inSet == v.inSet {
// this interval is not impacted by v;
// however, its implying rules may be updated by those of v.
newImplyingRules = set[ind].implyingRules.Copy()
newImplyingRules.Union(v.implyingRules, collectRules)
} else {
newImplyingRules = v.implyingRules.Copy()
newImplyingRules.OverrideUnlessOppositeDirections(v.implyingRules)
}
result = append(result, AugmentedInterval{interval: set[ind].interval, inSet: v.inSet, implyingRules: newImplyingRules})
}
@@ -488,12 +512,11 @@
if left < right || (left == right && v.interval.Start() == set[left].interval.Start()) {
// a special case when left==right (i.e., v is included in one interval from set) was already handled
// at the left-hand side of the intersection of v with set
var newImplyingRules ImplyingRulesType
newImplyingRules := set[right].implyingRules.Copy()
if set[right].inSet == v.inSet {
newImplyingRules = set[right].implyingRules.Copy()
newImplyingRules.Union(v.implyingRules, collectRules)
} else {
newImplyingRules = v.implyingRules.Copy()
newImplyingRules.OverrideUnlessOppositeDirections(v.implyingRules)
}
new1 := AugmentedInterval{interval: interval.New(set[right].interval.Start(), v.interval.End()),
inSet: v.inSet, implyingRules: newImplyingRules}
@@ -537,12 +560,12 @@
res := NewAugmentedCanonicalSet(c.MinValue(), c.MaxValue(), false)
for _, left := range c.intervalSet {
if !left.inSet {
res.AddAugmentedInterval(left, false)
res.AddAugmentedInterval(left, collectRules)
}
}
for _, right := range other.intervalSet {
if !right.inSet {
res.AddAugmentedInterval(right, false)
res.AddAugmentedInterval(right, collectRules)
}
}
for _, left := range c.intervalSet {
@@ -627,12 +650,12 @@
}
for _, left := range c.intervalSet {
if !left.inSet {
res.AddAugmentedInterval(left, false)
res.AddAugmentedInterval(left, true) // collect implying rules allowed by both sets
}
}
for _, right := range other.intervalSet {
if !right.inSet {
res.AddAugmentedInterval(right, false)
res.AddAugmentedInterval(right, true) // collect implying rules allowed by both sets
}
}
return res
4 changes: 4 additions & 0 deletions test_outputs/connlist/anp_banp_blog_demo_2_explain_output.txt
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ ALLOWED SCTP:1-65535 the system default (Allow all)
ALLOWED UDP:1-65535 the system default (Allow all)

DENIED TCP:1-1233 due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

@@ -39,15 +40,18 @@ ALLOWED TCP:1234 due to the following policies//rules:
1) [ANP] allow-monitoring//Ingress rule allow-ingress-from-monitoring (Allow)

DENIED TCP:1235-8079 due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

DENIED TCP:8080 due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [ANP] pass-monitoring//Ingress rule pass-ingress-from-monitoring (Pass)
2) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

DENIED TCP:8081-9000 due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

80 changes: 80 additions & 0 deletions test_outputs/connlist/anp_banp_blog_demo_explain_output.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN 0.0.0.0-255.255.255.255 => foo/my-foo[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [NP] foo/allow-monitoring//Ingress (captured but not selected by any Ingress rule)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN bar/my-bar[Pod] => foo/my-foo[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [NP] foo/allow-monitoring//Ingress (captured but not selected by any Ingress rule)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN baz/my-baz[Pod] => bar/my-bar[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN baz/my-baz[Pod] => foo/my-foo[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [NP] foo/allow-monitoring//Ingress (captured but not selected by any Ingress rule)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN foo/my-foo[Pod] => bar/my-bar[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN monitoring/my-monitoring[Pod] => bar/my-bar[Pod]:

No Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (DENIED)
1) [ANP] pass-monitoring//Ingress rule pass-ingress-from-monitoring (Pass)
2) [BANP] default//Ingress rule deny-ingress-from-all-namespaces (Deny)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN monitoring/my-monitoring[Pod] => baz/my-baz[Pod]:

All Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (ALLOWED)
1) [ANP] allow-monitoring//Ingress rule allow-ingress-from-monitoring (Allow)

----------------------------------------------------------------------------------------------------------------------------------------------------------------
CONNECTIONS BETWEEN monitoring/my-monitoring[Pod] => foo/my-foo[Pod]:

All Connections due to the following policies//rules:
EGRESS DIRECTION (ALLOWED) due to the system default (Allow all)
INGRESS DIRECTION (ALLOWED)
1) [ANP] pass-monitoring//Ingress rule pass-ingress-from-monitoring (Pass)
2) [NP] foo/allow-monitoring//Ingress rule #1

----------------------------------------------------------------------------------------------------------------------------------------------------------------
The following nodes are connected due to the system default (Allow all):
0.0.0.0-255.255.255.255 => bar/my-bar[Pod]
0.0.0.0-255.255.255.255 => baz/my-baz[Pod]
0.0.0.0-255.255.255.255 => monitoring/my-monitoring[Pod]
bar/my-bar[Pod] => 0.0.0.0-255.255.255.255
bar/my-bar[Pod] => baz/my-baz[Pod]
bar/my-bar[Pod] => monitoring/my-monitoring[Pod]
baz/my-baz[Pod] => 0.0.0.0-255.255.255.255
baz/my-baz[Pod] => monitoring/my-monitoring[Pod]
foo/my-foo[Pod] => 0.0.0.0-255.255.255.255
foo/my-foo[Pod] => baz/my-baz[Pod]
foo/my-foo[Pod] => monitoring/my-monitoring[Pod]
monitoring/my-monitoring[Pod] => 0.0.0.0-255.255.255.255

This file was deleted.

Loading