You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
If a service uses 2+ label selectors to identify the target pod, the Popeye scanner is incorrectly using the selectors to find the pod. The end result is you may have false positives reported by Popeye because it is comparing against the wrong pod.
To Reproduce
Steps to reproduce the behavior:
Apply the following resources
apiVersion: v1
kind: Pod
metadata:
name: aaa
labels:
part-of: foo
instance: web
spec:
containers:
- name: web
image: nginx
ports:
- name: web
containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Pod
metadata:
name: bbb
labels:
part-of: foo
instance: bar
spec:
containers:
- name: web
image: nginx
ports:
- name: http
containerPort: 80
protocol: TCP
---
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
part-of: foo
instance: bar
ports:
- name: http
protocol: TCP
port: 80
targetPort: http
Note that both the aaa and bbb pods have the same part-of label, but different instance labels. The service is expecting to match a pod with part-of=foo AND instance=bar
Scan the cluster using popeye
Observe the error
· default/my-service.............................................................................💥
💥 [POP-1106] No target ports match service port TCP:http:80.
😱 [POP-1109] Single endpoint is associated with this service.
Expected behavior
POP-1106 is not falsely reported.
Screenshots
Versions (please complete the following information):
OS: linux
Popeye: latest
K8s: 1.26
Additional context
The issue appears to lie in the MatchLabels() function in db.go:
aaa is processed first. The part-of selector matches on the aaa pod. count > 0, and so the aaa pod is returned as the matching pod for this selector set. Instead, both selector labels should match, as multiple selectors are treated as an AND.
My first impression is that MatchLabels() should be checking count == len(sel).
The text was updated successfully, but these errors were encountered:
bpfoster
added a commit
to bpfoster/popeye
that referenced
this issue
Apr 2, 2024
Describe the bug
If a service uses 2+ label selectors to identify the target pod, the Popeye scanner is incorrectly using the selectors to find the pod. The end result is you may have false positives reported by Popeye because it is comparing against the wrong pod.
To Reproduce
Steps to reproduce the behavior:
aaa
andbbb
pods have the samepart-of
label, but differentinstance
labels. The service is expecting to match a pod withpart-of=foo AND instance=bar
Expected behavior
POP-1106 is not falsely reported.
Screenshots
Versions (please complete the following information):
Additional context
The issue appears to lie in the
MatchLabels()
function indb.go
:popeye/internal/db/db.go
Lines 384 to 393 in f736e64
aaa
is processed first. Thepart-of
selector matches on theaaa
pod.count > 0
, and so theaaa
pod is returned as the matching pod for this selector set. Instead, both selector labels should match, as multiple selectors are treated as an AND.My first impression is that
MatchLabels()
should be checkingcount == len(sel)
.The text was updated successfully, but these errors were encountered: