Skip to content

Commit ebcf91a

Browse files
committed
test with vm- vm is exposet to all TCP conns
1 parent 14a424c commit ebcf91a

13 files changed

Lines changed: 228 additions & 1 deletion

pkg/netpol/connlist/connlist_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2155,6 +2155,11 @@ var goodPathTests = []struct {
21552155
testDirName: "virtual_machines_example",
21562156
outputFormats: ValidFormats,
21572157
},
2158+
{
2159+
// a test with UDN having a VM and Ingress-Controller; external ingress ports to a service in a UDN are allowed to the VM
2160+
testDirName: "udn_with_vm_and_ingress_controller",
2161+
outputFormats: ValidFormats,
2162+
},
21582163
}
21592164

21602165
func runParsedResourcesConnlistTests(t *testing.T, testList []examples.ParsedResourcesTest) {

pkg/netpol/connlist/internal/ingressanalyzer/ingress_analyzer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,10 @@ func (ia *IngressAnalyzer) getIngressPeerConnection(peer eval.Peer, actualServic
385385
return nil, err
386386
}
387387
// only TCP ports are acceptable for Ingress resource
388+
// Note that: if the current peer is a virtual-machine then named-ports will always have no match and be skipped;
389+
// since virtual-machine does not specify any ports in its spec; so named-port can not be converted
388390
if protocol != string(corev1.ProtocolTCP) || portInt < 0 { // no matching port for the given named port
389-
continue
391+
continue // skip
390392
}
391393
portNum = int(portInt)
392394
}

pkg/netpol/eval/check.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/np-guard/models/pkg/netset"
1919

2020
"github.com/np-guard/netpol-analyzer/pkg/internal/netpolerrors"
21+
"github.com/np-guard/netpol-analyzer/pkg/manifests/parser"
2122
"github.com/np-guard/netpol-analyzer/pkg/netpol/eval/internal/k8s"
2223
"github.com/np-guard/netpol-analyzer/pkg/netpol/internal/alerts"
2324
"github.com/np-guard/netpol-analyzer/pkg/netpol/internal/common"
@@ -175,6 +176,10 @@ func GetPeerExposedTCPConnections(peer Peer) *common.ConnectionSet {
175176
case *k8s.IPBlockPeer:
176177
return nil
177178
case *k8s.WorkloadPeer:
179+
// since virtual-machine specs does not contain Ports field(s); assuming it is exposed on all TCP conns
180+
if currentPeer.Kind() == parser.VirtualMachine {
181+
return common.GetAllTCPConnections()
182+
}
178183
return currentPeer.Pod.PodExposedTCPConnections()
179184
case *k8s.PodPeer:
180185
return currentPeer.Pod.PodExposedTCPConnections()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
src,dst,conn
2+
0.0.0.0-255.255.255.255[External],green[udn]/vm-a[VirtualMachine],All Connections
3+
green[udn]/vm-a[VirtualMachine],0.0.0.0-255.255.255.255[External],All Connections
4+
{ingress-controller},green[udn]/vm-a[VirtualMachine],"TCP 8000,8090"
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
digraph {
2+
subgraph "cluster_green[udn]" {
3+
color="black"
4+
fontcolor="black"
5+
"green[udn]/vm-a[VirtualMachine]" [label="vm-a[VirtualMachine]" color="blue" fontcolor="blue"]
6+
label="green[udn]"
7+
}
8+
"0.0.0.0-255.255.255.255[External]" [label="0.0.0.0-255.255.255.255[External]" color="red2" fontcolor="red2"]
9+
"{ingress-controller}" [label="{ingress-controller}" color="blue" fontcolor="blue"]
10+
"0.0.0.0-255.255.255.255[External]" -> "green[udn]/vm-a[VirtualMachine]" [label="All Connections" color="gold2" fontcolor="darkgreen" weight=0.5]
11+
"green[udn]/vm-a[VirtualMachine]" -> "0.0.0.0-255.255.255.255[External]" [label="All Connections" color="gold2" fontcolor="darkgreen" weight=1]
12+
"{ingress-controller}" -> "green[udn]/vm-a[VirtualMachine]" [label="TCP 8000,8090" color="gold2" fontcolor="darkgreen" weight=1]
13+
}
20.4 KB
Loading
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"src": "0.0.0.0-255.255.255.255[External]",
4+
"dst": "green[udn]/vm-a[VirtualMachine]",
5+
"conn": "All Connections"
6+
},
7+
{
8+
"src": "green[udn]/vm-a[VirtualMachine]",
9+
"dst": "0.0.0.0-255.255.255.255[External]",
10+
"conn": "All Connections"
11+
},
12+
{
13+
"src": "{ingress-controller}",
14+
"dst": "green[udn]/vm-a[VirtualMachine]",
15+
"conn": "TCP 8000,8090"
16+
}
17+
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
| src | dst | conn |
2+
|-----|-----|------|
3+
| 0.0.0.0-255.255.255.255[External] | green[udn]/vm-a[VirtualMachine] | All Connections |
4+
| green[udn]/vm-a[VirtualMachine] | 0.0.0.0-255.255.255.255[External] | All Connections |
5+
| {ingress-controller} | green[udn]/vm-a[VirtualMachine] | TCP 8000,8090 |
Lines changed: 56 additions & 0 deletions
Loading
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
green[udn]:
3+
0.0.0.0-255.255.255.255[External] => green[udn]/vm-a[VirtualMachine] : All Connections
4+
green[udn]/vm-a[VirtualMachine] => 0.0.0.0-255.255.255.255[External] : All Connections
5+
{ingress-controller} => green[udn]/vm-a[VirtualMachine] : TCP 8000,8090

0 commit comments

Comments
 (0)