Skip to content

Commit

Permalink
fix(query): service should match container using targetPort instead o…
Browse files Browse the repository at this point in the history
…f port (#4762)
  • Loading branch information
Churro authored Feb 1, 2022
1 parent b38bc28 commit 12db5eb
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assets/queries/k8s/service_does_not_target_pod/query.rego
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ confirmPorts(label, servicePorts) {
resource.metadata.labels[_] == label[_]
[path, value] := walk(resource.spec)
cont := value[types[j]]
cont[_].ports[_].containerPort == servicePorts.port
cont[_].ports[_].containerPort == servicePorts.targetPort
}

match_label(string) = ret {
Expand Down
39 changes: 39 additions & 0 deletions assets/queries/k8s/service_does_not_target_pod/test/negative2.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apiVersion: v1
kind: Service
metadata:
name: helloworld
spec:
type: ClusterIP
ports:
- name: http
port: 80
protocol: TCP
targetPort: 8080
- name: health
port: 8081
protocol: TCP
targetPort: 8082
selector:
app: helloworld
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: helloworld
labels:
app: helloworld
spec:
selector:
matchLabels:
app: helloworld
template:
metadata:
labels:
app: helloworld
spec:
containers:
- name: webserver
image: nginx:latest
ports:
- containerPort: 8080
- containerPort: 8082

0 comments on commit 12db5eb

Please sign in to comment.