Skip to content

Commit

Permalink
fix: DNS queries recognition not working
Browse files Browse the repository at this point in the history
since networking events are global for all containers in a pod we need
to support a single identifier for all networking events and a parent
id for each container event to cross reference the events from
containers to events from pods
  • Loading branch information
barp committed Jan 12, 2023
1 parent 180bece commit 0bba5fd
Show file tree
Hide file tree
Showing 11 changed files with 142 additions and 115 deletions.
4 changes: 2 additions & 2 deletions cmd/dnsproxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func main() {
panic(err)
}
sourceId := &proto.SourceId{
Type: "container",
Id: hostname + "-" + os.Getenv(consts.ContainerNameEnv),
Type: "pod",
Id: hostname,
}
client := CreateDaemonServiceClient(sourceId)
search, err := retrieveSearchList()
Expand Down
5 changes: 3 additions & 2 deletions cmd/entrypoint/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ func xmain() error {

_, err = client.Monitor(context.Background(), &proto.MonitorPodRequest{
Id: &proto.SourceId{
Type: "container",
Id: hostname + "-" + os.Getenv(consts.ContainerNameEnv),
Type: "container",
Parent: hostname,
Id: hostname + "-" + os.Getenv(consts.ContainerNameEnv),
},
})
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyze/analyze.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func Analyze(inputFilename string, filters *Filters) (*proto.AnalysisSummary, er
}

for i, s := range sources {
if s.GetType() == "host" {
if s.GetType() == "host" || s.GetType() == "pod" {
continue
}
sum, err := analyzeContainer(inputFilename, s, searchPaths[i], filters)
Expand Down
21 changes: 20 additions & 1 deletion pkg/analyze/analyze_failed_connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,27 @@ func (analyzer *connectionAnalyzer) handleDnsEvent(dns *proto.Event_DnsQueryEven
return true
}

func (analyzer *connectionAnalyzer) isEventRelevant(event *proto.Event) bool {
// TODO: compare the host id
if event.GetSource().GetType() == "host" {
return true
}
if event.GetSource().GetType() == "container" {
if event.GetSource().GetId() == analyzer.sourceId.GetId() {
return true
}
} else if event.GetSource().GetType() == "pod" {
if event.GetSource().GetId() == analyzer.sourceId.GetParent() {
return true
}
}

return false

}

func (analyzer *connectionAnalyzer) handleEvent(event *proto.Event) bool {
if (event.GetSource().GetId() != analyzer.sourceId.GetId() || event.GetSource().GetType() != analyzer.sourceId.GetType()) && (event.GetSource().GetType() != "host") {
if !analyzer.isEventRelevant(event) {
return true
}
net := event.GetNetwork()
Expand Down
4 changes: 2 additions & 2 deletions pkg/analyze/analyze_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ package analyze
import (
"testing"

"github.com/google/containerdbg/proto"
"github.com/google/go-cmp/cmp"
"google.golang.org/protobuf/testing/protocmp"
"github.com/google/containerdbg/proto"
)

func TestAnalyze(t *testing.T) {
Expand Down Expand Up @@ -131,7 +131,7 @@ func TestAnalyze(t *testing.T) {
},
},
{
name: "connection failed to external service error",
name: "connection failed to external service error ubuntu",
dataFile: "./testdata/tomcat-ubuntu-host.pb",
expected: &proto.AnalysisSummary{
ContainerSummaries: []*proto.AnalysisSummary_ContainerSummaryTuple{
Expand Down
4 changes: 3 additions & 1 deletion pkg/debug/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func modifyContainer(container *v1.Container) error {
}

func GetDnsProxyContainer() v1.EphemeralContainerCommon {
return v1.EphemeralContainerCommon{
container := v1.EphemeralContainerCommon{
Name: "dnsproxy",
Image: build.ImageRepo + "/dnsproxy:" + build.ImageVersion,
ImagePullPolicy: v1.PullPolicy(build.PullPolicy),
Expand All @@ -126,6 +126,8 @@ func GetDnsProxyContainer() v1.EphemeralContainerCommon {
RunAsGroup: pointer.Int64(0),
},
}

return container
}

func ModifyPodSpec(podspec *v1.PodSpec) error {
Expand Down
192 changes: 100 additions & 92 deletions proto/event.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions proto/event.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ message DnsQueryError {
message SourceId {
string type = 1;
string id = 2;
string parent = 3;
}

message Event {
Expand Down
10 changes: 4 additions & 6 deletions proto/node_api.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion proto/node_api_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 5 additions & 7 deletions proto/summary.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 0bba5fd

Please sign in to comment.