Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making sure that service and ingress are in the same namespace #525

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions controls/C-0256-exposuretointernet.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
"baseScore": 7.0,
"scanningScope": {
"matches": [
"cluster",
"file"
"cluster"
]
}
}
17 changes: 13 additions & 4 deletions rules/exposure-to-internet/raw.rego
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ deny[msga] {

svc := input[_]
svc.kind == "Service"

# Make sure that they belong to the same namespace
svc.metadata.namespace == ingress.metadata.namespace

# avoid duplicate alerts
# if service is already exposed through NodePort or LoadBalancer workload will fail on that
not is_exposed_service(svc)
Expand All @@ -55,11 +59,16 @@ deny[msga] {
"alertObject": {
"k8sApiObjects": [wl]
},
"relatedObjects": [{
"object": ingress,
"relatedObjects": [
{
"object": ingress,
"reviewPaths": result,
"failedPaths": result,
}]
"failedPaths": result,
},
{
"object": svc,
}
]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"apiVersion": "networking.k8s.io/v1",
"kind": "Ingress",
"metadata": {
"name": "my-ingress"
"name": "my-ingress",
"namespace": "default"
},
"spec": {
"ingressClassName": "nginx",
Expand Down Expand Up @@ -54,6 +55,28 @@
"spec.rules[0].http.paths[0].backend.service.name"
],
"fixPaths": null
},
{
"object": {
"apiVersion": "v1",
"kind": "Service",
"metadata": {
"name": "my-service",
"namespace": "default"
},
"spec": {
"ports": [
{
"port": 80,
"targetPort": 80
}
],
"selector": {
"app": "my-app"
},
"type": "ClusterIP"
}
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: my-ingress
namespace: default
spec:
ingressClassName: nginx
rules:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
kind: Service
metadata:
name: my-service
namespace: default
Dismissed Show dismissed Hide dismissed
spec:
selector:
app: my-app
Expand Down
Loading