Skip to content

Commit 28fbe92

Browse files
authored
Merge pull request #645 from kubescape/fix/detecting-public-istio-gw
Fixing the detection of public Istio Gateways
2 parents bedef41 + dd17500 commit 28fbe92

File tree

1 file changed

+23
-7
lines changed
  • rules/exposure-to-internet-via-istio-ingress

1 file changed

+23
-7
lines changed

rules/exposure-to-internet-via-istio-ingress/raw.rego

+23-7
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,12 @@ deny[msga] {
1919
gateway.metadata.name == vs_gw.name
2020
get_namespace(gateway) == vs_gw.namespace
2121

22-
# Find the connected Istio Ingress Gateway that should be a LoadBalancer if it is exposed to the internet
23-
istioingressgateway := input[_]
24-
istioingressgateway.kind == "Service"
25-
istioingressgateway.metadata.namespace == "istio-system"
26-
gateway.spec.selector[_] == istioingressgateway.metadata.labels[_]
22+
# print("Found the gateway that the virtualservice is connected to", gateway)
2723

28-
# Check if the Istio Ingress Gateway is exposed to the internet
29-
is_exposed_service(istioingressgateway)
24+
# Either the gateway is exposed via LoadBalancer/n service OR has "public" suffix
25+
is_gateway_public(gateway, input)
26+
27+
# print("Gateway is public", gateway)
3028

3129
# Check if the VirtualService is connected to an workload
3230
# First, find the service that the VirtualService is connected to
@@ -40,15 +38,21 @@ deny[msga] {
4038
# Check if the service is the target of the VirtualService
4139
connected_service.metadata.name == target_name
4240

41+
# print("Found the service that the virtualservice is connected to", connected_service)
42+
4343
# Check if the service is connected to a workload
4444
wl := input[_]
4545
is_same_namespace(connected_service, wl)
4646
spec_template_spec_patterns := {"Deployment", "ReplicaSet", "DaemonSet", "StatefulSet", "Pod", "Job", "CronJob"}
4747
spec_template_spec_patterns[wl.kind]
4848
wl_connected_to_service(wl, connected_service)
4949

50+
# print("Found the workload that the service is connected to", wl)
51+
5052
failedPaths := [sprintf("spec.http[%d].routes[%d].destination.host", [i,j])]
5153

54+
# print("Found the failed paths", failedPaths)
55+
5256
msga := {
5357
"alertMessage": sprintf("workload '%v' is exposed through virtualservice '%v'", [wl.metadata.name, virtualservice.metadata.name]),
5458
"packagename": "armo_builtins",
@@ -73,6 +77,18 @@ deny[msga] {
7377

7478
# ====================================================================================
7579

80+
is_gateway_public(gateway, inputs) {
81+
endswith(gateway.metadata.name, "public")
82+
}
83+
84+
is_gateway_public(gateway, inputs) {
85+
inputs[_].kind == "Service"
86+
inputs[_].metadata.namespace == "istio-system"
87+
gateway.spec.selector[_] == inputs[_].metadata.labels[_]
88+
is_exposed_service(inputs[_])
89+
}
90+
91+
7692
get_namespace(obj) = namespace {
7793
obj.metadata
7894
obj.metadata.namespace

0 commit comments

Comments
 (0)