Skip to content

Commit

Permalink
Fix a bug where host networking traffic could be misclassified as con…
Browse files Browse the repository at this point in the history
…trol plane traffic on Minikube
  • Loading branch information
omris94 committed Dec 22, 2024
1 parent 43dbc5b commit b60bf31
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/mapper/pkg/resolvers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ func (r *Resolver) discoverInternalSrcIdentity(ctx context.Context, src *model.R
Host: lo.ToPtr(src.SrcIP),
PodHostname: lo.ToPtr(src.SrcHostname),
}
pods, err := r.kubeFinder.ResolveServiceToPods(ctx, svc)
if err != nil && !errors.Is(err, kubefinder.ErrNoPodFound) {
return model.OtterizeServiceIdentity{}, errors.Errorf("could not resolve service %s to pods: %w", svc.Name, err)
}
// ignore services backed by host networking pods because it might as well be unrelated traffic (not from the control plane)
if len(pods) > 0 && lo.SomeBy(pods, func(pod corev1.Pod) bool { return pod.Spec.HostNetwork }) {
logrus.Debugf("control plane service is backed by a host networking pod, ignoring")
return model.OtterizeServiceIdentity{}, nil
}
return model.OtterizeServiceIdentity{Name: svc.Name, Namespace: svc.Namespace, KubernetesService: &svc.Name, ResolutionData: &resolutionData}, nil
}

Expand Down
13 changes: 7 additions & 6 deletions src/mapper/pkg/resolvers/schema.helpers.resolvers.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,13 @@ func (r *Resolver) resolveDestIdentity(ctx context.Context, dest model.Destinati
Namespace: destPod.Namespace,
Labels: kubefinder.PodLabelsToOtterizeLabels(destPod),
ResolutionData: &model.IdentityResolutionData{
Host: lo.ToPtr(dest.Destination),
Port: dest.DestinationPort,
IsService: lo.ToPtr(false),
ExtraInfo: lo.ToPtr("resolveDestIdentity"),
LastSeen: lo.ToPtr(dest.LastSeen.String()),
Uptime: lo.ToPtr(time.Since(destPod.CreationTimestamp.Time).String()),
Host: lo.ToPtr(dest.Destination),
PodHostname: lo.ToPtr(destPod.Name),
Port: dest.DestinationPort,
IsService: lo.ToPtr(false),
ExtraInfo: lo.ToPtr("resolveDestIdentity"),
LastSeen: lo.ToPtr(dest.LastSeen.String()),
Uptime: lo.ToPtr(time.Since(destPod.CreationTimestamp.Time).String()),
},
}
if dstService.OwnerObject != nil {
Expand Down

0 comments on commit b60bf31

Please sign in to comment.