@@ -6,28 +6,33 @@ deny[msga] {
6
6
virtualservice := input[_]
7
7
virtualservice.kind == " VirtualService"
8
8
9
+ # Get the namescape of the VirtualService
10
+ vs_ns := get_namespace (virtualservice)
11
+ # Looping over the gateways of the VirtualService
12
+ vs_gw_name := virtualservice.spec.gateways[_]
13
+ # Get the namespace of the Gateway
14
+ vs_gw = get_vs_gw_ns (vs_ns, vs_gw_name)
15
+
9
16
# Check if the VirtualService is connected to a Gateway
10
17
gateway := input[_]
11
18
gateway.kind == " Gateway"
12
-
13
- is_same_namespace (gateway, virtualservice)
14
- virtualservice.spec.gateways[_] == gateway.metadata.name
19
+ gateway.metadata.name == vs_gw.name
20
+ get_namespace (gateway) == vs_gw.namespace
15
21
16
22
# Find the connected Istio Ingress Gateway that should be a LoadBalancer if it is exposed to the internet
17
23
istioingressgateway := input[_]
18
24
istioingressgateway.kind == " Service"
19
25
istioingressgateway.metadata.namespace == " istio-system"
20
26
gateway.spec.selector[_] == istioingressgateway.metadata.labels[_]
21
27
22
-
23
28
# Check if the Istio Ingress Gateway is exposed to the internet
24
29
is_exposed_service (istioingressgateway)
25
30
26
31
# Check if the VirtualService is connected to an workload
27
32
# First, find the service that the VirtualService is connected to
28
33
connected_service := input[_]
29
34
connected_service.kind == " Service"
30
- fqsn := get_fqsn (get_namespace (virtualservice), virtualservice.spec.http[_ ].route[_ ].destination.host)
35
+ fqsn := get_fqsn (get_namespace (virtualservice), virtualservice.spec.http[i ].route[j ].destination.host)
31
36
target_ns := split (fqsn," ." )[1 ]
32
37
target_name := split (fqsn," ." )[0 ]
33
38
# Check if the service is in the same namespace as the VirtualService
@@ -42,7 +47,7 @@ deny[msga] {
42
47
spec_template_spec_patterns[wl.kind]
43
48
wl_connected_to_service (wl, connected_service)
44
49
45
- result := svc_connected_to_virtualservice (connected_service, virtualservice)
50
+ failedPaths := [ sprintf ( " spec.http[%d].routes[%d].destination.host " , [i,j])]
46
51
47
52
msga := {
48
53
" alertMessage" : sprintf (" workload '%v' is exposed through virtualservice '%v'" , [wl.metadata.name, virtualservice.metadata.name]),
@@ -54,14 +59,14 @@ deny[msga] {
54
59
" k8sApiObjects" : [wl]
55
60
},
56
61
" relatedObjects" : [
57
- {
62
+ {
58
63
" object" : virtualservice,
59
- " reviewPaths" : result ,
60
- " failedPaths" : result ,
64
+ " reviewPaths" : failedPaths ,
65
+ " failedPaths" : failedPaths ,
61
66
},
62
- {
63
- " object" : connected_service,
64
- }
67
+ {
68
+ " object" : connected_service,
69
+ }
65
70
]
66
71
}
67
72
}
@@ -79,6 +84,20 @@ get_namespace(obj) = namespace {
79
84
namespace := " default"
80
85
}
81
86
87
+ get_vs_gw_ns (vs_ns, vs_gw_name) = {" name" : name, " namespace" : ns} {
88
+ # Check if there is a / in the gateway name
89
+ count (split (vs_gw_name, " /" )) == 2
90
+ ns := split (vs_gw_name, " /" )[0 ]
91
+ name := split (vs_gw_name, " /" )[1 ]
92
+ }
93
+
94
+ get_vs_gw_ns (vs_ns, vs_gw_name) = {" name" : name, " namespace" : ns} {
95
+ # Check if there is no / in the gateway name
96
+ count (split (vs_gw_name, " /" )) == 1
97
+ ns := vs_ns
98
+ name := vs_gw_name
99
+ }
100
+
82
101
is_same_namespace (obj1, obj2) {
83
102
obj1.metadata.namespace == obj2.metadata.namespace
84
103
}
@@ -141,4 +160,3 @@ get_fqsn(ns, dest_host) = fqsn {
141
160
}
142
161
143
162
144
-
0 commit comments