Skip to content

Commit 9d5c581

Browse files
committed
Adding iteration over workloads
Signed-off-by: Amit Schendel <[email protected]>
1 parent 09c43af commit 9d5c581

File tree

2 files changed

+61
-16
lines changed

2 files changed

+61
-16
lines changed
+23-5
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,48 @@
11
package armo_builtins
22

33
deny[msga] {
4-
service := input[_]
4+
5+
service := input[_]
56
service.kind == "Service"
67

8+
wl := input[_]
9+
spec_template_spec_patterns := {"Deployment", "ReplicaSet", "DaemonSet", "StatefulSet", "Pod", "Job", "CronJob"}
10+
spec_template_spec_patterns[wl.kind]
11+
wl_connected_to_service(wl, service)
12+
713
specificPort := service.spec.ports[i]
814
portNumber := specificPort.port
915
service_name := service.metadata.name
1016
namespace := service.metadata.namespace
1117
hasUnauthenticatedService(service_name, portNumber, namespace)
1218

13-
path := sprintf("spec.ports[%v].port", [i])
19+
# Path to the pod spec
20+
path := "spec"
1421

1522
msga := {
16-
"alertMessage": sprintf("Unauthenticated service %v", [service_name]),
23+
"alertMessage": sprintf("Unauthenticated service %v which exposes %v", [service_name, wl.metadata.name]),
1724
"alertScore": 7,
1825
"fixPaths": [],
1926
"reviewPaths": [path],
2027
"failedPaths": [path],
2128
"packagename": "armo_builtins",
2229
"alertObject": {
23-
"k8sApiObjects": [service]
30+
"k8sApiObjects": [wl]
2431
},
32+
"relatedObjects": [{
33+
"object": service
34+
}]
2535
}
2636
}
2737

2838
hasUnauthenticatedService(service_name, port, namespace) {
2939
networkscanner.isUnauthenticatedService(service_name, port, namespace)
30-
}
40+
}
41+
42+
wl_connected_to_service(wl, svc) {
43+
count({x | svc.spec.selector[x] == wl.metadata.labels[x]}) == count(svc.spec.selector)
44+
}
45+
46+
wl_connected_to_service(wl, svc) {
47+
wl.spec.selector.matchLabels == svc.spec.selector
48+
}

rules/unauthenticated-service/rule.metadata.json

+38-11
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,44 @@
22
"name": "unauthenticated-service",
33
"ruleLanguage": "Rego",
44
"match": [
5-
{
6-
"apiGroups": [
7-
""
8-
],
9-
"apiVersions": [
10-
"v1"
11-
],
12-
"resources": [
13-
"Service"
14-
]
15-
}
5+
{
6+
"apiGroups": [
7+
""
8+
],
9+
"apiVersions": [
10+
"v1"
11+
],
12+
"resources": [
13+
"Pod",
14+
"Service"
15+
]
16+
},
17+
{
18+
"apiGroups": [
19+
"apps"
20+
],
21+
"apiVersions": [
22+
"v1"
23+
],
24+
"resources": [
25+
"Deployment",
26+
"ReplicaSet",
27+
"DaemonSet",
28+
"StatefulSet"
29+
]
30+
},
31+
{
32+
"apiGroups": [
33+
"batch"
34+
],
35+
"apiVersions": [
36+
"*"
37+
],
38+
"resources": [
39+
"Job",
40+
"CronJob"
41+
]
42+
}
1643
],
1744
"dynamicMatch": [
1845
],

0 commit comments

Comments
 (0)