@@ -5,7 +5,7 @@ deny[msga] {
5
5
service := input[_]
6
6
service.kind == " Service"
7
7
is_exposed_service (service)
8
-
8
+
9
9
wl := input[_]
10
10
spec_template_spec_patterns := {" Deployment" , " ReplicaSet" , " DaemonSet" , " StatefulSet" , " Pod" , " Job" , " CronJob" }
11
11
spec_template_spec_patterns[wl.kind]
@@ -32,7 +32,7 @@ deny[msga] {
32
32
deny[msga] {
33
33
ingress := input[_]
34
34
ingress.kind == " Ingress"
35
-
35
+
36
36
svc := input[_]
37
37
svc.kind == " Service"
38
38
@@ -49,7 +49,7 @@ deny[msga] {
49
49
wl_connected_to_service (wl, svc)
50
50
51
51
result := svc_connected_to_ingress (svc, ingress)
52
-
52
+
53
53
msga := {
54
54
" alertMessage" : sprintf (" workload '%v' is exposed through ingress '%v'" , [wl.metadata.name, ingress.metadata.name]),
55
55
" packagename" : " armo_builtins" ,
@@ -70,7 +70,51 @@ deny[msga] {
70
70
}
71
71
]
72
72
}
73
- }
73
+ }
74
+
75
+ deny[msga] {
76
+ httproute := input[_]
77
+ httproute.kind == " HTTPRoute"
78
+
79
+ svc := input[_]
80
+ svc.kind == " Service"
81
+
82
+ # Make sure that they belong to the same namespace
83
+ svc.metadata.namespace == httproute.metadata.namespace
84
+
85
+ # avoid duplicate alerts
86
+ # if service is already exposed through NodePort or LoadBalancer workload will fail on that
87
+ not is_exposed_service (svc)
88
+
89
+ wl := input[_]
90
+ wl.metadata.namespace == svc.metadata.namespace
91
+ spec_template_spec_patterns := {" Deployment" , " ReplicaSet" , " DaemonSet" , " StatefulSet" , " Pod" , " Job" , " CronJob" }
92
+ spec_template_spec_patterns[wl.kind]
93
+ wl_connected_to_service (wl, svc)
94
+
95
+ result := svc_connected_to_httproute (svc, httproute)
96
+
97
+ msga := {
98
+ " alertMessage" : sprintf (" workload '%v' is exposed through httproute '%v'" , [wl.metadata.name, httproute.metadata.name]),
99
+ " packagename" : " armo_builtins" ,
100
+ " failedPaths" : [],
101
+ " fixPaths" : [],
102
+ " alertScore" : 7 ,
103
+ " alertObject" : {
104
+ " k8sApiObjects" : [wl]
105
+ },
106
+ " relatedObjects" : [
107
+ {
108
+ " object" : httproute,
109
+ " reviewPaths" : result,
110
+ " failedPaths" : result,
111
+ },
112
+ {
113
+ " object" : svc,
114
+ }
115
+ ]
116
+ }
117
+ }
74
118
75
119
# ====================================================================================
76
120
@@ -90,6 +134,10 @@ wl_connected_to_service(wl, svc) {
90
134
wl.spec.selector.matchLabels == svc.spec.selector
91
135
}
92
136
137
+ wl_connected_to_service (wl, svc) {
138
+ count ({x | svc.spec.selector[x] == wl.spec.template.metadata.labels[x]}) == count (svc.spec.selector)
139
+ }
140
+
93
141
# check if service is connected to ingress
94
142
svc_connected_to_ingress (svc, ingress) = result {
95
143
rule := ingress.spec.rules[i]
@@ -98,3 +146,11 @@ svc_connected_to_ingress(svc, ingress) = result {
98
146
result := [sprintf (" spec.rules[%d].http.paths[%d].backend.service.name" , [i,j])]
99
147
}
100
148
149
+ svc_connected_to_httproute (svc, httproute) = result {
150
+ rule := httproute.spec.rules[i]
151
+ ref := rule.backendRefs[j]
152
+ ref.kind == " Service"
153
+ svc.metadata.name == ref.name
154
+ result := [sprintf (" spec.rules[%d].backendRefs[%d].name" , [i,j])]
155
+ }
156
+
0 commit comments